@erudit-js/cli 3.0.0-dev.8 → 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 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,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,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,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,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,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
@@ -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,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,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: `./.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.0.0-dev.8",
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
- ".": "./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.8",
32
- "chalk": "^5.4.1",
35
+ "@erudit-js/core": "4.0.0-dev.1",
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,398 +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.8";
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(rootDir) {
79
- rootDir = resolvePaths(rootDir);
80
- if (!existsSync(rootDir)) {
81
- return;
82
- }
83
- const ALIASES_RESOLVED_FILE = path.join(rootDir, "ALIASES_RESOLVED");
84
- if (existsSync(ALIASES_RESOLVED_FILE)) {
85
- console.log("Aliases already resolved. Skipping...");
86
- return;
87
- }
88
- const replaceMap = {
89
- "@erudit": "./",
90
- "@module": "./module",
91
- "@server": "./server/plugin",
92
- "@shared": "./shared",
93
- "@app": "./app"
94
- };
95
- const allFiles = await findAllFiles(rootDir);
96
- for (const filePath of allFiles) {
97
- await processFile(filePath, rootDir, replaceMap);
98
- }
99
- await fs.writeFile(ALIASES_RESOLVED_FILE, (/* @__PURE__ */ new Date()).toISOString());
100
- console.log("All aliases resolved successfully");
101
- }
102
- async function findAllFiles(dir) {
103
- const results = [];
104
- try {
105
- const entries = await fs.readdir(dir, { withFileTypes: true });
106
- for (const entry of entries) {
107
- const fullPath = path.join(dir, entry.name);
108
- if (entry.isDirectory()) {
109
- if (![".git", "dist", "build"].includes(entry.name)) {
110
- results.push(...await findAllFiles(fullPath));
111
- }
112
- } else if (entry.isFile() && /\.(js|ts|vue)$/.test(entry.name)) {
113
- results.push(fullPath);
114
- }
115
- }
116
- } catch (error) {
117
- console.error(`Error reading directory ${dir}:`, error);
118
- }
119
- return results;
120
- }
121
- async function processFile(filePath, rootDir, replaceMap) {
122
- try {
123
- let content = await fs.readFile(filePath, "utf8");
124
- let modified = false;
125
- for (const [alias, targetBasePath] of Object.entries(replaceMap)) {
126
- const staticAliasPattern = new RegExp(
127
- `(import|from)\\s+(['"])${alias}/([^'"]+)(['"])`,
128
- "g"
129
- );
130
- const dynamicAliasPattern = new RegExp(
131
- `(import\\s*\\()\\s*(['"])${alias}/([^'"]+)(['"])\\s*\\)`,
132
- "g"
133
- );
134
- const calculateRelativePath = (importPath) => {
135
- const currentFileDir = path.dirname(filePath);
136
- const targetAbsoluteDir = path.join(
137
- rootDir,
138
- targetBasePath.replace(/^\.\//, "")
139
- );
140
- const targetAbsolutePath = path.join(
141
- targetAbsoluteDir,
142
- importPath
143
- );
144
- let relativePath = path.relative(
145
- currentFileDir,
146
- targetAbsolutePath
147
- );
148
- if (!relativePath.startsWith(".")) {
149
- relativePath = "./" + relativePath;
150
- }
151
- return relativePath.replace(/\\/g, "/");
152
- };
153
- content = content.replace(
154
- staticAliasPattern,
155
- (match, statement, openQuote, importPath, closeQuote) => {
156
- const relativePath = calculateRelativePath(importPath);
157
- modified = true;
158
- return `${statement} ${openQuote}${relativePath}${closeQuote}`;
159
- }
160
- );
161
- content = content.replace(
162
- dynamicAliasPattern,
163
- (match, importStatement, openQuote, importPath, closeQuote) => {
164
- const relativePath = calculateRelativePath(importPath);
165
- modified = true;
166
- return `${importStatement}${openQuote}${relativePath}${closeQuote})`;
167
- }
168
- );
169
- }
170
- if (modified) {
171
- await fs.writeFile(filePath, content, "utf8");
172
- console.log(`Updated aliases in: ${filePath}`);
173
- }
174
- } catch (error) {
175
- console.error(`Error processing file ${filePath}:`, error);
176
- }
177
- }
178
-
179
- async function prepare$1(projectPath, eruditPath) {
180
- const eruditBuildDir = `${projectPath}/.erudit`;
181
- const distDir = `${projectPath}/dist`;
182
- const nodeModulesErudit = `${projectPath}/node_modules/erudit`;
183
- await alias2Relative(nodeModulesErudit);
184
- consola.start("Cleaning up...");
185
- if (existsSync(distDir)) rmSync(distDir, { recursive: true });
186
- if (existsSync(eruditBuildDir)) rmSync(eruditBuildDir, { recursive: true });
187
- consola.success("Cleaned up!");
188
- consola.start("Generating Erudit build files...");
189
- mkdirSync(eruditBuildDir, { recursive: true });
190
- mkdirSync(eruditBuildDir + "/nuxt", { recursive: true });
191
- writeFileSync(
192
- `${eruditBuildDir}/nuxt/nuxt.config.ts`,
193
- `
194
- export default {
195
- compatibilityDate: '2025-01-01',
196
- extends: ['${eruditPath}'],
197
- future: {
198
- compatibilityVersion: 4,
199
- },
200
- }
201
- `
202
- );
203
- writeFileSync(
204
- `${eruditBuildDir}/tsconfig.json`,
205
- JSON.stringify(
206
- {
207
- extends: "./nuxt/.nuxt/tsconfig.json"
208
- },
209
- null,
210
- 4
211
- )
212
- );
213
- consola.success("Erudit build files ready!");
214
- }
215
-
216
- async function spawnNuxt(command, projectPath) {
217
- return new Promise((resolve) => {
218
- const onClose = (exitCode) => {
219
- if (exitCode === 1337) _spawnNuxt();
220
- else if (exitCode !== 0)
221
- throw new Error(`Nuxt exited with code ${exitCode}!`);
222
- else resolve();
223
- };
224
- const _spawnNuxt = () => {
225
- const nuxtProcess = spawn(
226
- `nuxt ${command} ${projectPath}/.erudit/nuxt`,
227
- {
228
- shell: true,
229
- stdio: "inherit",
230
- env: {
231
- ...process.env,
232
- ERUDIT_PROJECT_DIR: projectPath
233
- }
234
- }
235
- );
236
- nuxtProcess.on("close", onClose);
237
- };
238
- _spawnNuxt();
239
- });
240
- }
241
-
242
- const eruditPathArg = {
243
- eruditPath: {
244
- type: "string",
245
- description: "Custom Erudit Nuxt Layer location",
246
- required: false,
247
- default: "erudit"
248
- // Let `nuxi` find erudit in project dependencies
249
- }
250
- };
251
- const projectPathArg = {
252
- projectPath: {
253
- type: "positional",
254
- description: "Erudit project location",
255
- required: false,
256
- default: "."
257
- }
258
- };
259
- function resolveArgPaths(projectPath, eruditPath) {
260
- consola.start("Resolving project path...");
261
- projectPath = resolvePath(projectPath);
262
- consola.success("Resolved project path:", chalk.greenBright(projectPath));
263
- consola.start("Resolving Erudit Nuxt Layer path...");
264
- if (eruditPath === "erudit") {
265
- consola.success(`'nuxi' will find Erudit in your dependencies!`);
266
- } else {
267
- eruditPath = resolvePath(eruditPath);
268
- consola.warn(
269
- "Custom Erudit Nuxt Layer path will be used: " + chalk.yellowBright(eruditPath)
270
- );
271
- }
272
- return {
273
- projectPath,
274
- eruditPath
275
- };
276
- }
277
-
278
- const prepare = defineCommand({
279
- meta: {
280
- name: "Prepare",
281
- description: "Creates a .erudit directory in your project and generates build files"
282
- },
283
- args: {
284
- ...projectPathArg,
285
- ...eruditPathArg
286
- },
287
- async run({ args }) {
288
- logCommand("prepare");
289
- const { projectPath, eruditPath } = resolveArgPaths(
290
- args.projectPath,
291
- args.eruditPath
292
- );
293
- await prepare$1(projectPath, eruditPath);
294
- consola.start("Generating Nuxt build files...");
295
- await spawnNuxt("prepare", projectPath);
296
- consola.success("Nuxt is prepared!");
297
- }
298
- });
299
-
300
- const dev = defineCommand({
301
- meta: {
302
- name: "Dev",
303
- description: "Runs Erudit project in development mode"
304
- },
305
- args: {
306
- ...projectPathArg,
307
- ...eruditPathArg
308
- },
309
- async run({ args }) {
310
- logCommand("dev");
311
- const { projectPath, eruditPath } = resolveArgPaths(
312
- args.projectPath,
313
- args.eruditPath
314
- );
315
- await prepare$1(projectPath, eruditPath);
316
- consola.start("Starting Nuxt dev...");
317
- await spawnNuxt("dev", projectPath);
318
- }
319
- });
320
-
321
- const build = defineCommand({
322
- meta: {
323
- name: "Build",
324
- description: "Generates fully static Erudit site"
325
- },
326
- args: {
327
- ...projectPathArg,
328
- ...eruditPathArg
329
- },
330
- async run({ args }) {
331
- logCommand("build");
332
- const { projectPath, eruditPath } = resolveArgPaths(
333
- args.projectPath,
334
- args.eruditPath
335
- );
336
- await prepare$1(projectPath, eruditPath);
337
- consola.start("Starting Nuxt build...");
338
- await spawnNuxt("generate", projectPath);
339
- }
340
- });
341
-
342
- const preview = defineCommand({
343
- meta: {
344
- name: "Preview",
345
- description: "Preview created static Erudit site"
346
- },
347
- args: {
348
- project: {
349
- type: "positional",
350
- description: "Project path",
351
- required: false,
352
- default: "."
353
- }
354
- },
355
- async run({ args }) {
356
- consola.start("Resolving project path...");
357
- const projectPath = resolvePath(args.project);
358
- consola.success(
359
- "Resolved project path:",
360
- chalk.greenBright(projectPath)
361
- );
362
- const distPath = `${projectPath}/dist`;
363
- if (!existsSync(distPath))
364
- throw new Error(
365
- `No 'dist' folder found! Did you run 'erudit build'?`
366
- );
367
- spawn("npx http-server . -p 3000", {
368
- shell: true,
369
- stdio: "inherit",
370
- env: process.env,
371
- cwd: distPath
372
- });
373
- }
374
- });
375
-
376
- const main = defineCommand({
377
- meta: {
378
- name: "Erudit CLI",
379
- description: "Command Line Interface for Erudit!",
380
- version
381
- },
382
- subCommands: {
383
- init,
384
- prepare,
385
- dev,
386
- build,
387
- preview
388
- },
389
- setup() {
390
- console.log(brandColorLogotype);
391
- }
392
- });
393
-
394
- function run() {
395
- runMain(main);
396
- }
397
-
398
- export { run };