@erudit-js/cli 3.0.0-dev.9 → 4.0.0-dev.1
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 +13 -12
- package/bin/erudit-cli.js +5 -0
- package/dist/commands/build.d.ts +25 -0
- package/dist/commands/build.js +36 -0
- package/dist/commands/dev.d.ts +20 -0
- package/dist/commands/dev.js +28 -0
- package/dist/commands/generate.d.ts +25 -0
- package/dist/commands/generate.js +29 -0
- package/dist/commands/init.d.ts +8 -0
- package/dist/commands/init.js +60 -0
- package/dist/commands/launch.d.ts +8 -0
- package/dist/commands/launch.js +38 -0
- package/dist/commands/main.d.ts +1 -0
- package/dist/commands/main.js +29 -0
- package/dist/commands/prepare.d.ts +14 -0
- package/dist/commands/prepare.js +27 -0
- package/dist/commands/preview.d.ts +8 -0
- package/dist/commands/preview.js +37 -0
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -0
- package/dist/run.d.ts +1 -0
- package/dist/run.js +5 -0
- package/dist/shared/args.d.ts +35 -0
- package/dist/shared/args.js +52 -0
- package/dist/shared/log.d.ts +1 -0
- package/dist/shared/log.js +6 -0
- package/dist/shared/nuxt.d.ts +3 -0
- package/dist/shared/nuxt.js +50 -0
- package/dist/shared/path.d.ts +1 -0
- package/dist/shared/path.js +13 -0
- package/dist/shared/prepare.d.ts +7 -0
- package/dist/shared/prepare.js +92 -0
- package/package.json +15 -14
- package/bin/erudit-cli.mjs +0 -5
- package/dist/index.d.mts +0 -3
- package/dist/index.mjs +0 -411
package/README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
# 📟 Erudit CLI
|
|
2
|
-
|
|
3
|
-
Command Line Interface for [Erudit](https://github.com/erudit-js/erudit).
|
|
4
|
-
|
|
5
|
-
CLI is accessible via `erudit` or `erudit-cli` commands.
|
|
6
|
-
|
|
7
|
-
## Commands
|
|
8
|
-
|
|
9
|
-
- `
|
|
10
|
-
- `
|
|
11
|
-
- `
|
|
12
|
-
- `
|
|
1
|
+
# 📟 Erudit CLI
|
|
2
|
+
|
|
3
|
+
Command Line Interface for [Erudit](https://github.com/erudit-js/erudit).
|
|
4
|
+
|
|
5
|
+
CLI is accessible via `erudit` or `erudit-cli` commands.
|
|
6
|
+
|
|
7
|
+
## Commands
|
|
8
|
+
|
|
9
|
+
- `play` - starts an Erudit project in full dev mode
|
|
10
|
+
- `build` - compiles Erudit project
|
|
11
|
+
- `launch` - launches compiled Erudit project
|
|
12
|
+
- `generate` - generates a fully static production-ready site from Erudit project
|
|
13
|
+
- `preview` - preview generated static site
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const build: import("citty").CommandDef<{
|
|
2
|
+
preset: {
|
|
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: {
|
|
20
|
+
type: "positional";
|
|
21
|
+
description: string;
|
|
22
|
+
required: false;
|
|
23
|
+
default: string;
|
|
24
|
+
};
|
|
25
|
+
}>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { rmSync } from 'node:fs';
|
|
2
|
+
import consola from 'consola';
|
|
3
|
+
import { defineCommand } from 'citty';
|
|
4
|
+
import { contentTargetsArg, eruditPathArg, nitroPresetArg, projectPathArg, resolveArgPaths, } from '../shared/args.js';
|
|
5
|
+
import { logCommand } from '../shared/log.js';
|
|
6
|
+
import { spawnNuxt } from '../shared/nuxt.js';
|
|
7
|
+
import { prepare } from '../shared/prepare.js';
|
|
8
|
+
export const build = defineCommand({
|
|
9
|
+
meta: {
|
|
10
|
+
name: 'Build',
|
|
11
|
+
description: 'Builds Erudit project for fast and convenient content writing',
|
|
12
|
+
},
|
|
13
|
+
args: {
|
|
14
|
+
...projectPathArg,
|
|
15
|
+
...eruditPathArg,
|
|
16
|
+
...contentTargetsArg,
|
|
17
|
+
...nitroPresetArg,
|
|
18
|
+
},
|
|
19
|
+
async run({ args }) {
|
|
20
|
+
logCommand('build');
|
|
21
|
+
const { projectPath, eruditPath } = resolveArgPaths(args.projectPath, args.eruditPath);
|
|
22
|
+
await prepare({
|
|
23
|
+
projectPath,
|
|
24
|
+
eruditPath,
|
|
25
|
+
contentTargets: args.target,
|
|
26
|
+
});
|
|
27
|
+
const restParams = args.preset ? ` --preset ${args.preset}` : '';
|
|
28
|
+
consola.start('Starting Nuxt build...');
|
|
29
|
+
await spawnNuxt('build', projectPath, restParams);
|
|
30
|
+
// Just fucking remove @jsprose because not a single fucking option inside Nuxt/Nitro allows NOT TO bundle it!
|
|
31
|
+
rmSync(`${projectPath}/.output/server/node_modules/@jsprose`, {
|
|
32
|
+
recursive: true,
|
|
33
|
+
force: true,
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const dev: import("citty").CommandDef<{
|
|
2
|
+
target: {
|
|
3
|
+
type: "string";
|
|
4
|
+
description: string;
|
|
5
|
+
required: false;
|
|
6
|
+
default: string;
|
|
7
|
+
};
|
|
8
|
+
eruditPath: {
|
|
9
|
+
type: "string";
|
|
10
|
+
description: string;
|
|
11
|
+
required: false;
|
|
12
|
+
default: string;
|
|
13
|
+
};
|
|
14
|
+
projectPath: {
|
|
15
|
+
type: "positional";
|
|
16
|
+
description: string;
|
|
17
|
+
required: false;
|
|
18
|
+
default: string;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { consola } from 'consola';
|
|
2
|
+
import { defineCommand } from 'citty';
|
|
3
|
+
import { logCommand } from '../shared/log.js';
|
|
4
|
+
import { prepare } from '../shared/prepare.js';
|
|
5
|
+
import { spawnNuxt } from '../shared/nuxt.js';
|
|
6
|
+
import { contentTargetsArg, eruditPathArg, projectPathArg, resolveArgPaths, } from '../shared/args.js';
|
|
7
|
+
export const dev = defineCommand({
|
|
8
|
+
meta: {
|
|
9
|
+
name: 'Dev',
|
|
10
|
+
description: 'Runs Erudit project in development mode',
|
|
11
|
+
},
|
|
12
|
+
args: {
|
|
13
|
+
...projectPathArg,
|
|
14
|
+
...eruditPathArg,
|
|
15
|
+
...contentTargetsArg,
|
|
16
|
+
},
|
|
17
|
+
async run({ args }) {
|
|
18
|
+
logCommand('dev');
|
|
19
|
+
const { projectPath, eruditPath } = resolveArgPaths(args.projectPath, args.eruditPath);
|
|
20
|
+
await prepare({
|
|
21
|
+
projectPath,
|
|
22
|
+
eruditPath,
|
|
23
|
+
contentTargets: args.target,
|
|
24
|
+
});
|
|
25
|
+
consola.start('Starting Nuxt dev...');
|
|
26
|
+
await spawnNuxt('dev', projectPath);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const generate: import("citty").CommandDef<{
|
|
2
|
+
preset: {
|
|
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: {
|
|
20
|
+
type: "positional";
|
|
21
|
+
description: string;
|
|
22
|
+
required: false;
|
|
23
|
+
default: string;
|
|
24
|
+
};
|
|
25
|
+
}>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import { contentTargetsArg, eruditPathArg, nitroPresetArg, projectPathArg, resolveArgPaths, } from '../shared/args.js';
|
|
3
|
+
import { logCommand } from '../shared/log.js';
|
|
4
|
+
import { prepare } from '../shared/prepare.js';
|
|
5
|
+
import { spawnNuxt } from '../shared/nuxt.js';
|
|
6
|
+
export const generate = defineCommand({
|
|
7
|
+
meta: {
|
|
8
|
+
name: 'Generate',
|
|
9
|
+
description: 'Generates static production-ready site from Erudit project',
|
|
10
|
+
},
|
|
11
|
+
args: {
|
|
12
|
+
...projectPathArg,
|
|
13
|
+
...eruditPathArg,
|
|
14
|
+
...contentTargetsArg,
|
|
15
|
+
...nitroPresetArg,
|
|
16
|
+
},
|
|
17
|
+
async run({ args }) {
|
|
18
|
+
logCommand('generate');
|
|
19
|
+
const { projectPath, eruditPath } = resolveArgPaths(args.projectPath, args.eruditPath);
|
|
20
|
+
await prepare({
|
|
21
|
+
projectPath,
|
|
22
|
+
eruditPath,
|
|
23
|
+
contentTargets: args.target,
|
|
24
|
+
});
|
|
25
|
+
const restParams = args.preset ? `--preset ${args.preset}` : '';
|
|
26
|
+
console.log('Starting Nuxt generate...');
|
|
27
|
+
await spawnNuxt('generate', projectPath, restParams);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import { consola } from 'consola';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { existsSync, mkdirSync, readdirSync, rmSync, writeFileSync, } from 'node:fs';
|
|
5
|
+
import { resolvePath } from '../shared/path.js';
|
|
6
|
+
export const init = defineCommand({
|
|
7
|
+
meta: {
|
|
8
|
+
name: 'Init',
|
|
9
|
+
description: 'Creates a new Erudit project at specified path',
|
|
10
|
+
},
|
|
11
|
+
args: {
|
|
12
|
+
path: {
|
|
13
|
+
type: 'positional',
|
|
14
|
+
description: 'Path for the new Erudit project',
|
|
15
|
+
required: true,
|
|
16
|
+
valueHint: chalk.gray(`"${chalk.greenBright('.')}" OR "${chalk.greenBright('path/to/project')}"`),
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
async run({ args }) {
|
|
20
|
+
consola.start('Resolving project path...');
|
|
21
|
+
const projectPath = resolvePath(args.path);
|
|
22
|
+
if (projectPath === undefined)
|
|
23
|
+
return;
|
|
24
|
+
if (existsSync(projectPath) && readdirSync(projectPath).length > 0)
|
|
25
|
+
throw new Error(`Directory "${chalk.yellowBright(projectPath)}" is not empty!`);
|
|
26
|
+
consola.success('Resolved project path:', chalk.greenBright(projectPath));
|
|
27
|
+
consola.start('Creating project directory...');
|
|
28
|
+
try {
|
|
29
|
+
try {
|
|
30
|
+
rmSync(projectPath, { recursive: true });
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (error?.code !== 'ENOENT') {
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
mkdirSync(projectPath, { recursive: true });
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw new Error(`Failed to prepare project directory "${chalk.yellowBright(projectPath)}"!\n\n${error}`);
|
|
41
|
+
}
|
|
42
|
+
consola.success('Project directory created!');
|
|
43
|
+
consola.start('Creating project files...');
|
|
44
|
+
consola.success('Project files created!');
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
function createPackageJson(projectPath) {
|
|
48
|
+
// TODO: Get correct package versions
|
|
49
|
+
writeFileSync(`${projectPath}/package.json`, JSON.stringify({
|
|
50
|
+
private: true,
|
|
51
|
+
name: projectPath.split('/').pop() || 'my-erudit-project',
|
|
52
|
+
type: 'module',
|
|
53
|
+
scripts: {
|
|
54
|
+
dev: 'erudit dev',
|
|
55
|
+
build: 'erudit build',
|
|
56
|
+
preview: 'erudit preview',
|
|
57
|
+
prepare: 'erudit prepare',
|
|
58
|
+
},
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import { consola } from 'consola';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
import { spawn } from 'node:child_process';
|
|
6
|
+
import { resolvePath } from '../shared/path.js';
|
|
7
|
+
export const launch = defineCommand({
|
|
8
|
+
meta: {
|
|
9
|
+
name: 'Launch',
|
|
10
|
+
description: 'Launch builded Erudit server',
|
|
11
|
+
},
|
|
12
|
+
args: {
|
|
13
|
+
project: {
|
|
14
|
+
type: 'positional',
|
|
15
|
+
description: 'Project path',
|
|
16
|
+
required: false,
|
|
17
|
+
default: '.',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
async run({ args }) {
|
|
21
|
+
consola.start('Resolving project path...');
|
|
22
|
+
const projectPath = resolvePath(args.project);
|
|
23
|
+
consola.success('Resolved project path:', chalk.greenBright(projectPath));
|
|
24
|
+
const distPath = `${projectPath}/.output/server`;
|
|
25
|
+
if (!existsSync(distPath))
|
|
26
|
+
throw new Error(`No ".output/server" folder found! Did you run 'erudit build'?`);
|
|
27
|
+
spawn(`node index.mjs`, {
|
|
28
|
+
shell: true,
|
|
29
|
+
stdio: 'inherit',
|
|
30
|
+
env: {
|
|
31
|
+
...process.env,
|
|
32
|
+
ERUDIT_COMMAND: 'launch',
|
|
33
|
+
ERUDIT_MODE: 'write',
|
|
34
|
+
},
|
|
35
|
+
cwd: distPath,
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const main: import("citty").CommandDef<import("citty").ArgsDef>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import { brandColorLogotype } from '@erudit-js/core/brandTerminal';
|
|
3
|
+
// Sub commands
|
|
4
|
+
import { init } from './init.js';
|
|
5
|
+
import { prepare } from './prepare.js';
|
|
6
|
+
import { dev } from './dev.js';
|
|
7
|
+
import { build } from './build.js';
|
|
8
|
+
import { preview } from './preview.js';
|
|
9
|
+
import { launch } from './launch.js';
|
|
10
|
+
import { generate } from './generate.js';
|
|
11
|
+
export const main = defineCommand({
|
|
12
|
+
meta: {
|
|
13
|
+
name: 'Erudit CLI',
|
|
14
|
+
description: 'Command Line Interface for Erudit!',
|
|
15
|
+
version: '4.0.0-dev.1',
|
|
16
|
+
},
|
|
17
|
+
subCommands: {
|
|
18
|
+
init,
|
|
19
|
+
prepare,
|
|
20
|
+
dev,
|
|
21
|
+
build,
|
|
22
|
+
generate,
|
|
23
|
+
preview,
|
|
24
|
+
launch,
|
|
25
|
+
},
|
|
26
|
+
setup() {
|
|
27
|
+
console.log(brandColorLogotype);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const prepare: import("citty").CommandDef<{
|
|
2
|
+
eruditPath: {
|
|
3
|
+
type: "string";
|
|
4
|
+
description: string;
|
|
5
|
+
required: false;
|
|
6
|
+
default: string;
|
|
7
|
+
};
|
|
8
|
+
projectPath: {
|
|
9
|
+
type: "positional";
|
|
10
|
+
description: string;
|
|
11
|
+
required: false;
|
|
12
|
+
default: string;
|
|
13
|
+
};
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { consola } from 'consola';
|
|
2
|
+
import { defineCommand } from 'citty';
|
|
3
|
+
import { logCommand } from '../shared/log.js';
|
|
4
|
+
import { prepare as _prepare } from '../shared/prepare.js';
|
|
5
|
+
import { spawnNuxt } from '../shared/nuxt.js';
|
|
6
|
+
import { eruditPathArg, projectPathArg, resolveArgPaths, } from '../shared/args.js';
|
|
7
|
+
export const prepare = defineCommand({
|
|
8
|
+
meta: {
|
|
9
|
+
name: 'Prepare',
|
|
10
|
+
description: 'Creates a .erudit directory in your project and generates build files',
|
|
11
|
+
},
|
|
12
|
+
args: {
|
|
13
|
+
...projectPathArg,
|
|
14
|
+
...eruditPathArg,
|
|
15
|
+
},
|
|
16
|
+
async run({ args }) {
|
|
17
|
+
logCommand('prepare');
|
|
18
|
+
const { projectPath, eruditPath } = resolveArgPaths(args.projectPath, args.eruditPath);
|
|
19
|
+
await _prepare({
|
|
20
|
+
projectPath,
|
|
21
|
+
eruditPath,
|
|
22
|
+
});
|
|
23
|
+
consola.start('Generating Nuxt build files...');
|
|
24
|
+
await spawnNuxt('prepare', projectPath);
|
|
25
|
+
consola.success('Nuxt is prepared!');
|
|
26
|
+
},
|
|
27
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { defineCommand } from 'citty';
|
|
4
|
+
import { consola } from 'consola';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import { resolvePath } from '../shared/path.js';
|
|
7
|
+
export const preview = defineCommand({
|
|
8
|
+
meta: {
|
|
9
|
+
name: 'Preview',
|
|
10
|
+
description: 'Preview builded static Erudit site',
|
|
11
|
+
},
|
|
12
|
+
args: {
|
|
13
|
+
project: {
|
|
14
|
+
type: 'positional',
|
|
15
|
+
description: 'Project path',
|
|
16
|
+
required: false,
|
|
17
|
+
default: '.',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
async run({ args }) {
|
|
21
|
+
consola.start('Resolving project path...');
|
|
22
|
+
const projectPath = resolvePath(args.project);
|
|
23
|
+
consola.success('Resolved project path:', chalk.greenBright(projectPath));
|
|
24
|
+
const distPath = `${projectPath}/.output/public`;
|
|
25
|
+
if (!existsSync(distPath)) {
|
|
26
|
+
throw new Error(`No ".output/public" folder found! Did you run 'erudit build'?`);
|
|
27
|
+
}
|
|
28
|
+
spawn(`npx http-server ${distPath} -p 3000`, {
|
|
29
|
+
shell: true,
|
|
30
|
+
stdio: 'inherit',
|
|
31
|
+
env: {
|
|
32
|
+
...process.env,
|
|
33
|
+
ERUDIT_MODE: 'static',
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
});
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { run } from './run.js';
|
package/dist/run.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function run(): void;
|
package/dist/run.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare const eruditPathArg: {
|
|
2
|
+
eruditPath: {
|
|
3
|
+
type: "string";
|
|
4
|
+
description: string;
|
|
5
|
+
required: false;
|
|
6
|
+
default: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare const projectPathArg: {
|
|
10
|
+
projectPath: {
|
|
11
|
+
type: "positional";
|
|
12
|
+
description: string;
|
|
13
|
+
required: false;
|
|
14
|
+
default: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export declare const contentTargetsArg: {
|
|
18
|
+
target: {
|
|
19
|
+
type: "string";
|
|
20
|
+
description: string;
|
|
21
|
+
required: false;
|
|
22
|
+
default: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare const nitroPresetArg: {
|
|
26
|
+
preset: {
|
|
27
|
+
type: "string";
|
|
28
|
+
required: false;
|
|
29
|
+
description: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export declare function resolveArgPaths(projectPath: string, eruditPath: string): {
|
|
33
|
+
projectPath: string;
|
|
34
|
+
eruditPath: string;
|
|
35
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { consola } from 'consola';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { resolvePath } from './path.js';
|
|
4
|
+
export const eruditPathArg = {
|
|
5
|
+
eruditPath: {
|
|
6
|
+
type: 'string',
|
|
7
|
+
description: 'Custom Erudit Nuxt Layer location',
|
|
8
|
+
required: false,
|
|
9
|
+
default: 'erudit', // Let `nuxi` find erudit in project dependencies
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
export const projectPathArg = {
|
|
13
|
+
projectPath: {
|
|
14
|
+
type: 'positional',
|
|
15
|
+
description: 'Erudit project location',
|
|
16
|
+
required: false,
|
|
17
|
+
default: '.',
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
export const contentTargetsArg = {
|
|
21
|
+
target: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
description: 'Content targets to process',
|
|
24
|
+
required: false,
|
|
25
|
+
default: '',
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
export const nitroPresetArg = {
|
|
29
|
+
preset: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
required: false,
|
|
32
|
+
description: '(Nuxt Build Flag) Nitro preset to use for building',
|
|
33
|
+
},
|
|
34
|
+
};
|
|
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 logCommand(command: string): void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
export async function spawnNuxt(command, projectPath, restParams) {
|
|
3
|
+
return new Promise((resolve) => {
|
|
4
|
+
const onClose = (exitCode) => {
|
|
5
|
+
if (exitCode === 0) {
|
|
6
|
+
console.log('Nuxt process exited successfully!');
|
|
7
|
+
return resolve();
|
|
8
|
+
}
|
|
9
|
+
if (exitCode === 1) {
|
|
10
|
+
console.error('Nuxt process exited with an error!');
|
|
11
|
+
return resolve();
|
|
12
|
+
}
|
|
13
|
+
if (exitCode === 1337) {
|
|
14
|
+
console.warn('Nuxt full restart is requested!');
|
|
15
|
+
_spawnNuxt();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (command === 'dev') {
|
|
19
|
+
console.error(`Nuxt process exited with an error code ${exitCode} in development mode!\nRespawning...`);
|
|
20
|
+
_spawnNuxt();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const _spawnNuxt = () => {
|
|
25
|
+
const mode = (() => {
|
|
26
|
+
switch (command) {
|
|
27
|
+
case 'dev':
|
|
28
|
+
case 'prepare':
|
|
29
|
+
return 'dev';
|
|
30
|
+
case 'build':
|
|
31
|
+
return 'write';
|
|
32
|
+
case 'generate':
|
|
33
|
+
return 'static';
|
|
34
|
+
}
|
|
35
|
+
})();
|
|
36
|
+
const nuxtProcess = spawn(`nuxt ${command} ${projectPath}/.erudit/nuxt ${restParams || ''}`, {
|
|
37
|
+
shell: true,
|
|
38
|
+
stdio: 'inherit',
|
|
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
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function resolvePath(path: string): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { existsSync, lstatSync } from 'node:fs';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { resolve, isAbsolute } from 'node:path';
|
|
4
|
+
export function resolvePath(path) {
|
|
5
|
+
path = path.replace(/\\/g, '/');
|
|
6
|
+
path = path.endsWith('/') ? path.slice(0, -1) : path;
|
|
7
|
+
if (!isAbsolute(path)) {
|
|
8
|
+
path = resolve(process.cwd(), path).replace(/\\/g, '/');
|
|
9
|
+
}
|
|
10
|
+
if (existsSync(path) && !lstatSync(path).isDirectory())
|
|
11
|
+
throw new Error(`Path "${chalk.yellowBright(path)}" is not a directory!`);
|
|
12
|
+
return path;
|
|
13
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { consola } from 'consola';
|
|
3
|
+
export async function prepare({ projectPath, eruditPath, contentTargets, }) {
|
|
4
|
+
const eruditBuildDir = `${projectPath}/.erudit`;
|
|
5
|
+
const distDir = `${projectPath}/.output`;
|
|
6
|
+
consola.start('Cleaning up...');
|
|
7
|
+
if (existsSync(distDir))
|
|
8
|
+
rmSync(distDir, { recursive: true });
|
|
9
|
+
if (existsSync(eruditBuildDir))
|
|
10
|
+
rmSync(eruditBuildDir, { recursive: true });
|
|
11
|
+
consola.success('Cleaned up!');
|
|
12
|
+
consola.start('Generating Erudit build files...');
|
|
13
|
+
mkdirSync(eruditBuildDir, { recursive: true });
|
|
14
|
+
mkdirSync(eruditBuildDir + '/nuxt', { recursive: true });
|
|
15
|
+
writeFileSync(`${eruditBuildDir}/nuxt/nuxt.config.ts`, `
|
|
16
|
+
export default {
|
|
17
|
+
compatibilityDate: '2025-07-20',
|
|
18
|
+
extends: ['${eruditPath}'],
|
|
19
|
+
}
|
|
20
|
+
`);
|
|
21
|
+
['app', 'server', 'shared', 'node'].forEach((name) => {
|
|
22
|
+
writeFileSync(`${eruditBuildDir}/tsconfig.nuxt.${name}.json`, JSON.stringify({ extends: [`./nuxt/.nuxt/tsconfig.${name}.json`] }, null, 4));
|
|
23
|
+
});
|
|
24
|
+
mkdirSync(`${eruditBuildDir}/types`, { recursive: true });
|
|
25
|
+
writeFileSync(`${eruditBuildDir}/tsconfig.erudit.json`, JSON.stringify({
|
|
26
|
+
compilerOptions: {
|
|
27
|
+
paths: {
|
|
28
|
+
'#project/*': [`${projectPath}/*`],
|
|
29
|
+
'#content/*': [`${projectPath}/content/*`],
|
|
30
|
+
},
|
|
31
|
+
verbatimModuleSyntax: true,
|
|
32
|
+
forceConsistentCasingInFileNames: true,
|
|
33
|
+
strict: true,
|
|
34
|
+
noEmit: true,
|
|
35
|
+
skipLibCheck: true,
|
|
36
|
+
target: 'ESNext',
|
|
37
|
+
module: 'ESNext',
|
|
38
|
+
moduleResolution: 'Bundler',
|
|
39
|
+
allowJs: true,
|
|
40
|
+
resolveJsonModule: true,
|
|
41
|
+
allowSyntheticDefaultImports: true,
|
|
42
|
+
jsx: 'react-jsx',
|
|
43
|
+
jsxImportSource: '@jsprose/core',
|
|
44
|
+
types: ['@jsprose/core/types', '@erudit-js/prose/types'],
|
|
45
|
+
lib: ['ESNext'],
|
|
46
|
+
},
|
|
47
|
+
include: [`${projectPath}/**/*`, `${eruditBuildDir}/**/*`],
|
|
48
|
+
exclude: [
|
|
49
|
+
`${eruditBuildDir}/nuxt/**/*`,
|
|
50
|
+
`${projectPath}/**/docs.ts`,
|
|
51
|
+
],
|
|
52
|
+
}, null, 4));
|
|
53
|
+
if (!existsSync(`${projectPath}/tsconfig.json`)) {
|
|
54
|
+
writeFileSync(`${projectPath}/tsconfig.json`, JSON.stringify({
|
|
55
|
+
files: [],
|
|
56
|
+
references: [
|
|
57
|
+
{
|
|
58
|
+
path: `./.erudit/tsconfig.erudit.json`,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
path: `./.erudit/tsconfig.nuxt.app.json`,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
path: `./.erudit/tsconfig.nuxt.server.json`,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
path: `./.erudit/tsconfig.nuxt.shared.json`,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
path: `./.erudit/tsconfig.nuxt.node.json`,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
}, null, 4));
|
|
74
|
+
}
|
|
75
|
+
await prepareContentTargets(eruditBuildDir, contentTargets);
|
|
76
|
+
writeFileSync(`${eruditBuildDir}/__AUTOGENERATED__`, `This directory is autogenerated by Erudit CLI.\nAll changes will be lost on next launch!`);
|
|
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}"!`);
|
|
92
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@erudit-js/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-dev.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "📟 Command Line Interface for Erudit",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,31 +9,32 @@
|
|
|
9
9
|
"url": "git+https://github.com/erudit-js/erudit.git",
|
|
10
10
|
"directory": "packages/cli"
|
|
11
11
|
},
|
|
12
|
+
"main": "./dist/index.js",
|
|
12
13
|
"types": "./dist/index.d.ts",
|
|
13
14
|
"exports": {
|
|
14
|
-
".":
|
|
15
|
-
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts"
|
|
18
|
+
},
|
|
19
|
+
"./cli": "./bin/erudit-cli.js"
|
|
16
20
|
},
|
|
17
21
|
"bin": {
|
|
18
|
-
"erudit-cli": "bin/erudit-cli.
|
|
19
|
-
"erudit": "bin/erudit-cli.
|
|
22
|
+
"erudit-cli": "bin/erudit-cli.js",
|
|
23
|
+
"erudit": "bin/erudit-cli.js"
|
|
20
24
|
},
|
|
21
25
|
"scripts": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"prepack": "bun
|
|
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"
|
|
25
29
|
},
|
|
26
30
|
"files": [
|
|
27
31
|
"bin",
|
|
28
32
|
"dist"
|
|
29
33
|
],
|
|
30
34
|
"dependencies": {
|
|
31
|
-
"@erudit-js/
|
|
32
|
-
"chalk": "^5.
|
|
35
|
+
"@erudit-js/core": "4.0.0-dev.1",
|
|
36
|
+
"chalk": "^5.6.2",
|
|
33
37
|
"citty": "^0.1.6",
|
|
34
|
-
"consola": "^3.4.
|
|
35
|
-
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"unbuild": "^3.3.1"
|
|
38
|
+
"consola": "^3.4.2"
|
|
38
39
|
}
|
|
39
40
|
}
|
package/bin/erudit-cli.mjs
DELETED
package/dist/index.d.mts
DELETED
package/dist/index.mjs
DELETED
|
@@ -1,411 +0,0 @@
|
|
|
1
|
-
import { defineCommand, runMain } from 'citty';
|
|
2
|
-
import { brandColorLogotype } from '@erudit-js/cog/utils/brandNode';
|
|
3
|
-
import { consola } from 'consola';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
import { existsSync, lstatSync, readdirSync, rmSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
6
|
-
import { resolvePaths } from '@erudit-js/cog/kit';
|
|
7
|
-
import * as fs from 'node:fs/promises';
|
|
8
|
-
import * as path from 'node:path';
|
|
9
|
-
import { spawn } from 'node:child_process';
|
|
10
|
-
|
|
11
|
-
const version = "3.0.0-dev.9";
|
|
12
|
-
|
|
13
|
-
function resolvePath(path) {
|
|
14
|
-
path = resolvePaths(path);
|
|
15
|
-
path = path.endsWith("/") ? path.slice(0, -1) : path;
|
|
16
|
-
if (existsSync(path) && !lstatSync(path).isDirectory())
|
|
17
|
-
throw new Error(
|
|
18
|
-
`Path "${chalk.yellowBright(path)}" is not a directory!`
|
|
19
|
-
);
|
|
20
|
-
return path;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const init = defineCommand({
|
|
24
|
-
meta: {
|
|
25
|
-
name: "Init",
|
|
26
|
-
description: "Creates a new Erudit project at specified path"
|
|
27
|
-
},
|
|
28
|
-
args: {
|
|
29
|
-
path: {
|
|
30
|
-
type: "positional",
|
|
31
|
-
description: "Path for the new Erudit project",
|
|
32
|
-
required: true,
|
|
33
|
-
valueHint: chalk.gray(
|
|
34
|
-
`"${chalk.greenBright(".")}" OR "${chalk.greenBright("path/to/project")}"`
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
async run({ args }) {
|
|
39
|
-
consola.start("Resolving project path...");
|
|
40
|
-
const projectPath = resolvePath(args.path);
|
|
41
|
-
if (projectPath === void 0) return;
|
|
42
|
-
if (existsSync(projectPath) && readdirSync(projectPath).length > 0)
|
|
43
|
-
throw new Error(
|
|
44
|
-
`Directory "${chalk.yellowBright(projectPath)}" is not empty!`
|
|
45
|
-
);
|
|
46
|
-
consola.success(
|
|
47
|
-
"Resolved project path:",
|
|
48
|
-
chalk.greenBright(projectPath)
|
|
49
|
-
);
|
|
50
|
-
consola.start("Creating project directory...");
|
|
51
|
-
try {
|
|
52
|
-
try {
|
|
53
|
-
rmSync(projectPath, { recursive: true });
|
|
54
|
-
} catch (error) {
|
|
55
|
-
if (error?.code !== "ENOENT") {
|
|
56
|
-
throw error;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
mkdirSync(projectPath, { recursive: true });
|
|
60
|
-
} catch (error) {
|
|
61
|
-
throw new Error(
|
|
62
|
-
`Failed to prepare project directory "${chalk.yellowBright(projectPath)}"!
|
|
63
|
-
|
|
64
|
-
${error}`
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
consola.success("Project directory created!");
|
|
68
|
-
consola.start("Creating project files...");
|
|
69
|
-
consola.success("Project files created!");
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
function logCommand(command) {
|
|
74
|
-
consola.info(`Running command: ${chalk.cyanBright(command)}`);
|
|
75
|
-
console.log();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async function alias2Relative(baseDir, toReplaceDir) {
|
|
79
|
-
baseDir = resolvePaths(baseDir);
|
|
80
|
-
toReplaceDir = resolvePaths(toReplaceDir);
|
|
81
|
-
if (!existsSync(baseDir)) {
|
|
82
|
-
console.log(`Base directory ${baseDir} does not exist. Skipping...`);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if (!existsSync(toReplaceDir)) {
|
|
86
|
-
console.log(
|
|
87
|
-
`Target directory ${toReplaceDir} does not exist. Skipping...`
|
|
88
|
-
);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
const ALIASES_RESOLVED_FILE = path.join(toReplaceDir, "ALIASES_RESOLVED");
|
|
92
|
-
if (existsSync(ALIASES_RESOLVED_FILE)) {
|
|
93
|
-
console.log(`Aliases already resolved in ${toReplaceDir}. Skipping...`);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const replaceMap = {
|
|
97
|
-
"@erudit": "./",
|
|
98
|
-
"@module": "./module",
|
|
99
|
-
"@server": "./server/plugin",
|
|
100
|
-
"@shared": "./shared",
|
|
101
|
-
"@app": "./app"
|
|
102
|
-
};
|
|
103
|
-
const allFiles = await findAllFiles(toReplaceDir);
|
|
104
|
-
for (const filePath of allFiles) {
|
|
105
|
-
await processFile(filePath, baseDir, replaceMap);
|
|
106
|
-
}
|
|
107
|
-
await fs.writeFile(ALIASES_RESOLVED_FILE, (/* @__PURE__ */ new Date()).toISOString());
|
|
108
|
-
console.log(`All aliases in ${toReplaceDir} resolved successfully!`);
|
|
109
|
-
}
|
|
110
|
-
async function findAllFiles(dir) {
|
|
111
|
-
const results = [];
|
|
112
|
-
try {
|
|
113
|
-
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
114
|
-
for (const entry of entries) {
|
|
115
|
-
const fullPath = path.join(dir, entry.name);
|
|
116
|
-
if (entry.isDirectory()) {
|
|
117
|
-
if (![".git", "dist", "build"].includes(entry.name)) {
|
|
118
|
-
results.push(...await findAllFiles(fullPath));
|
|
119
|
-
}
|
|
120
|
-
} else if (entry.isFile() && /\.(js|ts|vue)$/.test(entry.name)) {
|
|
121
|
-
results.push(fullPath);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
} catch (error) {
|
|
125
|
-
console.error(`Error reading directory ${dir}:`, error);
|
|
126
|
-
}
|
|
127
|
-
return results;
|
|
128
|
-
}
|
|
129
|
-
async function processFile(filePath, rootDir, replaceMap) {
|
|
130
|
-
try {
|
|
131
|
-
let content = await fs.readFile(filePath, "utf8");
|
|
132
|
-
let modified = false;
|
|
133
|
-
for (const [alias, targetBasePath] of Object.entries(replaceMap)) {
|
|
134
|
-
const staticAliasPattern = new RegExp(
|
|
135
|
-
`(import|from)\\s+(['"])${alias}/([^'"]+)(['"])`,
|
|
136
|
-
"g"
|
|
137
|
-
);
|
|
138
|
-
const dynamicAliasPattern = new RegExp(
|
|
139
|
-
`(import\\s*\\()\\s*(['"])${alias}/([^'"]+)(['"])\\s*\\)`,
|
|
140
|
-
"g"
|
|
141
|
-
);
|
|
142
|
-
const calculateRelativePath = (importPath) => {
|
|
143
|
-
const currentFileDir = path.dirname(filePath);
|
|
144
|
-
const targetAbsoluteDir = path.join(
|
|
145
|
-
rootDir,
|
|
146
|
-
targetBasePath.replace(/^\.\//, "")
|
|
147
|
-
);
|
|
148
|
-
const targetAbsolutePath = path.join(
|
|
149
|
-
targetAbsoluteDir,
|
|
150
|
-
importPath
|
|
151
|
-
);
|
|
152
|
-
let relativePath = path.relative(
|
|
153
|
-
currentFileDir,
|
|
154
|
-
targetAbsolutePath
|
|
155
|
-
);
|
|
156
|
-
if (!relativePath.startsWith(".")) {
|
|
157
|
-
relativePath = "./" + relativePath;
|
|
158
|
-
}
|
|
159
|
-
return relativePath.replace(/\\/g, "/");
|
|
160
|
-
};
|
|
161
|
-
content = content.replace(
|
|
162
|
-
staticAliasPattern,
|
|
163
|
-
(match, statement, openQuote, importPath, closeQuote) => {
|
|
164
|
-
const relativePath = calculateRelativePath(importPath);
|
|
165
|
-
modified = true;
|
|
166
|
-
return `${statement} ${openQuote}${relativePath}${closeQuote}`;
|
|
167
|
-
}
|
|
168
|
-
);
|
|
169
|
-
content = content.replace(
|
|
170
|
-
dynamicAliasPattern,
|
|
171
|
-
(match, importStatement, openQuote, importPath, closeQuote) => {
|
|
172
|
-
const relativePath = calculateRelativePath(importPath);
|
|
173
|
-
modified = true;
|
|
174
|
-
return `${importStatement}${openQuote}${relativePath}${closeQuote})`;
|
|
175
|
-
}
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
if (modified) {
|
|
179
|
-
await fs.writeFile(filePath, content, "utf8");
|
|
180
|
-
console.log(`Updated aliases in: ${filePath}`);
|
|
181
|
-
}
|
|
182
|
-
} catch (error) {
|
|
183
|
-
console.error(`Error processing file ${filePath}:`, error);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
async function prepare$1(projectPath, eruditPath) {
|
|
188
|
-
const eruditBuildDir = `${projectPath}/.erudit`;
|
|
189
|
-
const distDir = `${projectPath}/dist`;
|
|
190
|
-
const nodeModules = `${projectPath}/node_modules`;
|
|
191
|
-
const nodeModulesErudit = `${nodeModules}/erudit`;
|
|
192
|
-
await alias2Relative(nodeModulesErudit, nodeModulesErudit);
|
|
193
|
-
await alias2Relative(
|
|
194
|
-
nodeModulesErudit,
|
|
195
|
-
nodeModules + "/@erudit-js/bitran-elements"
|
|
196
|
-
);
|
|
197
|
-
consola.start("Cleaning up...");
|
|
198
|
-
if (existsSync(distDir)) rmSync(distDir, { recursive: true });
|
|
199
|
-
if (existsSync(eruditBuildDir)) rmSync(eruditBuildDir, { recursive: true });
|
|
200
|
-
consola.success("Cleaned up!");
|
|
201
|
-
consola.start("Generating Erudit build files...");
|
|
202
|
-
mkdirSync(eruditBuildDir, { recursive: true });
|
|
203
|
-
mkdirSync(eruditBuildDir + "/nuxt", { recursive: true });
|
|
204
|
-
writeFileSync(
|
|
205
|
-
`${eruditBuildDir}/nuxt/nuxt.config.ts`,
|
|
206
|
-
`
|
|
207
|
-
export default {
|
|
208
|
-
compatibilityDate: '2025-01-01',
|
|
209
|
-
extends: ['${eruditPath}'],
|
|
210
|
-
future: {
|
|
211
|
-
compatibilityVersion: 4,
|
|
212
|
-
},
|
|
213
|
-
}
|
|
214
|
-
`
|
|
215
|
-
);
|
|
216
|
-
writeFileSync(
|
|
217
|
-
`${eruditBuildDir}/tsconfig.json`,
|
|
218
|
-
JSON.stringify(
|
|
219
|
-
{
|
|
220
|
-
extends: "./nuxt/.nuxt/tsconfig.json"
|
|
221
|
-
},
|
|
222
|
-
null,
|
|
223
|
-
4
|
|
224
|
-
)
|
|
225
|
-
);
|
|
226
|
-
consola.success("Erudit build files ready!");
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
async function spawnNuxt(command, projectPath) {
|
|
230
|
-
return new Promise((resolve) => {
|
|
231
|
-
const onClose = (exitCode) => {
|
|
232
|
-
if (exitCode === 1337) _spawnNuxt();
|
|
233
|
-
else if (exitCode !== 0)
|
|
234
|
-
throw new Error(`Nuxt exited with code ${exitCode}!`);
|
|
235
|
-
else resolve();
|
|
236
|
-
};
|
|
237
|
-
const _spawnNuxt = () => {
|
|
238
|
-
const nuxtProcess = spawn(
|
|
239
|
-
`nuxt ${command} ${projectPath}/.erudit/nuxt`,
|
|
240
|
-
{
|
|
241
|
-
shell: true,
|
|
242
|
-
stdio: "inherit",
|
|
243
|
-
env: {
|
|
244
|
-
...process.env,
|
|
245
|
-
ERUDIT_PROJECT_DIR: projectPath
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
);
|
|
249
|
-
nuxtProcess.on("close", onClose);
|
|
250
|
-
};
|
|
251
|
-
_spawnNuxt();
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const eruditPathArg = {
|
|
256
|
-
eruditPath: {
|
|
257
|
-
type: "string",
|
|
258
|
-
description: "Custom Erudit Nuxt Layer location",
|
|
259
|
-
required: false,
|
|
260
|
-
default: "erudit"
|
|
261
|
-
// Let `nuxi` find erudit in project dependencies
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
const projectPathArg = {
|
|
265
|
-
projectPath: {
|
|
266
|
-
type: "positional",
|
|
267
|
-
description: "Erudit project location",
|
|
268
|
-
required: false,
|
|
269
|
-
default: "."
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
function resolveArgPaths(projectPath, eruditPath) {
|
|
273
|
-
consola.start("Resolving project path...");
|
|
274
|
-
projectPath = resolvePath(projectPath);
|
|
275
|
-
consola.success("Resolved project path:", chalk.greenBright(projectPath));
|
|
276
|
-
consola.start("Resolving Erudit Nuxt Layer path...");
|
|
277
|
-
if (eruditPath === "erudit") {
|
|
278
|
-
consola.success(`'nuxi' will find Erudit in your dependencies!`);
|
|
279
|
-
} else {
|
|
280
|
-
eruditPath = resolvePath(eruditPath);
|
|
281
|
-
consola.warn(
|
|
282
|
-
"Custom Erudit Nuxt Layer path will be used: " + chalk.yellowBright(eruditPath)
|
|
283
|
-
);
|
|
284
|
-
}
|
|
285
|
-
return {
|
|
286
|
-
projectPath,
|
|
287
|
-
eruditPath
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const prepare = defineCommand({
|
|
292
|
-
meta: {
|
|
293
|
-
name: "Prepare",
|
|
294
|
-
description: "Creates a .erudit directory in your project and generates build files"
|
|
295
|
-
},
|
|
296
|
-
args: {
|
|
297
|
-
...projectPathArg,
|
|
298
|
-
...eruditPathArg
|
|
299
|
-
},
|
|
300
|
-
async run({ args }) {
|
|
301
|
-
logCommand("prepare");
|
|
302
|
-
const { projectPath, eruditPath } = resolveArgPaths(
|
|
303
|
-
args.projectPath,
|
|
304
|
-
args.eruditPath
|
|
305
|
-
);
|
|
306
|
-
await prepare$1(projectPath, eruditPath);
|
|
307
|
-
consola.start("Generating Nuxt build files...");
|
|
308
|
-
await spawnNuxt("prepare", projectPath);
|
|
309
|
-
consola.success("Nuxt is prepared!");
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
const dev = defineCommand({
|
|
314
|
-
meta: {
|
|
315
|
-
name: "Dev",
|
|
316
|
-
description: "Runs Erudit project in development mode"
|
|
317
|
-
},
|
|
318
|
-
args: {
|
|
319
|
-
...projectPathArg,
|
|
320
|
-
...eruditPathArg
|
|
321
|
-
},
|
|
322
|
-
async run({ args }) {
|
|
323
|
-
logCommand("dev");
|
|
324
|
-
const { projectPath, eruditPath } = resolveArgPaths(
|
|
325
|
-
args.projectPath,
|
|
326
|
-
args.eruditPath
|
|
327
|
-
);
|
|
328
|
-
await prepare$1(projectPath, eruditPath);
|
|
329
|
-
consola.start("Starting Nuxt dev...");
|
|
330
|
-
await spawnNuxt("dev", projectPath);
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
const build = defineCommand({
|
|
335
|
-
meta: {
|
|
336
|
-
name: "Build",
|
|
337
|
-
description: "Generates fully static Erudit site"
|
|
338
|
-
},
|
|
339
|
-
args: {
|
|
340
|
-
...projectPathArg,
|
|
341
|
-
...eruditPathArg
|
|
342
|
-
},
|
|
343
|
-
async run({ args }) {
|
|
344
|
-
logCommand("build");
|
|
345
|
-
const { projectPath, eruditPath } = resolveArgPaths(
|
|
346
|
-
args.projectPath,
|
|
347
|
-
args.eruditPath
|
|
348
|
-
);
|
|
349
|
-
await prepare$1(projectPath, eruditPath);
|
|
350
|
-
consola.start("Starting Nuxt build...");
|
|
351
|
-
await spawnNuxt("generate", projectPath);
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
const preview = defineCommand({
|
|
356
|
-
meta: {
|
|
357
|
-
name: "Preview",
|
|
358
|
-
description: "Preview created static Erudit site"
|
|
359
|
-
},
|
|
360
|
-
args: {
|
|
361
|
-
project: {
|
|
362
|
-
type: "positional",
|
|
363
|
-
description: "Project path",
|
|
364
|
-
required: false,
|
|
365
|
-
default: "."
|
|
366
|
-
}
|
|
367
|
-
},
|
|
368
|
-
async run({ args }) {
|
|
369
|
-
consola.start("Resolving project path...");
|
|
370
|
-
const projectPath = resolvePath(args.project);
|
|
371
|
-
consola.success(
|
|
372
|
-
"Resolved project path:",
|
|
373
|
-
chalk.greenBright(projectPath)
|
|
374
|
-
);
|
|
375
|
-
const distPath = `${projectPath}/dist`;
|
|
376
|
-
if (!existsSync(distPath))
|
|
377
|
-
throw new Error(
|
|
378
|
-
`No 'dist' folder found! Did you run 'erudit build'?`
|
|
379
|
-
);
|
|
380
|
-
spawn("npx http-server . -p 3000", {
|
|
381
|
-
shell: true,
|
|
382
|
-
stdio: "inherit",
|
|
383
|
-
env: process.env,
|
|
384
|
-
cwd: distPath
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
const main = defineCommand({
|
|
390
|
-
meta: {
|
|
391
|
-
name: "Erudit CLI",
|
|
392
|
-
description: "Command Line Interface for Erudit!",
|
|
393
|
-
version
|
|
394
|
-
},
|
|
395
|
-
subCommands: {
|
|
396
|
-
init,
|
|
397
|
-
prepare,
|
|
398
|
-
dev,
|
|
399
|
-
build,
|
|
400
|
-
preview
|
|
401
|
-
},
|
|
402
|
-
setup() {
|
|
403
|
-
console.log(brandColorLogotype);
|
|
404
|
-
}
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
function run() {
|
|
408
|
-
runMain(main);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
export { run };
|