@erudit-js/cli 4.0.0-dev.3 → 4.0.0-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +7 -0
- package/dist/commands/build.d.ts +2 -19
- package/dist/commands/build.js +24 -19
- package/dist/commands/dev.d.ts +12 -6
- package/dist/commands/dev.js +32 -14
- package/dist/commands/generate.d.ts +13 -7
- package/dist/commands/generate.js +35 -15
- package/dist/commands/launch.d.ts +20 -2
- package/dist/commands/launch.js +34 -23
- package/dist/commands/main.js +15 -8
- package/dist/commands/prepare.d.ts +2 -8
- package/dist/commands/prepare.js +23 -15
- package/dist/commands/preview.d.ts +2 -2
- package/dist/commands/preview.js +48 -21
- package/dist/config.d.ts +3 -0
- package/dist/config.js +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/inject.d.ts +1 -0
- package/dist/inject.js +1 -0
- package/dist/shared/absPath.d.ts +3 -0
- package/dist/shared/absPath.js +25 -0
- package/dist/shared/args.d.ts +16 -12
- package/dist/shared/args.js +19 -32
- package/dist/shared/cliError.d.ts +1 -0
- package/dist/shared/cliError.js +8 -0
- package/dist/shared/env.d.ts +1 -0
- package/dist/shared/env.js +9 -0
- package/dist/shared/logCommand.js +4 -0
- package/dist/shared/nuxt.d.ts +7 -2
- package/dist/shared/nuxt.js +84 -43
- package/dist/shared/prepare.d.ts +3 -7
- package/dist/shared/prepare.js +53 -45
- package/dist/shared/projectPath.d.ts +3 -0
- package/dist/shared/projectPath.js +22 -0
- package/dist/shared/urlProps.d.ts +7 -0
- package/dist/shared/urlProps.js +77 -0
- package/package.json +35 -36
- package/bin/erudit-cli.js +0 -5
- package/dist/commands/init.d.ts +0 -8
- package/dist/commands/init.js +0 -60
- package/dist/run.d.ts +0 -1
- package/dist/run.js +0 -5
- package/dist/shared/log.js +0 -6
- package/dist/shared/path.d.ts +0 -1
- package/dist/shared/path.js +0 -13
- /package/dist/shared/{log.d.ts → logCommand.d.ts} +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { existsSync, lstatSync } from 'node:fs';
|
|
2
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
export function absPath(path) {
|
|
5
|
+
const normalize = (p) => p.replaceAll('\\', '/');
|
|
6
|
+
path = normalize(path);
|
|
7
|
+
if (!isAbsolute(path)) {
|
|
8
|
+
path = normalize(resolve(process.cwd(), path));
|
|
9
|
+
}
|
|
10
|
+
return path;
|
|
11
|
+
}
|
|
12
|
+
export function absPathEnsured(path) {
|
|
13
|
+
const abs = absPath(path);
|
|
14
|
+
if (!existsSync(abs)) {
|
|
15
|
+
throw new Error(chalk.red(`Path does not exist: ${abs}`));
|
|
16
|
+
}
|
|
17
|
+
return abs;
|
|
18
|
+
}
|
|
19
|
+
export function absDirectoryEnsured(path) {
|
|
20
|
+
const abs = absPathEnsured(path);
|
|
21
|
+
if (!lstatSync(abs).isDirectory()) {
|
|
22
|
+
throw new Error(chalk.red(`Path is not a directory: ${abs}`));
|
|
23
|
+
}
|
|
24
|
+
return abs;
|
|
25
|
+
}
|
package/dist/shared/args.d.ts
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
|
|
1
|
+
export declare const projectPathArg: {
|
|
2
|
+
projectPath: {
|
|
3
|
+
type: "positional";
|
|
4
|
+
description: string;
|
|
5
|
+
required: false;
|
|
6
|
+
valueHint: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare const siteUrlArg: {
|
|
10
|
+
siteUrl: {
|
|
3
11
|
type: "string";
|
|
4
12
|
description: string;
|
|
5
13
|
required: false;
|
|
6
|
-
|
|
14
|
+
valueHint: string;
|
|
7
15
|
};
|
|
8
16
|
};
|
|
9
|
-
export declare const
|
|
10
|
-
|
|
11
|
-
type: "
|
|
17
|
+
export declare const basePathArg: {
|
|
18
|
+
basePath: {
|
|
19
|
+
type: "string";
|
|
12
20
|
description: string;
|
|
13
21
|
required: false;
|
|
14
|
-
|
|
22
|
+
valueHint: string;
|
|
15
23
|
};
|
|
16
24
|
};
|
|
17
25
|
export declare const contentTargetsArg: {
|
|
@@ -19,7 +27,7 @@ export declare const contentTargetsArg: {
|
|
|
19
27
|
type: "string";
|
|
20
28
|
description: string;
|
|
21
29
|
required: false;
|
|
22
|
-
|
|
30
|
+
valueHint: string;
|
|
23
31
|
};
|
|
24
32
|
};
|
|
25
33
|
export declare const nitroPresetArg: {
|
|
@@ -29,7 +37,3 @@ export declare const nitroPresetArg: {
|
|
|
29
37
|
description: string;
|
|
30
38
|
};
|
|
31
39
|
};
|
|
32
|
-
export declare function resolveArgPaths(projectPath: string, eruditPath: string): {
|
|
33
|
-
projectPath: string;
|
|
34
|
-
eruditPath: string;
|
|
35
|
-
};
|
package/dist/shared/args.js
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export const projectPathArg = {
|
|
2
|
+
projectPath: {
|
|
3
|
+
type: 'positional',
|
|
4
|
+
description: 'Erudit project directory. Can also be set via ERUDIT_PROJECT_PATH env variable.',
|
|
5
|
+
required: false,
|
|
6
|
+
valueHint: '.',
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
export const siteUrlArg = {
|
|
10
|
+
siteUrl: {
|
|
6
11
|
type: 'string',
|
|
7
|
-
description: '
|
|
12
|
+
description: 'Erudit full site URL. Can also be set via ERUDIT_SITE_URL env variable.',
|
|
8
13
|
required: false,
|
|
9
|
-
|
|
14
|
+
valueHint: 'https://my-awesome-site.com/',
|
|
10
15
|
},
|
|
11
16
|
};
|
|
12
|
-
export const
|
|
13
|
-
|
|
14
|
-
type: '
|
|
15
|
-
description: 'Erudit
|
|
17
|
+
export const basePathArg = {
|
|
18
|
+
basePath: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
description: 'Base path for Erudit site. Can also be set via ERUDIT_BASE_PATH env variable.',
|
|
16
21
|
required: false,
|
|
17
|
-
|
|
22
|
+
valueHint: '/subfolder/',
|
|
18
23
|
},
|
|
19
24
|
};
|
|
20
25
|
export const contentTargetsArg = {
|
|
@@ -22,31 +27,13 @@ export const contentTargetsArg = {
|
|
|
22
27
|
type: 'string',
|
|
23
28
|
description: 'Content targets to process',
|
|
24
29
|
required: false,
|
|
25
|
-
|
|
30
|
+
valueHint: '"combinatorics"',
|
|
26
31
|
},
|
|
27
32
|
};
|
|
28
33
|
export const nitroPresetArg = {
|
|
29
34
|
preset: {
|
|
30
35
|
type: 'string',
|
|
31
36
|
required: false,
|
|
32
|
-
description: '(Nuxt Build Flag) Nitro preset to use for building',
|
|
37
|
+
description: '(Nuxt Build Flag) Nitro preset to use for building. Can also be set via ERUDIT_NITRO_PRESET env variable.',
|
|
33
38
|
},
|
|
34
39
|
};
|
|
35
|
-
export function resolveArgPaths(projectPath, eruditPath) {
|
|
36
|
-
consola.start('Resolving project path...');
|
|
37
|
-
projectPath = resolvePath(projectPath);
|
|
38
|
-
consola.success('Resolved project path:', chalk.greenBright(projectPath));
|
|
39
|
-
consola.start('Resolving Erudit Nuxt Layer path...');
|
|
40
|
-
if (eruditPath === 'erudit') {
|
|
41
|
-
consola.success(`'nuxi' will find Erudit in your dependencies!`);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
eruditPath = resolvePath(eruditPath);
|
|
45
|
-
consola.warn('Custom Erudit Nuxt Layer path will be used: ' +
|
|
46
|
-
chalk.yellowBright(eruditPath));
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
projectPath,
|
|
50
|
-
eruditPath,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cliError(message: string, causeError?: any): Error;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loadEnvFiles(files: string[]): void;
|
package/dist/shared/nuxt.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
interface NuxtConfig {
|
|
2
|
+
command: 'prepare' | 'dev' | 'build' | 'generate';
|
|
3
|
+
absProjectPath: string;
|
|
4
|
+
restArgs?: string | string[];
|
|
5
|
+
env?: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
export declare function spawnNuxt(config: NuxtConfig): Promise<void>;
|
|
3
8
|
export {};
|
package/dist/shared/nuxt.js
CHANGED
|
@@ -1,50 +1,91 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
-
export async function spawnNuxt(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export async function spawnNuxt(config) {
|
|
3
|
+
const onClose = (exitCode) => {
|
|
4
|
+
switch (exitCode) {
|
|
5
|
+
case 0:
|
|
6
6
|
console.log('Nuxt process exited successfully!');
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
if (exitCode === 1) {
|
|
10
|
-
console.error('Nuxt process exited with an error!');
|
|
11
|
-
return resolve();
|
|
12
|
-
}
|
|
13
|
-
if (exitCode === 1337) {
|
|
7
|
+
return;
|
|
8
|
+
case 1337:
|
|
14
9
|
console.warn('Nuxt full restart is requested!');
|
|
15
10
|
_spawnNuxt();
|
|
16
11
|
return;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
console.error(`Nuxt process exited with an error code ${exitCode} in development mode!\nRespawning...`);
|
|
20
|
-
_spawnNuxt();
|
|
12
|
+
default:
|
|
13
|
+
console.error(`Nuxt process exited with code ${exitCode}!`);
|
|
21
14
|
return;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
env: {
|
|
40
|
-
...process.env,
|
|
41
|
-
ERUDIT_PROJECT_DIR: projectPath,
|
|
42
|
-
ERUDIT_COMMAND: command,
|
|
43
|
-
ERUDIT_MODE: mode,
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
nuxtProcess.on('close', onClose);
|
|
47
|
-
};
|
|
48
|
-
_spawnNuxt();
|
|
49
|
-
});
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const _spawnNuxt = () => {
|
|
18
|
+
const restArgs = Array.isArray(config.restArgs)
|
|
19
|
+
? config.restArgs.join(' ')
|
|
20
|
+
: config.restArgs || '';
|
|
21
|
+
const nuxtProcess = spawn(`nuxt ${config.command} ${config.absProjectPath}/.erudit/nuxt ${restArgs}`, {
|
|
22
|
+
shell: true,
|
|
23
|
+
stdio: 'inherit',
|
|
24
|
+
env: {
|
|
25
|
+
...process.env,
|
|
26
|
+
...config.env,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
nuxtProcess.on('close', onClose);
|
|
30
|
+
};
|
|
31
|
+
_spawnNuxt();
|
|
50
32
|
}
|
|
33
|
+
// type NuxtCommand = 'dev' | 'build' | 'generate' | 'prepare';
|
|
34
|
+
// export async function spawnNuxt(
|
|
35
|
+
// command: NuxtCommand,
|
|
36
|
+
// projectPath: string,
|
|
37
|
+
// restParams?: string,
|
|
38
|
+
// ) {
|
|
39
|
+
// return new Promise<void>((resolve) => {
|
|
40
|
+
// const onClose = (exitCode: number) => {
|
|
41
|
+
// if (exitCode === 0) {
|
|
42
|
+
// console.log('Nuxt process exited successfully!');
|
|
43
|
+
// return resolve();
|
|
44
|
+
// }
|
|
45
|
+
// if (exitCode === 1) {
|
|
46
|
+
// console.error('Nuxt process exited with an error!');
|
|
47
|
+
// return resolve();
|
|
48
|
+
// }
|
|
49
|
+
// if (exitCode === 1337) {
|
|
50
|
+
// console.warn('Nuxt full restart is requested!');
|
|
51
|
+
// _spawnNuxt();
|
|
52
|
+
// return;
|
|
53
|
+
// }
|
|
54
|
+
// if (command === 'dev') {
|
|
55
|
+
// console.error(
|
|
56
|
+
// `Nuxt process exited with an error code ${exitCode} in development mode!\nRespawning...`,
|
|
57
|
+
// );
|
|
58
|
+
// _spawnNuxt();
|
|
59
|
+
// return;
|
|
60
|
+
// }
|
|
61
|
+
// };
|
|
62
|
+
// const _spawnNuxt = () => {
|
|
63
|
+
// const mode: EruditMode | undefined = (() => {
|
|
64
|
+
// switch (command) {
|
|
65
|
+
// case 'dev':
|
|
66
|
+
// case 'prepare':
|
|
67
|
+
// return 'dev';
|
|
68
|
+
// case 'build':
|
|
69
|
+
// return 'write';
|
|
70
|
+
// case 'generate':
|
|
71
|
+
// return 'static';
|
|
72
|
+
// }
|
|
73
|
+
// })();
|
|
74
|
+
// const nuxtProcess = spawn(
|
|
75
|
+
// `nuxt ${command} ${projectPath}/.erudit/nuxt ${restParams || ''}`,
|
|
76
|
+
// {
|
|
77
|
+
// shell: true,
|
|
78
|
+
// stdio: 'inherit',
|
|
79
|
+
// env: {
|
|
80
|
+
// ...process.env,
|
|
81
|
+
// ERUDIT_PROJECT_DIR: projectPath,
|
|
82
|
+
// ERUDIT_COMMAND: command,
|
|
83
|
+
// ERUDIT_MODE: mode,
|
|
84
|
+
// },
|
|
85
|
+
// },
|
|
86
|
+
// );
|
|
87
|
+
// nuxtProcess.on('close', onClose);
|
|
88
|
+
// };
|
|
89
|
+
// _spawnNuxt();
|
|
90
|
+
// });
|
|
91
|
+
// }
|
package/dist/shared/prepare.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
contentTargets?: string | string[];
|
|
5
|
-
}
|
|
6
|
-
export declare function prepare({ projectPath, eruditPath, contentTargets, }: PrepareData): Promise<void>;
|
|
7
|
-
export {};
|
|
1
|
+
export declare function prepareProject({ absProjectPath, }: {
|
|
2
|
+
absProjectPath: string;
|
|
3
|
+
}): Promise<void>;
|
package/dist/shared/prepare.js
CHANGED
|
@@ -1,32 +1,58 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (existsSync(
|
|
10
|
-
rmSync(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { CONFIG } from '../config.js';
|
|
4
|
+
export async function prepareProject({ absProjectPath, }) {
|
|
5
|
+
process.stdout.write('Preparing Erudit project...');
|
|
6
|
+
const eruditBuildPath = `${absProjectPath}/.erudit`;
|
|
7
|
+
const nuxtLayerPath = `${eruditBuildPath}/nuxt`;
|
|
8
|
+
const distPath = `${absProjectPath}/.output`;
|
|
9
|
+
if (existsSync(eruditBuildPath)) {
|
|
10
|
+
rmSync(eruditBuildPath, { force: true, recursive: true });
|
|
11
|
+
}
|
|
12
|
+
if (existsSync(distPath)) {
|
|
13
|
+
rmSync(distPath, { force: true, recursive: true });
|
|
14
|
+
}
|
|
15
|
+
mkdirSync(nuxtLayerPath, { recursive: true });
|
|
16
|
+
if (!existsSync(`${absProjectPath}/erudit.config.ts`)) {
|
|
17
|
+
writeFileSync(`${absProjectPath}/erudit.config.ts`, `export default defineEruditConfig({\n /* Adjust Erudit to your needs here... */\n});`);
|
|
18
|
+
}
|
|
19
|
+
if (!existsSync(`${absProjectPath}/tsconfig.json`)) {
|
|
20
|
+
writeFileSync(`${absProjectPath}/tsconfig.json`, JSON.stringify({
|
|
21
|
+
files: [],
|
|
22
|
+
references: [
|
|
23
|
+
{
|
|
24
|
+
path: './.erudit/tsconfig.erudit.json',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
path: './.erudit/tsconfig.nuxt.app.json',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
path: './.erudit/tsconfig.nuxt.server.json',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
path: './.erudit/tsconfig.nuxt.shared.json',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
path: './.erudit/tsconfig.nuxt.node.json',
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
}, null, 2));
|
|
40
|
+
}
|
|
41
|
+
writeFileSync(`${nuxtLayerPath}/nuxt.config.ts`, `
|
|
16
42
|
export default {
|
|
17
|
-
compatibilityDate: '
|
|
18
|
-
extends: ['${
|
|
43
|
+
compatibilityDate: '2026-01-01',
|
|
44
|
+
extends: ['${CONFIG.ERUDIT_PATH}'],
|
|
19
45
|
}
|
|
20
46
|
`);
|
|
21
47
|
['app', 'server', 'shared', 'node'].forEach((name) => {
|
|
22
|
-
writeFileSync(`${
|
|
48
|
+
writeFileSync(`${eruditBuildPath}/tsconfig.nuxt.${name}.json`, JSON.stringify({ extends: [`./nuxt/.nuxt/tsconfig.${name}.json`] }, null, 4));
|
|
23
49
|
});
|
|
24
|
-
mkdirSync(`${
|
|
25
|
-
writeFileSync(`${
|
|
50
|
+
mkdirSync(`${eruditBuildPath}/types`, { recursive: true });
|
|
51
|
+
writeFileSync(`${eruditBuildPath}/tsconfig.erudit.json`, JSON.stringify({
|
|
26
52
|
compilerOptions: {
|
|
27
53
|
paths: {
|
|
28
|
-
'#project/*': [`${
|
|
29
|
-
'#content/*': [`${
|
|
54
|
+
'#project/*': [`${absProjectPath}/*`],
|
|
55
|
+
'#content/*': [`${absProjectPath}/content/*`],
|
|
30
56
|
},
|
|
31
57
|
verbatimModuleSyntax: true,
|
|
32
58
|
forceConsistentCasingInFileNames: true,
|
|
@@ -44,14 +70,11 @@ export async function prepare({ projectPath, eruditPath, contentTargets, }) {
|
|
|
44
70
|
types: ['@jsprose/core/types', '@erudit-js/prose/types'],
|
|
45
71
|
lib: ['ESNext'],
|
|
46
72
|
},
|
|
47
|
-
include: [`${
|
|
48
|
-
exclude: [
|
|
49
|
-
`${eruditBuildDir}/nuxt/**/*`,
|
|
50
|
-
`${projectPath}/**/docs.ts`,
|
|
51
|
-
],
|
|
73
|
+
include: [`${absProjectPath}/**/*`, `${eruditBuildPath}/**/*`],
|
|
74
|
+
exclude: [`${nuxtLayerPath}/**/*`],
|
|
52
75
|
}, null, 4));
|
|
53
|
-
if (!existsSync(`${
|
|
54
|
-
writeFileSync(`${
|
|
76
|
+
if (!existsSync(`${absProjectPath}/tsconfig.json`)) {
|
|
77
|
+
writeFileSync(`${absProjectPath}/tsconfig.json`, JSON.stringify({
|
|
55
78
|
files: [],
|
|
56
79
|
references: [
|
|
57
80
|
{
|
|
@@ -72,21 +95,6 @@ export async function prepare({ projectPath, eruditPath, contentTargets, }) {
|
|
|
72
95
|
],
|
|
73
96
|
}, null, 4));
|
|
74
97
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
consola.success('Erudit build files ready!');
|
|
78
|
-
}
|
|
79
|
-
async function prepareContentTargets(buildDir, targets) {
|
|
80
|
-
if (typeof targets === 'undefined' || targets === '') {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
if (typeof targets === 'string') {
|
|
84
|
-
targets = [targets];
|
|
85
|
-
}
|
|
86
|
-
if (Array.isArray(targets)) {
|
|
87
|
-
writeFileSync(`${buildDir}/targets.json`, JSON.stringify(targets, null, 4));
|
|
88
|
-
consola.success(`Saved ${targets.length} content targets!`);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
throw new Error(`Failed to resolve content targets: "${targets}"!`);
|
|
98
|
+
writeFileSync(`${eruditBuildPath}/__AUTOGENERATED__`, `This directory is autogenerated by Erudit CLI.\nAll changes will be lost on next build!`);
|
|
99
|
+
process.stdout.write(` ${chalk.bold.green('Done!')}\n`);
|
|
92
100
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { absDirectoryEnsured } from './absPath.js';
|
|
3
|
+
import { cliError } from './cliError.js';
|
|
4
|
+
export function retrieveProjectPath(projectPathArg) {
|
|
5
|
+
if (projectPathArg) {
|
|
6
|
+
return projectPathArg;
|
|
7
|
+
}
|
|
8
|
+
return process.env.ERUDIT_PROJECT_PATH || '.';
|
|
9
|
+
}
|
|
10
|
+
export function normalizeProjectPath(projectPath) {
|
|
11
|
+
let absProjectPath;
|
|
12
|
+
try {
|
|
13
|
+
absProjectPath = absDirectoryEnsured(projectPath);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
throw cliError('Error normalizing project path!', error);
|
|
17
|
+
}
|
|
18
|
+
return absProjectPath;
|
|
19
|
+
}
|
|
20
|
+
export function logProjectPath(projectPath) {
|
|
21
|
+
console.log('Project path:', chalk.bold.cyan(projectPath));
|
|
22
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface UrlProps {
|
|
2
|
+
siteUrl: string;
|
|
3
|
+
basePath: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function retrieveUrlProps(siteUrlArg?: string, basePathArg?: string): UrlProps;
|
|
6
|
+
export declare function normalizeUrlProps(urlProps: UrlProps): UrlProps;
|
|
7
|
+
export declare function logUrlProps(urlProps: UrlProps): void;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { cliError } from './cliError.js';
|
|
3
|
+
export function retrieveUrlProps(siteUrlArg, basePathArg) {
|
|
4
|
+
const finalProps = {
|
|
5
|
+
siteUrl: 'http://localhost:3000',
|
|
6
|
+
basePath: '/',
|
|
7
|
+
};
|
|
8
|
+
if (siteUrlArg) {
|
|
9
|
+
finalProps.siteUrl = siteUrlArg;
|
|
10
|
+
}
|
|
11
|
+
else if (process.env.ERUDIT_SITE_URL) {
|
|
12
|
+
finalProps.siteUrl = process.env.ERUDIT_SITE_URL;
|
|
13
|
+
}
|
|
14
|
+
if (basePathArg) {
|
|
15
|
+
finalProps.basePath = basePathArg;
|
|
16
|
+
}
|
|
17
|
+
else if (process.env.ERUDIT_BASE_PATH) {
|
|
18
|
+
finalProps.basePath = process.env.ERUDIT_BASE_PATH;
|
|
19
|
+
}
|
|
20
|
+
return finalProps;
|
|
21
|
+
}
|
|
22
|
+
export function normalizeUrlProps(urlProps) {
|
|
23
|
+
const rawSiteUrl = urlProps.siteUrl || 'http://localhost:3000';
|
|
24
|
+
let url;
|
|
25
|
+
try {
|
|
26
|
+
url = new URL(rawSiteUrl);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
throw cliError(`Invalid site URL: "${rawSiteUrl}"`);
|
|
30
|
+
}
|
|
31
|
+
if (!/^https?:$/.test(url.protocol)) {
|
|
32
|
+
throw cliError(`Site URL must use http or https (got ${url.protocol})`);
|
|
33
|
+
}
|
|
34
|
+
if (url.search || url.hash) {
|
|
35
|
+
throw cliError(`Site URL must not include query or hash`);
|
|
36
|
+
}
|
|
37
|
+
const inferredBasePath = url.pathname && url.pathname !== '/'
|
|
38
|
+
? normalizeBasePath(url.pathname)
|
|
39
|
+
: '/';
|
|
40
|
+
let finalBasePath;
|
|
41
|
+
if (urlProps.basePath !== undefined && urlProps.basePath !== '/') {
|
|
42
|
+
const normalizedProvided = normalizeBasePath(urlProps.basePath);
|
|
43
|
+
if (inferredBasePath !== '/' && normalizedProvided !== inferredBasePath) {
|
|
44
|
+
throw cliError(`Conflicting base paths:\n` +
|
|
45
|
+
` Site URL implies base path "${inferredBasePath}"\n` +
|
|
46
|
+
` Explicitly set base path "${normalizedProvided}"\n\n` +
|
|
47
|
+
`Remove one of them or make them match!`);
|
|
48
|
+
}
|
|
49
|
+
finalBasePath = normalizedProvided;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
finalBasePath = inferredBasePath;
|
|
53
|
+
}
|
|
54
|
+
const finalSiteUrl = finalBasePath === '/'
|
|
55
|
+
? `${url.protocol}//${url.host}/`
|
|
56
|
+
: `${url.protocol}//${url.host}${finalBasePath}`;
|
|
57
|
+
return {
|
|
58
|
+
siteUrl: finalSiteUrl,
|
|
59
|
+
basePath: finalBasePath,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function normalizeBasePath(input) {
|
|
63
|
+
if (!input || input === '/')
|
|
64
|
+
return '/';
|
|
65
|
+
if (input.includes('?') || input.includes('#')) {
|
|
66
|
+
throw cliError(`Base path must not contain ? or #`);
|
|
67
|
+
}
|
|
68
|
+
if (input.includes('://')) {
|
|
69
|
+
throw cliError(`Base path must be a path, not a URL`);
|
|
70
|
+
}
|
|
71
|
+
const trimmed = input.replace(/^\/+|\/+$/g, '');
|
|
72
|
+
return trimmed === '' ? '/' : `/${trimmed}/`;
|
|
73
|
+
}
|
|
74
|
+
export function logUrlProps(urlProps) {
|
|
75
|
+
console.log(`Site URL: ${chalk.bold.cyan(urlProps.siteUrl)}`);
|
|
76
|
+
console.log(`Site base path: ${chalk.bold.cyan(urlProps.basePath)}`);
|
|
77
|
+
}
|
package/package.json
CHANGED
|
@@ -1,40 +1,39 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
"name": "@erudit-js/cli",
|
|
3
|
+
"version": "4.0.0-dev.5",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "📟 Command Line Interface for Erudit",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/erudit-js/erudit.git",
|
|
10
|
+
"directory": "packages/cli"
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts"
|
|
11
18
|
},
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
".": {
|
|
16
|
-
"import": "./dist/index.js",
|
|
17
|
-
"types": "./dist/index.d.ts"
|
|
18
|
-
},
|
|
19
|
-
"./cli": "./bin/erudit-cli.js"
|
|
20
|
-
},
|
|
21
|
-
"bin": {
|
|
22
|
-
"erudit-cli": "bin/erudit-cli.js",
|
|
23
|
-
"erudit": "bin/erudit-cli.js"
|
|
24
|
-
},
|
|
25
|
-
"scripts": {
|
|
26
|
-
"build": "rm -rf dist && bun tsc --project ./tsconfig.src.json && bun run postBuild.ts",
|
|
27
|
-
"test": "bun vitest run",
|
|
28
|
-
"prepack": "bun run build"
|
|
29
|
-
},
|
|
30
|
-
"files": [
|
|
31
|
-
"bin",
|
|
32
|
-
"dist"
|
|
33
|
-
],
|
|
34
|
-
"dependencies": {
|
|
35
|
-
"@erudit-js/core": "4.0.0-dev.3",
|
|
36
|
-
"chalk": "^5.6.2",
|
|
37
|
-
"citty": "^0.1.6",
|
|
38
|
-
"consola": "^3.4.2"
|
|
19
|
+
"./cli": {
|
|
20
|
+
"import": "./dist/cli.js",
|
|
21
|
+
"types": "./dist/cli.d.ts"
|
|
39
22
|
}
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "rm -rf dist && bun tsc --project ./tsconfig.src.json && bun run postBuild.ts",
|
|
26
|
+
"test": "bun vitest run",
|
|
27
|
+
"prepack": "bun run build"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@erudit-js/core": "4.0.0-dev.5",
|
|
34
|
+
"http-server": "^14.1.1",
|
|
35
|
+
"chalk": "^5.6.2",
|
|
36
|
+
"citty": "^0.2.0",
|
|
37
|
+
"dotenv": "^17.2.3"
|
|
38
|
+
}
|
|
40
39
|
}
|