Skip to content

Commit

Permalink
fix: 🐛 resolve path for projectFoler and cliFolder
Browse files Browse the repository at this point in the history
  • Loading branch information
mjancarik committed Aug 30, 2024
1 parent ec156f1 commit bf61497
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 28 deletions.
14 changes: 0 additions & 14 deletions packages/cli/bin/merkur.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,6 @@ const verboseOption = new Option('--verbose', 'Verbose mode which show debug inf
program
.name('merkur')
.description('CLI for Merkur framework.')
// .option('--writeToDisk', 'Write built files to disk.')
// .option('--sourcemap', 'Generate sourcemap.')
// .option('--runTasks [runTasks...]', 'Run only defined tasks.')
// .option('--outFile <string>', 'Server out file configuration in es-build.')
// .option('--port <number>', 'Widget server port.')
// .option('--devServerPort <number>', 'Dev server port.')
// .option('--projectFolder <string>', 'Project folder.')
// .option('--buildFolder <string>', 'Build folder.')
// .option('--staticFolder <string>', 'Static folder.')
// .option('--staticPath <string>', 'The static path for dev server and widget server.')
// .option('--hasRunDevServer', 'Flag for starting dev server')
// .option('--hasRunWidgetServer', 'Flag for starting widget server')
// .option('--inspect', 'Debugging widget server')
// .option('--verbose', 'Verbose mode which show debug information.')
.version(packageFile.version);

program.command(COMMAND_NAME.DEV)
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/buildConfig.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readdir } from 'node:fs/promises';
import path from 'node:path';

import manifestPlugin from 'esbuild-plugin-manifest';

Expand Down Expand Up @@ -39,7 +40,7 @@ export async function createBuildConfig({

// Alias
alias: {
'@widget': `${projectFolder}/src/widget.js`,
'@widget': path.resolve(`${projectFolder}/src/widget.js`),
...definition.build.alias,
},

Expand Down Expand Up @@ -91,14 +92,14 @@ async function getEntries({ merkurConfig, cliConfig }) {
};

try {
const files = await readdir(`${cliConfig.projectFolder}/src/entries/`);
const files = await readdir(path.resolve(`${cliConfig.projectFolder}/src/entries/`));
const FILENAMES = ['client', 'server'];

files.forEach((file) => {
FILENAMES.forEach((filename) => {
if (file.startsWith(filename)) {
entries[filename] = [
`${cliConfig.projectFolder}/src/entries/${file}`,
path.resolve(`${cliConfig.projectFolder}/src/entries/${file}`),
];
}
});
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/devServer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ export async function runDevServer({ context, merkurConfig, cliConfig }) {
}

const devClient = isDevCommand
? fs.readFileSync(`${cliFolder}/../lib/devClient.mjs`, 'utf8')
? fs.readFileSync(path.resolve(`${cliFolder}/../lib/devClient.mjs`), 'utf8')
: '';

const playgroundTemplate = ejs.compile(
fs.readFileSync(template, 'utf8'),
{
views: [
`${projectFolder}/server/playground/templates/`,
path.resolve(`${projectFolder}/server/playground/templates/`),
path.dirname(template),
templateFolder,
],
Expand Down
17 changes: 9 additions & 8 deletions packages/cli/src/merkurConfig.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export async function createMerkurConfig({ cliConfig, context, args } = {}) {

try {
logger.debug(
`Load merkur config on path ${projectFolder}/${MERKUR_CONFIG_FILE}`,
`Load merkur config on path ${path.resolve(`${projectFolder}/${MERKUR_CONFIG_FILE}`)}`,
);

const file = await import(`${projectFolder}/${MERKUR_CONFIG_FILE}`);
const file = await import(path.resolve(`${projectFolder}/${MERKUR_CONFIG_FILE}`));
merkurConfig = await file.default({
cliConfig,
context,
Expand All @@ -28,6 +28,7 @@ export async function createMerkurConfig({ cliConfig, context, args } = {}) {
});
} catch (error) {
logger.error(error);
process.exit(1);
}

cliConfig = { ...cliConfig, ...(merkurConfig?.cliConfig ?? {}), ...args };
Expand Down Expand Up @@ -101,7 +102,7 @@ emitter.on(
folder: 'es13',
build: {
platform: 'browser',
outdir: `${staticFolder}/es13`,
outdir: path.resolve(`${staticFolder}/es13`),
plugins: [devPlugin],
},
},
Expand All @@ -111,7 +112,7 @@ emitter.on(
build: {
platform: 'browser',
target: 'es2018',
outdir: `${staticFolder}/es9`,
outdir: path.resolve(`${staticFolder}/es9`),
},
},
};
Expand Down Expand Up @@ -172,8 +173,8 @@ emitter.on(
EMITTER_EVENTS.MERKUR_CONFIG,
function defaultEntries({ merkurConfig, cliConfig }) {
merkurConfig.defaultEntries = {
client: [`${cliConfig.projectFolder}/src/entries/client.js`],
server: [`${cliConfig.projectFolder}/src/entries/server.js`],
client: [path.resolve(`${cliConfig.projectFolder}/src/entries/client.js`)],
server: [path.resolve(`${cliConfig.projectFolder}/src/entries/server.js`)],
...merkurConfig.defaultEntries,
};

Expand All @@ -185,8 +186,8 @@ emitter.on(
EMITTER_EVENTS.MERKUR_CONFIG,
function playground({ merkurConfig, cliConfig }) {
merkurConfig.playground = {
template: `${cliConfig.cliFolder}/templates/playground.ejs`,
templateFolder: `${cliConfig.cliFolder}/templates`,
template: path.resolve(`${cliConfig.cliFolder}/templates/playground.ejs`),
templateFolder: path.resolve(`${cliConfig.cliFolder}/templates`),
path: '/',
widgetHandler: async (req) => {
const { protocol, host } = merkurConfig.widgetServer;
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/plugins/metaPlugin.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'node:fs/promises';
import path from 'node:path';

import { createLogger } from '../logger.mjs';
import { time } from '../utils.mjs';
Expand Down Expand Up @@ -31,7 +32,7 @@ export function metaPlugin({ definition, config, cliConfig }) {

metaInformation = await Promise.all(
generatedFiles.map(async (file) => {
const stat = await fs.stat(`${projectFolder}/${file}`);
const stat = await fs.stat(path.resolve(`${projectFolder}/${file}`));

return { stat, file };
}),
Expand Down

0 comments on commit bf61497

Please sign in to comment.