@erudit-js/cli 4.0.0-dev.3 → 4.0.0-dev.5

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