silgi 0.8.0 → 0.8.2

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.
@@ -1,4 +1,4 @@
1
- const version = "0.8.0";
1
+ const version = "0.8.2";
2
2
  const packageJson = {
3
3
  version: version};
4
4
 
@@ -1537,17 +1537,14 @@ async function compileTemplate(template, ctx) {
1537
1537
 
1538
1538
  async function commands(silgi) {
1539
1539
  const commands2 = {
1540
- module1: {
1541
- dev: 'echo "module dev"',
1542
- build: 'echo "module build"'
1543
- }
1540
+ ...silgi.options.commands
1544
1541
  };
1545
1542
  await silgi.callHook("prepare:commands", commands2);
1546
1543
  addTemplate({
1547
1544
  filename: "cli.json",
1548
1545
  where: ".silgi",
1549
1546
  write: true,
1550
- getContents: () => JSON.stringify(commands2, null, 2)
1547
+ getContents: () => Object.keys(commands2).length > 1 ? JSON.stringify(commands2, null, 2) : "{}"
1551
1548
  });
1552
1549
  }
1553
1550
 
package/dist/cli/run.mjs CHANGED
@@ -1,6 +1,8 @@
1
1
  import { execSync } from 'node:child_process';
2
+ import { readFileSync } from 'node:fs';
2
3
  import * as p from '@clack/prompts';
3
4
  import { defineCommand } from 'citty';
5
+ import { consola } from 'consola';
4
6
  import { resolve } from 'pathe';
5
7
  import color from 'picocolors';
6
8
  import { version } from 'silgi/meta';
@@ -10,11 +12,9 @@ import 'c12';
10
12
  import 'compatx';
11
13
  import 'klona/full';
12
14
  import 'std-env';
13
- import 'consola';
14
15
  import 'consola/utils';
15
16
  import 'escape-string-regexp';
16
17
  import 'mlly';
17
- import 'node:fs';
18
18
  import 'pkg-types';
19
19
  import 'silgi/kit';
20
20
  import 'silgi/runtime/meta';
@@ -37,16 +37,21 @@ const run = defineCommand({
37
37
  p.intro(color.bold(`Silgi CLI ${color.green(`v${version}`)}`));
38
38
  const silgiConfig = await loadOptions({});
39
39
  const getCli = resolve(silgiConfig.build.dir, "cli.json");
40
- const cli = await import(getCli);
41
- const commands = cli.default;
40
+ const cli = readFileSync(getCli, "utf-8");
41
+ const cliJson = JSON.parse(cli);
42
+ if (Object.keys(cliJson).length === 0) {
43
+ consola.info("Empty command list, maybe forgot pnpm silgi prepare?");
44
+ return;
45
+ }
42
46
  const commandName = await p.select({
43
47
  message: "Select a command to run",
44
- options: Object.keys(commands).map((key) => ({
48
+ options: Object.keys(cliJson).map((key) => ({
45
49
  label: key,
46
50
  value: key
47
51
  }))
48
52
  });
49
- const scripts = commands[commandName];
53
+ const scripts = cliJson[commandName];
54
+ console.log("scripts", scripts);
50
55
  const scriptName = await p.select({
51
56
  message: "Select a script to run",
52
57
  options: Object.keys(scripts).map((key) => ({
@@ -55,7 +60,13 @@ const run = defineCommand({
55
60
  }))
56
61
  });
57
62
  const script = scripts[scriptName];
58
- execSync(script, { stdio: "inherit" });
63
+ if (script.type === "command") {
64
+ execSync(script.handler, { stdio: "inherit" });
65
+ }
66
+ if (script.type === "function") {
67
+ const fn = eval(`(${script.handler})`);
68
+ fn();
69
+ }
59
70
  }
60
71
  });
61
72
 
@@ -1,3 +1,3 @@
1
- const version = "0.8.0";
1
+ const version = "0.8.2";
2
2
 
3
3
  export { version };
@@ -1,3 +1,3 @@
1
- const version = "0.8.0";
1
+ const version = "0.8.2";
2
2
 
3
3
  export { version };
@@ -8,9 +8,6 @@ const h3 = defineSilgiPreset(
8
8
  },
9
9
  prerender: {
10
10
  crawlLinks: true
11
- },
12
- commands: {
13
- preview: "npx serve ./public"
14
11
  }
15
12
  },
16
13
  {
@@ -12,9 +12,6 @@ const nitro = defineSilgiPreset(
12
12
  typescript: {
13
13
  generateTsConfig: false,
14
14
  tsconfigPath: ".nitro/types/silgi.tsconfig.json"
15
- },
16
- commands: {
17
- preview: "npx serve ./public"
18
15
  }
19
16
  },
20
17
  {
@@ -9,10 +9,7 @@ const npmPackage = defineSilgiPreset(
9
9
  silgi: {
10
10
  serverDir: "{{ serverDir }}/silgi"
11
11
  },
12
- modules: ["./src"],
13
- commands: {
14
- preview: "npx serve ./public"
15
- }
12
+ modules: ["./src"]
16
13
  },
17
14
  {
18
15
  name: "npm-package",
@@ -12,9 +12,6 @@ const nuxt = defineSilgiPreset(
12
12
  typescript: {
13
13
  generateTsConfig: false,
14
14
  tsconfigPath: ".nuxt/silgi.tsconfig.json"
15
- },
16
- commands: {
17
- preview: "npx serve ./public"
18
15
  }
19
16
  },
20
17
  {
@@ -351,7 +351,11 @@ interface SilgiCLIHooks extends SilgiHooks {
351
351
  */
352
352
  'app:templatesGenerated': (app: SilgiCLI, templates: ResolvedSilgiTemplate[], options?: GenerateAppOptions) => HookResult;
353
353
  'scanFiles:done': (app: SilgiCLI) => HookResult;
354
- 'prepare:commands': (commands: Record<string, Record<string, string>>) => HookResult;
354
+ 'prepare:commands': (commands: Record<string, Record<string, {
355
+ type: 'function' | 'command';
356
+ handler: string;
357
+ description?: string;
358
+ }>>) => HookResult;
355
359
  }
356
360
 
357
361
  /**
@@ -726,7 +730,11 @@ interface SilgiCLIOptions extends PresetOptions {
726
730
  * ```
727
731
  */
728
732
  ignoreOptions: Options;
729
- commands: Record<string, string>;
733
+ commands: Record<string, Record<string, {
734
+ type: 'function' | 'command';
735
+ handler: string;
736
+ description?: string;
737
+ }>>;
730
738
  }
731
739
  /**
732
740
  * Silgi input config (silgi.config)
@@ -351,7 +351,11 @@ interface SilgiCLIHooks extends SilgiHooks {
351
351
  */
352
352
  'app:templatesGenerated': (app: SilgiCLI, templates: ResolvedSilgiTemplate[], options?: GenerateAppOptions) => HookResult;
353
353
  'scanFiles:done': (app: SilgiCLI) => HookResult;
354
- 'prepare:commands': (commands: Record<string, Record<string, string>>) => HookResult;
354
+ 'prepare:commands': (commands: Record<string, Record<string, {
355
+ type: 'function' | 'command';
356
+ handler: string;
357
+ description?: string;
358
+ }>>) => HookResult;
355
359
  }
356
360
 
357
361
  /**
@@ -726,7 +730,11 @@ interface SilgiCLIOptions extends PresetOptions {
726
730
  * ```
727
731
  */
728
732
  ignoreOptions: Options;
729
- commands: Record<string, string>;
733
+ commands: Record<string, Record<string, {
734
+ type: 'function' | 'command';
735
+ handler: string;
736
+ description?: string;
737
+ }>>;
730
738
  }
731
739
  /**
732
740
  * Silgi input config (silgi.config)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.8.0",
4
+ "version": "0.8.2",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {