@erudit-js/cli 4.0.0-dev.4 → 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 +14 -9
- 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
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Command Line Interface for [Erudit](https://github.com/erudit-js/erudit).
|
|
4
4
|
|
|
5
|
-
CLI is accessible via `erudit`
|
|
5
|
+
CLI is accessible via `erudit` command **only** through installed `erudit` package!
|
|
6
6
|
|
|
7
7
|
## Commands
|
|
8
8
|
|
|
@@ -10,4 +10,4 @@ CLI is accessible via `erudit` or `erudit-cli` commands.
|
|
|
10
10
|
- `build` - compiles Erudit project
|
|
11
11
|
- `launch` - launches compiled Erudit project
|
|
12
12
|
- `generate` - generates a fully static production-ready site from Erudit project
|
|
13
|
-
- `preview` -
|
|
13
|
+
- `preview` - previews generated static site
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runCli(absEruditPath: string): void;
|
package/dist/cli.js
ADDED
package/dist/commands/build.d.ts
CHANGED
|
@@ -1,25 +1,8 @@
|
|
|
1
1
|
export declare const build: import("citty").CommandDef<{
|
|
2
|
-
|
|
3
|
-
type: "string";
|
|
4
|
-
required: false;
|
|
5
|
-
description: string;
|
|
6
|
-
};
|
|
7
|
-
target: {
|
|
8
|
-
type: "string";
|
|
9
|
-
description: string;
|
|
10
|
-
required: false;
|
|
11
|
-
default: string;
|
|
12
|
-
};
|
|
13
|
-
eruditPath: {
|
|
14
|
-
type: "string";
|
|
15
|
-
description: string;
|
|
16
|
-
required: false;
|
|
17
|
-
default: string;
|
|
18
|
-
};
|
|
19
|
-
projectPath: {
|
|
2
|
+
readonly projectPath: {
|
|
20
3
|
type: "positional";
|
|
21
4
|
description: string;
|
|
22
5
|
required: false;
|
|
23
|
-
|
|
6
|
+
valueHint: string;
|
|
24
7
|
};
|
|
25
8
|
}>;
|
package/dist/commands/build.js
CHANGED
|
@@ -1,34 +1,39 @@
|
|
|
1
1
|
import { rmSync } from 'node:fs';
|
|
2
|
-
import consola from 'consola';
|
|
3
2
|
import { defineCommand } from 'citty';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { projectPathArg } from '../shared/args.js';
|
|
4
|
+
import { logProjectPath, normalizeProjectPath, retrieveProjectPath, } from '../shared/projectPath.js';
|
|
5
|
+
import { prepareProject } from '../shared/prepare.js';
|
|
6
6
|
import { spawnNuxt } from '../shared/nuxt.js';
|
|
7
|
-
import {
|
|
7
|
+
import { CONFIG } from '../config.js';
|
|
8
|
+
import { version } from '../inject.js';
|
|
8
9
|
export const build = defineCommand({
|
|
9
10
|
meta: {
|
|
10
|
-
name: '
|
|
11
|
-
description: 'Builds Erudit project for fast
|
|
11
|
+
name: 'build',
|
|
12
|
+
description: 'Builds Erudit project that can be launched for fast content writing',
|
|
12
13
|
},
|
|
13
14
|
args: {
|
|
14
15
|
...projectPathArg,
|
|
15
|
-
...eruditPathArg,
|
|
16
|
-
...contentTargetsArg,
|
|
17
|
-
...nitroPresetArg,
|
|
18
16
|
},
|
|
19
17
|
async run({ args }) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
await
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
const absProjectPath = normalizeProjectPath(retrieveProjectPath(args.projectPath));
|
|
19
|
+
logProjectPath(absProjectPath);
|
|
20
|
+
await prepareProject({
|
|
21
|
+
absProjectPath,
|
|
22
|
+
});
|
|
23
|
+
console.log('Building Erudit Nuxt Layer...');
|
|
24
|
+
await spawnNuxt({
|
|
25
|
+
command: 'build',
|
|
26
|
+
absProjectPath,
|
|
27
|
+
env: {
|
|
28
|
+
ERUDIT_COMMAND: 'build',
|
|
29
|
+
NUXT_ERUDIT_PATH: CONFIG.ERUDIT_PATH,
|
|
30
|
+
NUXT_PROJECT_PATH: absProjectPath,
|
|
31
|
+
NUXT_PUBLIC_ERUDIT_MODE: 'write',
|
|
32
|
+
NUXT_PUBLIC_ERUDIT_VERSION: version,
|
|
33
|
+
},
|
|
26
34
|
});
|
|
27
|
-
const restParams = args.preset ? ` --preset ${args.preset}` : '';
|
|
28
|
-
consola.start('Starting Nuxt build...');
|
|
29
|
-
await spawnNuxt('build', projectPath, restParams);
|
|
30
35
|
// Just fucking remove @jsprose because not a single fucking option inside Nuxt/Nitro allows NOT TO bundle it!
|
|
31
|
-
rmSync(`${
|
|
36
|
+
rmSync(`${absProjectPath}/.output/server/node_modules/@jsprose`, {
|
|
32
37
|
recursive: true,
|
|
33
38
|
force: true,
|
|
34
39
|
});
|
package/dist/commands/dev.d.ts
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
export declare const dev: import("citty").CommandDef<{
|
|
2
|
-
target: {
|
|
2
|
+
readonly target: {
|
|
3
3
|
type: "string";
|
|
4
4
|
description: string;
|
|
5
5
|
required: false;
|
|
6
|
-
|
|
6
|
+
valueHint: string;
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
readonly basePath: {
|
|
9
9
|
type: "string";
|
|
10
10
|
description: string;
|
|
11
11
|
required: false;
|
|
12
|
-
|
|
12
|
+
valueHint: string;
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
readonly siteUrl: {
|
|
15
|
+
type: "string";
|
|
16
|
+
description: string;
|
|
17
|
+
required: false;
|
|
18
|
+
valueHint: string;
|
|
19
|
+
};
|
|
20
|
+
readonly projectPath: {
|
|
15
21
|
type: "positional";
|
|
16
22
|
description: string;
|
|
17
23
|
required: false;
|
|
18
|
-
|
|
24
|
+
valueHint: string;
|
|
19
25
|
};
|
|
20
26
|
}>;
|
package/dist/commands/dev.js
CHANGED
|
@@ -1,28 +1,46 @@
|
|
|
1
|
-
import { consola } from 'consola';
|
|
2
1
|
import { defineCommand } from 'citty';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { prepareProject } from '../shared/prepare.js';
|
|
3
|
+
import { projectPathArg, siteUrlArg, basePathArg, contentTargetsArg, } from '../shared/args.js';
|
|
4
|
+
import { logProjectPath, normalizeProjectPath, retrieveProjectPath, } from '../shared/projectPath.js';
|
|
5
|
+
import { logUrlProps, normalizeUrlProps, retrieveUrlProps, } from '../shared/urlProps.js';
|
|
6
|
+
import { loadEnvFiles } from '../shared/env.js';
|
|
5
7
|
import { spawnNuxt } from '../shared/nuxt.js';
|
|
6
|
-
import {
|
|
8
|
+
import { CONFIG } from '../config.js';
|
|
9
|
+
import { version } from '../inject.js';
|
|
7
10
|
export const dev = defineCommand({
|
|
8
11
|
meta: {
|
|
9
|
-
name: '
|
|
12
|
+
name: 'dev',
|
|
10
13
|
description: 'Runs Erudit project in development mode',
|
|
11
14
|
},
|
|
12
15
|
args: {
|
|
13
16
|
...projectPathArg,
|
|
14
|
-
...
|
|
17
|
+
...siteUrlArg,
|
|
18
|
+
...basePathArg,
|
|
15
19
|
...contentTargetsArg,
|
|
16
20
|
},
|
|
17
21
|
async run({ args }) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const absProjectPath = normalizeProjectPath(retrieveProjectPath(args.projectPath));
|
|
23
|
+
logProjectPath(absProjectPath);
|
|
24
|
+
loadEnvFiles([`${absProjectPath}/.env.dev`, `${absProjectPath}/.env`]);
|
|
25
|
+
const urlProps = normalizeUrlProps(retrieveUrlProps(args.siteUrl, args.basePath));
|
|
26
|
+
logUrlProps(urlProps);
|
|
27
|
+
await prepareProject({
|
|
28
|
+
absProjectPath,
|
|
29
|
+
});
|
|
30
|
+
console.log('Launching Erudit Nuxt Layer in development mode...');
|
|
31
|
+
await spawnNuxt({
|
|
32
|
+
command: 'dev',
|
|
33
|
+
absProjectPath,
|
|
34
|
+
env: {
|
|
35
|
+
ERUDIT_COMMAND: 'dev',
|
|
36
|
+
NUXT_ERUDIT_PATH: CONFIG.ERUDIT_PATH,
|
|
37
|
+
NUXT_PROJECT_PATH: absProjectPath,
|
|
38
|
+
NUXT_CONTENT_TARGETS: args.target ?? '',
|
|
39
|
+
NUXT_PUBLIC_ERUDIT_MODE: 'dev',
|
|
40
|
+
NUXT_PUBLIC_ERUDIT_VERSION: version,
|
|
41
|
+
NUXT_APP_BASE_URL: urlProps.basePath,
|
|
42
|
+
NUXT_PUBLIC_SITE_URL: urlProps.siteUrl,
|
|
43
|
+
},
|
|
24
44
|
});
|
|
25
|
-
consola.start('Starting Nuxt dev...');
|
|
26
|
-
await spawnNuxt('dev', projectPath);
|
|
27
45
|
},
|
|
28
46
|
});
|
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
export declare const generate: import("citty").CommandDef<{
|
|
2
|
-
preset: {
|
|
2
|
+
readonly preset: {
|
|
3
3
|
type: "string";
|
|
4
4
|
required: false;
|
|
5
5
|
description: string;
|
|
6
6
|
};
|
|
7
|
-
target: {
|
|
7
|
+
readonly target: {
|
|
8
8
|
type: "string";
|
|
9
9
|
description: string;
|
|
10
10
|
required: false;
|
|
11
|
-
|
|
11
|
+
valueHint: string;
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
readonly basePath: {
|
|
14
14
|
type: "string";
|
|
15
15
|
description: string;
|
|
16
16
|
required: false;
|
|
17
|
-
|
|
17
|
+
valueHint: string;
|
|
18
18
|
};
|
|
19
|
-
|
|
19
|
+
readonly siteUrl: {
|
|
20
|
+
type: "string";
|
|
21
|
+
description: string;
|
|
22
|
+
required: false;
|
|
23
|
+
valueHint: string;
|
|
24
|
+
};
|
|
25
|
+
readonly projectPath: {
|
|
20
26
|
type: "positional";
|
|
21
27
|
description: string;
|
|
22
28
|
required: false;
|
|
23
|
-
|
|
29
|
+
valueHint: string;
|
|
24
30
|
};
|
|
25
31
|
}>;
|
|
@@ -1,29 +1,49 @@
|
|
|
1
1
|
import { defineCommand } from 'citty';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { prepare } from '../shared/prepare.js';
|
|
2
|
+
import { basePathArg, contentTargetsArg, nitroPresetArg, projectPathArg, siteUrlArg, } from '../shared/args.js';
|
|
3
|
+
import { prepareProject } from '../shared/prepare.js';
|
|
5
4
|
import { spawnNuxt } from '../shared/nuxt.js';
|
|
5
|
+
import { logProjectPath, normalizeProjectPath, retrieveProjectPath, } from '../shared/projectPath.js';
|
|
6
|
+
import { loadEnvFiles } from '../shared/env.js';
|
|
7
|
+
import { logUrlProps, normalizeUrlProps, retrieveUrlProps, } from '../shared/urlProps.js';
|
|
8
|
+
import { version } from '../inject.js';
|
|
9
|
+
import { CONFIG } from '../config.js';
|
|
6
10
|
export const generate = defineCommand({
|
|
7
11
|
meta: {
|
|
8
|
-
name: '
|
|
9
|
-
description: 'Generates static production-ready site from Erudit project',
|
|
12
|
+
name: 'generate',
|
|
13
|
+
description: 'Generates fully static production-ready site from Erudit project',
|
|
10
14
|
},
|
|
11
15
|
args: {
|
|
12
16
|
...projectPathArg,
|
|
13
|
-
...
|
|
17
|
+
...siteUrlArg,
|
|
18
|
+
...basePathArg,
|
|
14
19
|
...contentTargetsArg,
|
|
15
20
|
...nitroPresetArg,
|
|
16
21
|
},
|
|
17
22
|
async run({ args }) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
const absProjectPath = normalizeProjectPath(retrieveProjectPath(args.projectPath));
|
|
24
|
+
logProjectPath(absProjectPath);
|
|
25
|
+
loadEnvFiles([`${absProjectPath}/.env.prod`, `${absProjectPath}/.env`]);
|
|
26
|
+
const urlProps = normalizeUrlProps(retrieveUrlProps(args.siteUrl, args.basePath));
|
|
27
|
+
logUrlProps(urlProps);
|
|
28
|
+
await prepareProject({
|
|
29
|
+
absProjectPath,
|
|
30
|
+
});
|
|
31
|
+
const nitroPreset = args.nitroPreset || process.env.ERUDIT_NITRO_PRESET;
|
|
32
|
+
console.log('Generating static site from Erudit Nuxt Layer...');
|
|
33
|
+
await spawnNuxt({
|
|
34
|
+
command: 'generate',
|
|
35
|
+
absProjectPath,
|
|
36
|
+
restArgs: nitroPreset ? `--preset ${nitroPreset}` : '',
|
|
37
|
+
env: {
|
|
38
|
+
ERUDIT_COMMAND: 'generate',
|
|
39
|
+
NUXT_ERUDIT_PATH: CONFIG.ERUDIT_PATH,
|
|
40
|
+
NUXT_PROJECT_PATH: absProjectPath,
|
|
41
|
+
NUXT_CONTENT_TARGETS: args.target ?? '',
|
|
42
|
+
NUXT_PUBLIC_ERUDIT_MODE: 'static',
|
|
43
|
+
NUXT_PUBLIC_ERUDIT_VERSION: version,
|
|
44
|
+
NUXT_APP_BASE_URL: urlProps.basePath,
|
|
45
|
+
NUXT_PUBLIC_SITE_URL: urlProps.siteUrl,
|
|
46
|
+
},
|
|
24
47
|
});
|
|
25
|
-
const restParams = args.preset ? `--preset ${args.preset}` : '';
|
|
26
|
-
console.log('Starting Nuxt generate...');
|
|
27
|
-
await spawnNuxt('generate', projectPath, restParams);
|
|
28
48
|
},
|
|
29
49
|
});
|
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
export declare const launch: import("citty").CommandDef<{
|
|
2
|
-
|
|
2
|
+
readonly target: {
|
|
3
|
+
type: "string";
|
|
4
|
+
description: string;
|
|
5
|
+
required: false;
|
|
6
|
+
valueHint: string;
|
|
7
|
+
};
|
|
8
|
+
readonly basePath: {
|
|
9
|
+
type: "string";
|
|
10
|
+
description: string;
|
|
11
|
+
required: false;
|
|
12
|
+
valueHint: string;
|
|
13
|
+
};
|
|
14
|
+
readonly siteUrl: {
|
|
15
|
+
type: "string";
|
|
16
|
+
description: string;
|
|
17
|
+
required: false;
|
|
18
|
+
valueHint: string;
|
|
19
|
+
};
|
|
20
|
+
readonly projectPath: {
|
|
3
21
|
type: "positional";
|
|
4
22
|
description: string;
|
|
5
23
|
required: false;
|
|
6
|
-
|
|
24
|
+
valueHint: string;
|
|
7
25
|
};
|
|
8
26
|
}>;
|
package/dist/commands/launch.js
CHANGED
|
@@ -1,38 +1,49 @@
|
|
|
1
|
-
import { defineCommand } from 'citty';
|
|
2
|
-
import { consola } from 'consola';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
1
|
import { existsSync } from 'node:fs';
|
|
5
2
|
import { spawn } from 'node:child_process';
|
|
6
|
-
import {
|
|
3
|
+
import { defineCommand } from 'citty';
|
|
4
|
+
import { basePathArg, contentTargetsArg, projectPathArg, siteUrlArg, } from '../shared/args.js';
|
|
5
|
+
import { logProjectPath, normalizeProjectPath, retrieveProjectPath, } from '../shared/projectPath.js';
|
|
6
|
+
import { loadEnvFiles } from '../shared/env.js';
|
|
7
|
+
import { logUrlProps, normalizeUrlProps, retrieveUrlProps, } from '../shared/urlProps.js';
|
|
8
|
+
import { cliError } from '../shared/cliError.js';
|
|
9
|
+
import { CONFIG } from '../config.js';
|
|
10
|
+
import { version } from '../inject.js';
|
|
7
11
|
export const launch = defineCommand({
|
|
8
12
|
meta: {
|
|
9
|
-
name: '
|
|
10
|
-
description: '
|
|
13
|
+
name: 'launch',
|
|
14
|
+
description: 'Launchs already built Erudit project for content writing',
|
|
11
15
|
},
|
|
12
16
|
args: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
default: '.',
|
|
18
|
-
},
|
|
17
|
+
...projectPathArg,
|
|
18
|
+
...siteUrlArg,
|
|
19
|
+
...basePathArg,
|
|
20
|
+
...contentTargetsArg,
|
|
19
21
|
},
|
|
20
22
|
async run({ args }) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
const absProjectPath = normalizeProjectPath(retrieveProjectPath(args.projectPath));
|
|
24
|
+
logProjectPath(absProjectPath);
|
|
25
|
+
loadEnvFiles([`${absProjectPath}/.env.prod`, `${absProjectPath}/.env`]);
|
|
26
|
+
const urlProps = normalizeUrlProps(retrieveUrlProps(args.siteUrl, args.basePath));
|
|
27
|
+
logUrlProps(urlProps);
|
|
28
|
+
const logProjectPathStr = args.projectPath ? ` "${args.projectPath}"` : '';
|
|
29
|
+
const didYouRun = `Did you run 'erudit build${logProjectPathStr}'?`;
|
|
30
|
+
const serverIndexPath = `${absProjectPath}/.output/server/index.mjs`;
|
|
31
|
+
if (!existsSync(serverIndexPath)) {
|
|
32
|
+
throw cliError(`Failed to find built Erudit project at "${absProjectPath}"!\n${didYouRun}`);
|
|
33
|
+
}
|
|
34
|
+
console.log('Launching Erudit project...');
|
|
35
|
+
spawn('node', [serverIndexPath], {
|
|
29
36
|
stdio: 'inherit',
|
|
30
37
|
env: {
|
|
31
|
-
...process.env,
|
|
32
38
|
ERUDIT_COMMAND: 'launch',
|
|
33
|
-
|
|
39
|
+
NUXT_ERUDIT_PATH: CONFIG.ERUDIT_PATH,
|
|
40
|
+
NUXT_PROJECT_PATH: absProjectPath,
|
|
41
|
+
NUXT_CONTENT_TARGETS: args.target,
|
|
42
|
+
NUXT_PUBLIC_ERUDIT_MODE: 'write',
|
|
43
|
+
NUXT_PUBLIC_ERUDIT_VERSION: version,
|
|
44
|
+
NUXT_APP_BASE_URL: urlProps.basePath,
|
|
45
|
+
NUXT_PUBLIC_SITE_URL: urlProps.siteUrl,
|
|
34
46
|
},
|
|
35
|
-
cwd: distPath,
|
|
36
47
|
});
|
|
37
48
|
},
|
|
38
49
|
});
|
package/dist/commands/main.js
CHANGED
|
@@ -1,31 +1,36 @@
|
|
|
1
1
|
import { defineCommand } from 'citty';
|
|
2
|
+
import chalk from 'chalk';
|
|
2
3
|
import { brandColorLogotype } from '@erudit-js/core/brandTerminal';
|
|
4
|
+
import { version } from '../inject.js';
|
|
5
|
+
import { logCommand } from '../shared/logCommand.js';
|
|
6
|
+
import { CONFIG } from '../config.js';
|
|
3
7
|
// Sub commands
|
|
4
|
-
import { init } from './init.js';
|
|
5
8
|
import { prepare } from './prepare.js';
|
|
6
9
|
import { dev } from './dev.js';
|
|
7
10
|
import { build } from './build.js';
|
|
8
|
-
import { preview } from './preview.js';
|
|
9
11
|
import { launch } from './launch.js';
|
|
10
12
|
import { generate } from './generate.js';
|
|
11
|
-
|
|
13
|
+
import { preview } from './preview.js';
|
|
12
14
|
export const main = defineCommand({
|
|
13
15
|
meta: {
|
|
14
|
-
name: '
|
|
15
|
-
description: '
|
|
16
|
+
name: 'erudit',
|
|
17
|
+
description: 'CLI for Erudit',
|
|
16
18
|
version,
|
|
17
19
|
},
|
|
18
20
|
subCommands: {
|
|
19
|
-
init,
|
|
20
21
|
prepare,
|
|
21
22
|
dev,
|
|
22
23
|
build,
|
|
24
|
+
launch,
|
|
23
25
|
generate,
|
|
24
26
|
preview,
|
|
25
|
-
launch,
|
|
26
27
|
},
|
|
27
|
-
setup() {
|
|
28
|
+
setup({ args }) {
|
|
28
29
|
console.log(brandColorLogotype);
|
|
29
|
-
console.log(`Version ${version}
|
|
30
|
+
console.log(`Version: ${chalk.bold.cyan(version)}`);
|
|
31
|
+
if (args._[0]) {
|
|
32
|
+
logCommand(args._[0]);
|
|
33
|
+
}
|
|
34
|
+
console.log(`Erudit path: ${chalk.bold.cyan(CONFIG.ERUDIT_PATH)}`);
|
|
30
35
|
},
|
|
31
36
|
});
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
export declare const prepare: import("citty").CommandDef<{
|
|
2
|
-
|
|
3
|
-
type: "string";
|
|
4
|
-
description: string;
|
|
5
|
-
required: false;
|
|
6
|
-
default: string;
|
|
7
|
-
};
|
|
8
|
-
projectPath: {
|
|
2
|
+
readonly projectPath: {
|
|
9
3
|
type: "positional";
|
|
10
4
|
description: string;
|
|
11
5
|
required: false;
|
|
12
|
-
|
|
6
|
+
valueHint: string;
|
|
13
7
|
};
|
|
14
8
|
}>;
|
package/dist/commands/prepare.js
CHANGED
|
@@ -1,27 +1,35 @@
|
|
|
1
|
-
import { consola } from 'consola';
|
|
2
1
|
import { defineCommand } from 'citty';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { projectPathArg } from '../shared/args.js';
|
|
3
|
+
import { logProjectPath, normalizeProjectPath, retrieveProjectPath, } from '../shared/projectPath.js';
|
|
4
|
+
import { prepareProject } from '../shared/prepare.js';
|
|
5
5
|
import { spawnNuxt } from '../shared/nuxt.js';
|
|
6
|
-
import {
|
|
6
|
+
import { CONFIG } from '../config.js';
|
|
7
|
+
import { version } from '../inject.js';
|
|
7
8
|
export const prepare = defineCommand({
|
|
8
9
|
meta: {
|
|
9
|
-
name: '
|
|
10
|
-
description: 'Creates
|
|
10
|
+
name: 'prepare',
|
|
11
|
+
description: 'Creates necessary files for Erudit project',
|
|
11
12
|
},
|
|
12
13
|
args: {
|
|
13
14
|
...projectPathArg,
|
|
14
|
-
...eruditPathArg,
|
|
15
15
|
},
|
|
16
16
|
async run({ args }) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
await
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
const absProjectPath = normalizeProjectPath(retrieveProjectPath(args.projectPath));
|
|
18
|
+
logProjectPath(absProjectPath);
|
|
19
|
+
await prepareProject({
|
|
20
|
+
absProjectPath,
|
|
21
|
+
});
|
|
22
|
+
console.log('Preparing Erudit Nuxt Layer...');
|
|
23
|
+
await spawnNuxt({
|
|
24
|
+
command: 'prepare',
|
|
25
|
+
absProjectPath,
|
|
26
|
+
env: {
|
|
27
|
+
ERUDIT_COMMAND: 'prepare',
|
|
28
|
+
NUXT_ERUDIT_PATH: CONFIG.ERUDIT_PATH,
|
|
29
|
+
NUXT_PROJECT_PATH: absProjectPath,
|
|
30
|
+
NUXT_PUBLIC_ERUDIT_MODE: 'write',
|
|
31
|
+
NUXT_PUBLIC_ERUDIT_VERSION: version,
|
|
32
|
+
},
|
|
22
33
|
});
|
|
23
|
-
consola.start('Generating Nuxt build files...');
|
|
24
|
-
await spawnNuxt('prepare', projectPath);
|
|
25
|
-
consola.success('Nuxt is prepared!');
|
|
26
34
|
},
|
|
27
35
|
});
|
package/dist/commands/preview.js
CHANGED
|
@@ -1,37 +1,64 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
2
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
3
|
+
import { join, relative, sep } from 'node:path';
|
|
3
4
|
import { defineCommand } from 'citty';
|
|
4
|
-
import { consola } from 'consola';
|
|
5
5
|
import chalk from 'chalk';
|
|
6
|
-
import {
|
|
6
|
+
import { projectPathArg } from '../shared/args.js';
|
|
7
|
+
import { logProjectPath, normalizeProjectPath, retrieveProjectPath, } from '../shared/projectPath.js';
|
|
8
|
+
import { cliError } from '../shared/cliError.js';
|
|
7
9
|
export const preview = defineCommand({
|
|
8
10
|
meta: {
|
|
9
|
-
name: '
|
|
10
|
-
description: '
|
|
11
|
+
name: 'preview',
|
|
12
|
+
description: 'Previews already generated static Erudit site',
|
|
11
13
|
},
|
|
12
14
|
args: {
|
|
13
|
-
|
|
14
|
-
type: 'positional',
|
|
15
|
-
description: 'Project path',
|
|
16
|
-
required: false,
|
|
17
|
-
default: '.',
|
|
18
|
-
},
|
|
15
|
+
...projectPathArg,
|
|
19
16
|
},
|
|
20
17
|
async run({ args }) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
18
|
+
const absProjectPath = normalizeProjectPath(retrieveProjectPath(args.projectPath));
|
|
19
|
+
logProjectPath(absProjectPath);
|
|
20
|
+
const distPath = `${absProjectPath}/.output/public`;
|
|
21
|
+
const logProjectPathStr = args.projectPath ? ` "${args.projectPath}"` : '';
|
|
22
|
+
const didYouRun = `Did you run 'erudit generate${logProjectPathStr}'?`;
|
|
25
23
|
if (!existsSync(distPath)) {
|
|
26
|
-
throw
|
|
24
|
+
throw cliError(`Failed to find generated static Erudit site at "${absProjectPath}"!\n${didYouRun}`);
|
|
27
25
|
}
|
|
28
|
-
|
|
26
|
+
const possibleBasePath = findBasePath(distPath);
|
|
27
|
+
if (!possibleBasePath) {
|
|
28
|
+
throw cliError(`Failed to find valid entry point (index.html with _nuxt directory) in generated static Erudit site!\n${didYouRun}`);
|
|
29
|
+
}
|
|
30
|
+
console.log(`Launching static site preview...\n → ${chalk.underline.cyan(`http://localhost:3000${possibleBasePath}`)}\n`);
|
|
31
|
+
spawn(`http-server ${distPath} -p 3000`, {
|
|
29
32
|
shell: true,
|
|
30
33
|
stdio: 'inherit',
|
|
31
|
-
env:
|
|
32
|
-
...process.env,
|
|
33
|
-
ERUDIT_MODE: 'static',
|
|
34
|
-
},
|
|
34
|
+
env: process.env,
|
|
35
35
|
});
|
|
36
36
|
},
|
|
37
37
|
});
|
|
38
|
+
function findBasePath(rootDir) {
|
|
39
|
+
const queue = [rootDir];
|
|
40
|
+
while (queue.length > 0) {
|
|
41
|
+
const currentDir = queue.shift();
|
|
42
|
+
if (!currentDir)
|
|
43
|
+
continue;
|
|
44
|
+
const hasIndexHtml = existsSync(join(currentDir, 'index.html'));
|
|
45
|
+
const hasNuxtDir = existsSync(join(currentDir, '_nuxt'));
|
|
46
|
+
if (hasIndexHtml && hasNuxtDir) {
|
|
47
|
+
const rel = relative(rootDir, currentDir);
|
|
48
|
+
const urlPath = rel.split(sep).join('/');
|
|
49
|
+
return urlPath ? `/${urlPath}/` : '/';
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const entries = readdirSync(currentDir, { withFileTypes: true });
|
|
53
|
+
for (const entry of entries) {
|
|
54
|
+
if (entry.isDirectory()) {
|
|
55
|
+
queue.push(join(currentDir, entry.name));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { version } from './inject.js';
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { version } from './inject.js';
|
package/dist/inject.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "{{ VERSION }}";
|