@erudit-js/cli 3.0.0-dev.22 → 3.0.0-dev.25

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 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
- - `init`
10
- - `dev`
11
- - `build`
12
- - `preview`
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,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { run } from '../dist/index.js';
4
+
5
+ run();
@@ -0,0 +1,31 @@
1
+ export declare const build: import("citty").CommandDef<{
2
+ prerender: {
3
+ required: false;
4
+ type: "boolean";
5
+ default: false;
6
+ description: string;
7
+ };
8
+ preset: {
9
+ type: "string";
10
+ required: false;
11
+ description: string;
12
+ };
13
+ target: {
14
+ type: "string";
15
+ description: string;
16
+ required: false;
17
+ default: string;
18
+ };
19
+ eruditPath: {
20
+ type: "string";
21
+ description: string;
22
+ required: false;
23
+ default: string;
24
+ };
25
+ projectPath: {
26
+ type: "positional";
27
+ description: string;
28
+ required: false;
29
+ default: string;
30
+ };
31
+ }>;
@@ -0,0 +1,37 @@
1
+ import consola from 'consola';
2
+ import { defineCommand } from 'citty';
3
+ import { contentTargetsArg, eruditPathArg, nitroPresetArg, projectPathArg, resolveArgPaths, } from '../shared/args.js';
4
+ import { logCommand } from '../shared/log.js';
5
+ import { spawnNuxt } from '../shared/nuxt.js';
6
+ import { prepare } from '../shared/prepare.js';
7
+ export const build = defineCommand({
8
+ meta: {
9
+ name: 'Build',
10
+ description: 'Builds Erudit project for fast and convenient content writing',
11
+ },
12
+ args: {
13
+ ...projectPathArg,
14
+ ...eruditPathArg,
15
+ ...contentTargetsArg,
16
+ ...nitroPresetArg,
17
+ prerender: {
18
+ required: false,
19
+ type: 'boolean',
20
+ default: false,
21
+ description: '(Nuxt Build Flag) Prerender routes',
22
+ },
23
+ },
24
+ async run({ args }) {
25
+ logCommand('build');
26
+ const { projectPath, eruditPath } = resolveArgPaths(args.projectPath, args.eruditPath);
27
+ await prepare({
28
+ projectPath,
29
+ eruditPath,
30
+ contentTargets: args.target,
31
+ });
32
+ const restParams = (args.prerender ? '--prerender' : '') +
33
+ (args.preset ? ` --preset ${args.preset}` : '');
34
+ consola.start('Starting Nuxt build...');
35
+ await spawnNuxt('build', projectPath, restParams);
36
+ },
37
+ });
@@ -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,8 @@
1
+ export declare const init: import("citty").CommandDef<{
2
+ path: {
3
+ type: "positional";
4
+ description: string;
5
+ required: true;
6
+ valueHint: string;
7
+ };
8
+ }>;
@@ -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,8 @@
1
+ export declare const launch: import("citty").CommandDef<{
2
+ project: {
3
+ type: "positional";
4
+ description: string;
5
+ required: false;
6
+ default: string;
7
+ };
8
+ }>;
@@ -0,0 +1,34 @@
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: process.env,
31
+ cwd: distPath,
32
+ });
33
+ },
34
+ });
@@ -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: '3.0.0-dev.25',
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,8 @@
1
+ export declare const preview: import("citty").CommandDef<{
2
+ project: {
3
+ type: "positional";
4
+ description: string;
5
+ required: false;
6
+ default: string;
7
+ };
8
+ }>;
@@ -0,0 +1,34 @@
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: process.env,
32
+ });
33
+ },
34
+ });
package/dist/index.d.ts CHANGED
@@ -1,3 +1 @@
1
- declare function run(): void;
2
-
3
- export { run };
1
+ export { run } from './run.js';
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,5 @@
1
+ import { runMain } from 'citty';
2
+ import { main } from './commands/main.js';
3
+ export function run() {
4
+ runMain(main);
5
+ }
@@ -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,6 @@
1
+ import chalk from 'chalk';
2
+ import { consola } from 'consola';
3
+ export function logCommand(command) {
4
+ consola.info(`Running command: ${chalk.cyanBright(command)}`);
5
+ console.log();
6
+ }
@@ -0,0 +1,3 @@
1
+ type NuxtCommand = 'dev' | 'build' | 'generate' | 'prepare';
2
+ export declare function spawnNuxt(command: NuxtCommand, projectPath: string, restParams?: string): Promise<void>;
3
+ export {};
@@ -0,0 +1,38 @@
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 nuxtProcess = spawn(`nuxt ${command} ${projectPath}/.erudit/nuxt ${restParams || ''}`, {
26
+ shell: true,
27
+ stdio: 'inherit',
28
+ env: {
29
+ ...process.env,
30
+ ERUDIT_PROJECT_DIR: projectPath,
31
+ ERUDIT_MODE: command,
32
+ },
33
+ });
34
+ nuxtProcess.on('close', onClose);
35
+ };
36
+ _spawnNuxt();
37
+ });
38
+ }
@@ -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,7 @@
1
+ interface PrepareData {
2
+ projectPath: string;
3
+ eruditPath: string;
4
+ contentTargets?: string | string[];
5
+ }
6
+ export declare function prepare({ projectPath, eruditPath, contentTargets, }: PrepareData): Promise<void>;
7
+ export {};
@@ -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: `${eruditBuildDir}/tsconfig.erudit.json`,
59
+ },
60
+ {
61
+ path: `${eruditBuildDir}/tsconfig.nuxt.app.json`,
62
+ },
63
+ {
64
+ path: `${eruditBuildDir}/tsconfig.nuxt.server.json`,
65
+ },
66
+ {
67
+ path: `${eruditBuildDir}/tsconfig.nuxt.shared.json`,
68
+ },
69
+ {
70
+ path: `${eruditBuildDir}/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.0.0-dev.22",
3
+ "version": "3.0.0-dev.25",
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
- ".": "./dist/index.mjs",
15
- "./cli": "./bin/erudit-cli.mjs"
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.mjs",
19
- "erudit": "bin/erudit-cli.mjs"
22
+ "erudit-cli": "bin/erudit-cli.js",
23
+ "erudit": "bin/erudit-cli.js"
20
24
  },
21
25
  "scripts": {
22
- "dev": "bun unbuild --stub",
23
- "build": "bun run prepack",
24
- "prepack": "bun unbuild"
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/cog": "3.0.0-dev.22",
32
- "chalk": "^5.4.1",
35
+ "@erudit-js/core": "workspace:3.0.0-dev.25",
36
+ "chalk": "^5.6.2",
33
37
  "citty": "^0.1.6",
34
- "consola": "^3.4.0"
35
- },
36
- "devDependencies": {
37
- "unbuild": "^3.3.1"
38
+ "consola": "^3.4.2"
38
39
  }
39
40
  }
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { run } from '../dist/index.mjs';
4
-
5
- run();
package/dist/index.d.mts DELETED
@@ -1,3 +0,0 @@
1
- declare function run(): void;
2
-
3
- export { run };
package/dist/index.mjs DELETED
@@ -1,503 +0,0 @@
1
- import { defineCommand, runMain } from 'citty';
2
- import { brandColorLogotype } from '@erudit-js/cog/utils/brandNode';
3
- import consola$1, { 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.22";
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 (baseDir.search("/node_modules/") === -1) {
82
- console.log(
83
- `Base directory ${baseDir} is not in node_modules. Skipping...`
84
- );
85
- return;
86
- }
87
- if (!existsSync(baseDir)) {
88
- console.log(`Base directory ${baseDir} does not exist. Skipping...`);
89
- return;
90
- }
91
- if (!existsSync(toReplaceDir)) {
92
- console.log(
93
- `Target directory ${toReplaceDir} does not exist. Skipping...`
94
- );
95
- return;
96
- }
97
- const ALIASES_RESOLVED_FILE = path.join(toReplaceDir, "ALIASES_RESOLVED");
98
- if (existsSync(ALIASES_RESOLVED_FILE)) {
99
- console.log(`Aliases already resolved in ${toReplaceDir}. Skipping...`);
100
- return;
101
- }
102
- const replaceMap = {
103
- "@erudit": "./",
104
- "@module": "./module",
105
- "@server": "./server/plugin",
106
- "@shared": "./shared",
107
- "@app": "./app"
108
- };
109
- const allFiles = await findAllFiles(toReplaceDir);
110
- for (const filePath of allFiles) {
111
- await processFile(filePath, baseDir, replaceMap);
112
- }
113
- await fs.writeFile(ALIASES_RESOLVED_FILE, (/* @__PURE__ */ new Date()).toISOString());
114
- console.log(`All aliases in ${toReplaceDir} resolved successfully!`);
115
- }
116
- async function findAllFiles(dir) {
117
- const results = [];
118
- try {
119
- const entries = await fs.readdir(dir, { withFileTypes: true });
120
- for (const entry of entries) {
121
- const fullPath = path.join(dir, entry.name);
122
- const ignore = [];
123
- if (entry.isDirectory()) {
124
- if (!ignore.includes(entry.name)) {
125
- results.push(...await findAllFiles(fullPath));
126
- }
127
- } else if (entry.isFile() && /\.(js|ts|vue)$/.test(entry.name)) {
128
- results.push(fullPath);
129
- }
130
- }
131
- } catch (error) {
132
- console.error(`Error reading directory ${dir}:`, error);
133
- }
134
- return results;
135
- }
136
- async function processFile(filePath, rootDir, replaceMap) {
137
- try {
138
- let content = await fs.readFile(filePath, "utf8");
139
- let modified = false;
140
- for (const [alias, targetBasePath] of Object.entries(replaceMap)) {
141
- const staticAliasPattern = new RegExp(
142
- `(import|from)\\s+(['"])${alias}/([^'"]+)(['"])`,
143
- "g"
144
- );
145
- const dynamicAliasPattern = new RegExp(
146
- `(import\\s*\\()\\s*(['"])${alias}/([^'"]+)(['"])\\s*\\)`,
147
- "g"
148
- );
149
- const calculateRelativePath = (importPath) => {
150
- const currentFileDir = path.dirname(filePath);
151
- const targetAbsoluteDir = path.join(
152
- rootDir,
153
- targetBasePath.replace(/^\.\//, "")
154
- );
155
- const targetAbsolutePath = path.join(
156
- targetAbsoluteDir,
157
- importPath
158
- );
159
- let relativePath = path.relative(
160
- currentFileDir,
161
- targetAbsolutePath
162
- );
163
- if (!relativePath.startsWith(".")) {
164
- relativePath = "./" + relativePath;
165
- }
166
- return relativePath.replace(/\\/g, "/");
167
- };
168
- content = content.replace(
169
- staticAliasPattern,
170
- (match, statement, openQuote, importPath, closeQuote) => {
171
- const relativePath = calculateRelativePath(importPath);
172
- modified = true;
173
- return `${statement} ${openQuote}${relativePath}${closeQuote}`;
174
- }
175
- );
176
- content = content.replace(
177
- dynamicAliasPattern,
178
- (match, importStatement, openQuote, importPath, closeQuote) => {
179
- const relativePath = calculateRelativePath(importPath);
180
- modified = true;
181
- return `${importStatement}${openQuote}${relativePath}${closeQuote})`;
182
- }
183
- );
184
- }
185
- if (modified) {
186
- await fs.writeFile(filePath, content, "utf8");
187
- console.log(`Updated aliases in: ${filePath}`);
188
- }
189
- } catch (error) {
190
- console.error(`Error processing file ${filePath}:`, error);
191
- }
192
- }
193
-
194
- async function prepare$1({
195
- projectPath,
196
- eruditPath,
197
- contentTargets
198
- }) {
199
- const eruditBuildDir = `${projectPath}/.erudit`;
200
- const distDir = `${projectPath}/dist`;
201
- const nodeModules = `${projectPath}/node_modules`;
202
- const nodeModulesErudit = eruditPath === "erudit" ? `${nodeModules}/erudit` : eruditPath;
203
- if (existsSync(nodeModulesErudit)) {
204
- consola.start("Resolving aliases in dependencies...");
205
- await alias2Relative(nodeModulesErudit, nodeModulesErudit);
206
- await alias2Relative(
207
- nodeModulesErudit,
208
- nodeModules + "/@erudit-js/bitran-elements"
209
- );
210
- consola.success("Resolved aliases in dependencies!");
211
- }
212
- consola.start("Cleaning up...");
213
- if (existsSync(distDir)) rmSync(distDir, { recursive: true });
214
- if (existsSync(eruditBuildDir)) rmSync(eruditBuildDir, { recursive: true });
215
- consola.success("Cleaned up!");
216
- consola.start("Generating Erudit build files...");
217
- mkdirSync(eruditBuildDir, { recursive: true });
218
- mkdirSync(eruditBuildDir + "/nuxt", { recursive: true });
219
- writeFileSync(
220
- `${eruditBuildDir}/nuxt/nuxt.config.ts`,
221
- `
222
- export default {
223
- compatibilityDate: '2025-01-01',
224
- extends: ['${eruditPath}'],
225
- future: {
226
- compatibilityVersion: 4,
227
- },
228
- }
229
- `
230
- );
231
- writeFileSync(
232
- `${eruditBuildDir}/tsconfig.json`,
233
- JSON.stringify(
234
- {
235
- extends: "./nuxt/.nuxt/tsconfig.json",
236
- compilerOptions: {
237
- paths: {
238
- "#project/*": [`${projectPath}/*`],
239
- "#content/*": [`${projectPath}/content/*`]
240
- }
241
- }
242
- },
243
- null,
244
- 4
245
- )
246
- );
247
- await prepareContentTargets(eruditBuildDir, contentTargets);
248
- writeFileSync(
249
- `${eruditBuildDir}/__AUTOGENERATED__`,
250
- `This directory is autogenerated by Erudit CLI.
251
- All changes will be lost on next launch!`
252
- );
253
- consola.success("Erudit build files ready!");
254
- }
255
- async function prepareContentTargets(buildDir, targets) {
256
- if (typeof targets === "undefined" || targets === "") {
257
- return;
258
- }
259
- if (typeof targets === "string") {
260
- targets = [targets];
261
- }
262
- if (Array.isArray(targets)) {
263
- writeFileSync(
264
- `${buildDir}/targets.json`,
265
- JSON.stringify(targets, null, 4)
266
- );
267
- consola.success(`Saved ${targets.length} content targets!`);
268
- return;
269
- }
270
- throw new Error(`Failed to resolve content targets: "${targets}"!`);
271
- }
272
-
273
- async function spawnNuxt(command, projectPath) {
274
- return new Promise((resolve) => {
275
- const onClose = (exitCode) => {
276
- if (exitCode === 1337) _spawnNuxt();
277
- else if (exitCode !== 0)
278
- throw new Error(`Nuxt exited with code ${exitCode}!`);
279
- else resolve();
280
- };
281
- const _spawnNuxt = () => {
282
- const nuxtProcess = spawn(
283
- `nuxt ${command} ${projectPath}/.erudit/nuxt`,
284
- {
285
- shell: true,
286
- stdio: "inherit",
287
- env: {
288
- ...process.env,
289
- ERUDIT_PROJECT_DIR: projectPath
290
- }
291
- }
292
- );
293
- nuxtProcess.on("close", onClose);
294
- };
295
- _spawnNuxt();
296
- });
297
- }
298
-
299
- const eruditPathArg = {
300
- eruditPath: {
301
- type: "string",
302
- description: "Custom Erudit Nuxt Layer location",
303
- required: false,
304
- default: "erudit"
305
- // Let `nuxi` find erudit in project dependencies
306
- }
307
- };
308
- const projectPathArg = {
309
- projectPath: {
310
- type: "positional",
311
- description: "Erudit project location",
312
- required: false,
313
- default: "."
314
- }
315
- };
316
- const contentTargetsArg = {
317
- target: {
318
- type: "string",
319
- description: "Content targets to process",
320
- required: false,
321
- default: ""
322
- }
323
- };
324
- function resolveArgPaths(projectPath, eruditPath) {
325
- consola.start("Resolving project path...");
326
- projectPath = resolvePath(projectPath);
327
- consola.success("Resolved project path:", chalk.greenBright(projectPath));
328
- consola.start("Resolving Erudit Nuxt Layer path...");
329
- if (eruditPath === "erudit") {
330
- consola.success(`'nuxi' will find Erudit in your dependencies!`);
331
- } else {
332
- eruditPath = resolvePath(eruditPath);
333
- consola.warn(
334
- "Custom Erudit Nuxt Layer path will be used: " + chalk.yellowBright(eruditPath)
335
- );
336
- }
337
- return {
338
- projectPath,
339
- eruditPath
340
- };
341
- }
342
-
343
- const prepare = defineCommand({
344
- meta: {
345
- name: "Prepare",
346
- description: "Creates a .erudit directory in your project and generates build files"
347
- },
348
- args: {
349
- ...projectPathArg,
350
- ...eruditPathArg
351
- },
352
- async run({ args }) {
353
- logCommand("prepare");
354
- const { projectPath, eruditPath } = resolveArgPaths(
355
- args.projectPath,
356
- args.eruditPath
357
- );
358
- await prepare$1({
359
- projectPath,
360
- eruditPath
361
- });
362
- consola.start("Generating Nuxt build files...");
363
- await spawnNuxt("prepare", projectPath);
364
- consola.success("Nuxt is prepared!");
365
- }
366
- });
367
-
368
- const dev = defineCommand({
369
- meta: {
370
- name: "Dev",
371
- description: "Runs Erudit project in development mode"
372
- },
373
- args: {
374
- ...projectPathArg,
375
- ...eruditPathArg,
376
- ...contentTargetsArg
377
- },
378
- async run({ args }) {
379
- logCommand("dev");
380
- const { projectPath, eruditPath } = resolveArgPaths(
381
- args.projectPath,
382
- args.eruditPath
383
- );
384
- await prepare$1({
385
- projectPath,
386
- eruditPath,
387
- contentTargets: args.target
388
- });
389
- consola.start("Starting Nuxt dev...");
390
- await spawnNuxt("dev", projectPath);
391
- }
392
- });
393
-
394
- const generate = defineCommand({
395
- meta: {
396
- name: "Generate",
397
- description: "Generates fully static production ready Erudit site"
398
- },
399
- args: {
400
- ...projectPathArg,
401
- ...eruditPathArg,
402
- ...contentTargetsArg
403
- },
404
- async run({ args }) {
405
- logCommand("generate");
406
- const { projectPath, eruditPath } = resolveArgPaths(
407
- args.projectPath,
408
- args.eruditPath
409
- );
410
- await prepare$1({
411
- projectPath,
412
- eruditPath,
413
- contentTargets: args.target
414
- });
415
- consola.start("Starting Nuxt generate...");
416
- await spawnNuxt("generate", projectPath);
417
- }
418
- });
419
-
420
- const preview = defineCommand({
421
- meta: {
422
- name: "Preview",
423
- description: "Preview created static Erudit site"
424
- },
425
- args: {
426
- project: {
427
- type: "positional",
428
- description: "Project path",
429
- required: false,
430
- default: "."
431
- }
432
- },
433
- async run({ args }) {
434
- consola.start("Resolving project path...");
435
- const projectPath = resolvePath(args.project);
436
- consola.success(
437
- "Resolved project path:",
438
- chalk.greenBright(projectPath)
439
- );
440
- const distPath = `${projectPath}/dist`;
441
- if (!existsSync(distPath))
442
- throw new Error(
443
- `No 'dist' folder found! Did you run 'erudit build'?`
444
- );
445
- spawn("npx http-server . -p 3000", {
446
- shell: true,
447
- stdio: "inherit",
448
- env: process.env,
449
- cwd: distPath
450
- });
451
- }
452
- });
453
-
454
- const build = defineCommand({
455
- meta: {
456
- name: "Build",
457
- description: "Builds Erudit project for fast and convenient content writing"
458
- },
459
- args: {
460
- ...projectPathArg,
461
- ...eruditPathArg,
462
- ...contentTargetsArg
463
- },
464
- async run({ args }) {
465
- logCommand("build");
466
- const { projectPath, eruditPath } = resolveArgPaths(
467
- args.projectPath,
468
- args.eruditPath
469
- );
470
- await prepare$1({
471
- projectPath,
472
- eruditPath,
473
- contentTargets: args.target
474
- });
475
- consola$1.start("Starting Nuxt build...");
476
- await spawnNuxt("build", projectPath);
477
- }
478
- });
479
-
480
- const main = defineCommand({
481
- meta: {
482
- name: "Erudit CLI",
483
- description: "Command Line Interface for Erudit!",
484
- version
485
- },
486
- subCommands: {
487
- init,
488
- prepare,
489
- dev,
490
- build,
491
- generate,
492
- preview
493
- },
494
- setup() {
495
- console.log(brandColorLogotype);
496
- }
497
- });
498
-
499
- function run() {
500
- runMain(main);
501
- }
502
-
503
- export { run };