silgi 0.19.0 → 0.19.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.19.0";
1
+ const version = "0.19.2";
2
2
  const peerDependencies = {
3
3
  "@fastify/deepmerge": "^2.0.2",
4
4
  "@nuxt/kit": "^3.15.3",
@@ -1,3 +1,115 @@
1
+ import * as p from '@clack/prompts';
2
+ import { existsSync, promises } from 'node:fs';
3
+ import * as dotenv from 'dotenv';
4
+ import { resolve } from 'pathe';
5
+
6
+ async function setupDotenv(options) {
7
+ const targetEnvironment = options.env ?? process.env;
8
+ const environment = await loadDotenv({
9
+ cwd: options.cwd,
10
+ fileName: options.fileName ?? ".env",
11
+ env: targetEnvironment,
12
+ interpolate: options.interpolate ?? true
13
+ });
14
+ for (const key in environment) {
15
+ if (!key.startsWith("_") && targetEnvironment[key] === void 0) {
16
+ targetEnvironment[key] = environment[key];
17
+ }
18
+ }
19
+ return environment;
20
+ }
21
+ async function loadDotenv(options) {
22
+ const environment = /* @__PURE__ */ Object.create(null);
23
+ const dotenvFile = resolve(options.cwd, options.fileName);
24
+ if (existsSync(dotenvFile)) {
25
+ const parsed = dotenv.parse(await promises.readFile(dotenvFile, "utf8"));
26
+ Object.assign(environment, parsed);
27
+ }
28
+ if (!options.env?._applied) {
29
+ Object.assign(environment, options.env);
30
+ environment._applied = true;
31
+ }
32
+ if (options.interpolate) {
33
+ interpolate(environment);
34
+ }
35
+ return environment;
36
+ }
37
+ function interpolate(target, source = {}, parse = (v) => v) {
38
+ function getValue(key) {
39
+ return source[key] === void 0 ? target[key] : source[key];
40
+ }
41
+ function interpolate2(value, parents = []) {
42
+ if (typeof value !== "string") {
43
+ return value;
44
+ }
45
+ const matches = value.match(/(.?\$\{?[\w:]*\}?)/g) || [];
46
+ return parse(
47
+ matches.reduce((newValue, match) => {
48
+ const parts = /(.?)\$\{?([\w:]+)?\}?/.exec(match) || [];
49
+ const prefix = parts[1];
50
+ let value2, replacePart;
51
+ if (prefix === "\\") {
52
+ replacePart = parts[0] || "";
53
+ value2 = replacePart.replace(String.raw`\$`, "$");
54
+ } else {
55
+ const key = parts[2];
56
+ replacePart = (parts[0] || "").slice(prefix.length);
57
+ if (parents.includes(key)) {
58
+ console.warn(
59
+ `Please avoid recursive environment variables ( loop: ${parents.join(
60
+ " > "
61
+ )} > ${key} )`
62
+ );
63
+ return "";
64
+ }
65
+ value2 = getValue(key);
66
+ value2 = interpolate2(value2, [...parents, key]);
67
+ }
68
+ return value2 === void 0 ? newValue : newValue.replace(replacePart, value2);
69
+ }, value)
70
+ );
71
+ }
72
+ for (const key in target) {
73
+ target[key] = interpolate2(getValue(key));
74
+ }
75
+ }
76
+
77
+ let initialized = false;
78
+ async function prepareEnv(silgiConfig) {
79
+ if (initialized)
80
+ return;
81
+ initialized = true;
82
+ const customEnvironments = silgiConfig.environments;
83
+ const environment = silgiConfig.activeEnvironment ? silgiConfig.activeEnvironment : await p.select({
84
+ message: "Select an environment",
85
+ options: customEnvironments?.length > 0 ? customEnvironments.map((env) => ({
86
+ label: env.fileName,
87
+ value: env.fileName
88
+ })) : [
89
+ { label: "Development (.env.dev)", value: "dev" },
90
+ { label: "Docker (.env.docker)", value: "docker" },
91
+ { label: "Staging (.env.staging)", value: "staging" },
92
+ { label: "Testing (.env.testing)", value: "testing" },
93
+ { label: "Production (.env)", value: ".env" }
94
+ ]
95
+ });
96
+ const findEnv = customEnvironments?.find((env) => env.fileName === environment);
97
+ if (findEnv) {
98
+ await setupDotenv({
99
+ cwd: findEnv.cwd || silgiConfig.rootDir,
100
+ interpolate: findEnv.interpolate,
101
+ fileName: findEnv.fileName,
102
+ env: findEnv.env
103
+ });
104
+ } else {
105
+ await setupDotenv({
106
+ cwd: silgiConfig.rootDir,
107
+ interpolate: true,
108
+ fileName: environment === "prod" ? ".env" : `.env.${environment}`
109
+ });
110
+ }
111
+ }
112
+
1
113
  const commonArgs = {
2
114
  dir: {
3
115
  type: "string",
@@ -10,4 +122,4 @@ const commonArgs = {
10
122
  }
11
123
  };
12
124
 
13
- export { commonArgs as c };
125
+ export { commonArgs as c, prepareEnv as p };
package/dist/cli/dev.mjs CHANGED
@@ -17,9 +17,6 @@ import 'silgi/types';
17
17
  import 'unimport';
18
18
  import '../_chunks/routeRules.mjs';
19
19
  import 'ufo';
20
- import './env.mjs';
21
- import '@clack/prompts';
22
- import 'dotenv';
23
20
  import 'mlly';
24
21
  import 'dev-jiti';
25
22
  import 'node:url';
@@ -41,6 +38,8 @@ import 'pkg-types';
41
38
  import 'pathe/utils';
42
39
  import 'untyped';
43
40
  import './types.mjs';
41
+ import '@clack/prompts';
42
+ import 'dotenv';
44
43
 
45
44
  async function reloadScan(silgi, path, _stats) {
46
45
  const startTime = performance.now();
@@ -1,22 +1,48 @@
1
1
  import { execSync } from 'node:child_process';
2
2
  import { readFileSync } from 'node:fs';
3
- import { defineCommand } from 'citty';
3
+ import { defineCommand, runCommand } from 'citty';
4
4
  import { consola } from 'consola';
5
5
  import { resolve } from 'pathe';
6
6
  import { version } from 'silgi/meta';
7
7
  import { c as commonArgs } from './common.mjs';
8
+ import prepare from './prepare.mjs';
8
9
  import { l as loadOptions } from './loader.mjs';
10
+ import '@clack/prompts';
11
+ import 'dotenv';
12
+ import 'silgi/kit';
13
+ import './writeTypesAndFiles.mjs';
14
+ import 'node:fs/promises';
15
+ import 'hookable';
16
+ import 'silgi/core';
17
+ import 'silgi/runtime/meta';
18
+ import 'silgi/types';
19
+ import 'unimport';
20
+ import '../_chunks/routeRules.mjs';
21
+ import 'ufo';
22
+ import 'mlly';
23
+ import 'dev-jiti';
24
+ import './compatibility.mjs';
25
+ import 'semver/functions/satisfies.js';
26
+ import 'node:url';
27
+ import 'defu';
28
+ import 'exsolve';
29
+ import 'globby';
30
+ import 'ignore';
31
+ import '@oxc-parser/wasm';
32
+ import 'klona';
33
+ import 'unstorage';
34
+ import 'pathe/utils';
35
+ import 'untyped';
36
+ import './types.mjs';
37
+ import 'pkg-types';
38
+ import './run.mjs';
39
+ import 'picocolors';
9
40
  import 'c12';
10
41
  import 'compatx';
11
42
  import 'klona/full';
12
43
  import 'std-env';
13
44
  import 'consola/utils';
14
45
  import 'escape-string-regexp';
15
- import 'mlly';
16
- import 'pkg-types';
17
- import 'silgi/kit';
18
- import 'silgi/runtime/meta';
19
- import 'ufo';
20
46
 
21
47
  const install = defineCommand({
22
48
  meta: {
@@ -32,6 +58,10 @@ const install = defineCommand({
32
58
  }
33
59
  },
34
60
  async run() {
61
+ await runCommand(prepare, {
62
+ rawArgs: []
63
+ }).catch(() => {
64
+ });
35
65
  const silgiConfig = await loadOptions({});
36
66
  const commandArgs = process.argv.slice(process.argv.indexOf("install") + 1);
37
67
  const extraArgs = commandArgs.length ? ` ${commandArgs.join(" ")}` : "";
@@ -1,10 +1,11 @@
1
- import { defineCommand } from 'citty';
1
+ import { defineCommand, runCommand } from 'citty';
2
2
  import consola from 'consola';
3
3
  import { join, resolve } from 'pathe';
4
4
  import { version } from 'silgi/meta';
5
5
  import { writeFile } from 'silgi/kit';
6
6
  import { c as createSilgiCLI, p as prepare$1, w as writeTypesAndFiles, a as writeCoreFile } from './writeTypesAndFiles.mjs';
7
7
  import { c as commonArgs } from './common.mjs';
8
+ import run from './run.mjs';
8
9
  import 'node:fs';
9
10
  import 'node:fs/promises';
10
11
  import 'hookable';
@@ -14,9 +15,6 @@ import 'silgi/types';
14
15
  import 'unimport';
15
16
  import '../_chunks/routeRules.mjs';
16
17
  import 'ufo';
17
- import './env.mjs';
18
- import '@clack/prompts';
19
- import 'dotenv';
20
18
  import 'mlly';
21
19
  import 'dev-jiti';
22
20
  import './compatibility.mjs';
@@ -40,6 +38,10 @@ import 'pkg-types';
40
38
  import 'pathe/utils';
41
39
  import 'untyped';
42
40
  import './types.mjs';
41
+ import '@clack/prompts';
42
+ import 'dotenv';
43
+ import 'node:child_process';
44
+ import 'picocolors';
43
45
 
44
46
  function serializeRules(rules, options = {}) {
45
47
  try {
@@ -169,6 +171,9 @@ const prepare = defineCommand({
169
171
  await silgi.callHook("close", silgi);
170
172
  consola.withTag("silgi").success("Prepare completed");
171
173
  await close();
174
+ await runCommand(run, {
175
+ rawArgs: ["--tag", "init"]
176
+ });
172
177
  }
173
178
  });
174
179
 
package/dist/cli/run.mjs CHANGED
@@ -7,8 +7,7 @@ import { createJiti } from 'dev-jiti';
7
7
  import { resolve } from 'pathe';
8
8
  import color from 'picocolors';
9
9
  import { version } from 'silgi/meta';
10
- import { c as commonArgs } from './common.mjs';
11
- import { p as prepareEnv } from './env.mjs';
10
+ import { c as commonArgs, p as prepareEnv } from './common.mjs';
12
11
  import { l as loadOptions } from './loader.mjs';
13
12
  import 'dotenv';
14
13
  import 'c12';
@@ -46,10 +45,6 @@ const run = defineCommand({
46
45
  const getCli = resolve(silgiConfig.build.dir, "cli.json");
47
46
  const cli = readFileSync(getCli, "utf-8");
48
47
  const cliJson = JSON.parse(cli);
49
- if (Object.keys(cliJson).length === 0) {
50
- consola.info("Empty command list, maybe forgot pnpm silgi prepare?");
51
- return;
52
- }
53
48
  await prepareEnv(silgiConfig);
54
49
  let selectedCommands = [];
55
50
  if (tags) {
@@ -67,7 +62,6 @@ const run = defineCommand({
67
62
  }
68
63
  }
69
64
  if (selectedCommands.length === 0) {
70
- consola.warn(`No commands found with tags: ${tags.join(", ")}`);
71
65
  return;
72
66
  }
73
67
  } else {
@@ -102,6 +96,9 @@ const run = defineCommand({
102
96
  }
103
97
  for (const cmd of selectedCommands) {
104
98
  consola.info(`Running ${cmd.command}:${cmd.script}...`);
99
+ if (!cmd.handler.enabled) {
100
+ continue;
101
+ }
105
102
  if (cmd.handler.type === "command") {
106
103
  execSync(cmd.handler.handler, { stdio: "inherit" });
107
104
  }
@@ -9,7 +9,7 @@ import { runtimeDir } from 'silgi/runtime/meta';
9
9
  import { autoImportTypes } from 'silgi/types';
10
10
  import { scanExports, createUnimport, toExports } from 'unimport';
11
11
  import { c as createRouteRules } from '../_chunks/routeRules.mjs';
12
- import { p as prepareEnv } from './env.mjs';
12
+ import { p as prepareEnv } from './common.mjs';
13
13
  import { resolveModuleExportNames, resolvePath, parseNodeModulePath, lookupNodeModuleSubpath } from 'mlly';
14
14
  import { createJiti } from 'dev-jiti';
15
15
  import { a as hasInstalledModule, h as hasError } from './compatibility.mjs';
@@ -1,4 +1,4 @@
1
- const version = "0.19.0";
1
+ const version = "0.19.2";
2
2
  const peerDependencies = {
3
3
  "@fastify/deepmerge": "^2.0.2",
4
4
  "@nuxt/kit": "^3.15.3",
@@ -1,4 +1,4 @@
1
- const version = "0.19.0";
1
+ const version = "0.19.2";
2
2
  const peerDependencies = {
3
3
  "@fastify/deepmerge": "^2.0.2",
4
4
  "@nuxt/kit": "^3.15.3",
@@ -280,6 +280,7 @@ interface SilgiCLIHooks extends SilgiHooks {
280
280
  handler: string;
281
281
  description?: string;
282
282
  tags?: string[];
283
+ enabled?: boolean;
283
284
  }>>) => HookResult;
284
285
  'prepare:installPackages': (packages: Record<'dependencies' | 'devDependencies', Record<string, string>>) => HookResult;
285
286
  }
@@ -280,6 +280,7 @@ interface SilgiCLIHooks extends SilgiHooks {
280
280
  handler: string;
281
281
  description?: string;
282
282
  tags?: string[];
283
+ enabled?: boolean;
283
284
  }>>) => HookResult;
284
285
  'prepare:installPackages': (packages: Record<'dependencies' | 'devDependencies', Record<string, string>>) => HookResult;
285
286
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.19.0",
4
+ "version": "0.19.2",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {
package/dist/cli/env.mjs DELETED
@@ -1,113 +0,0 @@
1
- import * as p from '@clack/prompts';
2
- import { existsSync, promises } from 'node:fs';
3
- import * as dotenv from 'dotenv';
4
- import { resolve } from 'pathe';
5
-
6
- async function setupDotenv(options) {
7
- const targetEnvironment = options.env ?? process.env;
8
- const environment = await loadDotenv({
9
- cwd: options.cwd,
10
- fileName: options.fileName ?? ".env",
11
- env: targetEnvironment,
12
- interpolate: options.interpolate ?? true
13
- });
14
- for (const key in environment) {
15
- if (!key.startsWith("_") && targetEnvironment[key] === void 0) {
16
- targetEnvironment[key] = environment[key];
17
- }
18
- }
19
- return environment;
20
- }
21
- async function loadDotenv(options) {
22
- const environment = /* @__PURE__ */ Object.create(null);
23
- const dotenvFile = resolve(options.cwd, options.fileName);
24
- if (existsSync(dotenvFile)) {
25
- const parsed = dotenv.parse(await promises.readFile(dotenvFile, "utf8"));
26
- Object.assign(environment, parsed);
27
- }
28
- if (!options.env?._applied) {
29
- Object.assign(environment, options.env);
30
- environment._applied = true;
31
- }
32
- if (options.interpolate) {
33
- interpolate(environment);
34
- }
35
- return environment;
36
- }
37
- function interpolate(target, source = {}, parse = (v) => v) {
38
- function getValue(key) {
39
- return source[key] === void 0 ? target[key] : source[key];
40
- }
41
- function interpolate2(value, parents = []) {
42
- if (typeof value !== "string") {
43
- return value;
44
- }
45
- const matches = value.match(/(.?\$\{?[\w:]*\}?)/g) || [];
46
- return parse(
47
- matches.reduce((newValue, match) => {
48
- const parts = /(.?)\$\{?([\w:]+)?\}?/.exec(match) || [];
49
- const prefix = parts[1];
50
- let value2, replacePart;
51
- if (prefix === "\\") {
52
- replacePart = parts[0] || "";
53
- value2 = replacePart.replace(String.raw`\$`, "$");
54
- } else {
55
- const key = parts[2];
56
- replacePart = (parts[0] || "").slice(prefix.length);
57
- if (parents.includes(key)) {
58
- console.warn(
59
- `Please avoid recursive environment variables ( loop: ${parents.join(
60
- " > "
61
- )} > ${key} )`
62
- );
63
- return "";
64
- }
65
- value2 = getValue(key);
66
- value2 = interpolate2(value2, [...parents, key]);
67
- }
68
- return value2 === void 0 ? newValue : newValue.replace(replacePart, value2);
69
- }, value)
70
- );
71
- }
72
- for (const key in target) {
73
- target[key] = interpolate2(getValue(key));
74
- }
75
- }
76
-
77
- let initialized = false;
78
- async function prepareEnv(silgiConfig) {
79
- if (initialized)
80
- return;
81
- initialized = true;
82
- const customEnvironments = silgiConfig.environments;
83
- const environment = silgiConfig.activeEnvironment ? silgiConfig.activeEnvironment : await p.select({
84
- message: "Select an environment",
85
- options: customEnvironments?.length > 0 ? customEnvironments.map((env) => ({
86
- label: env.fileName,
87
- value: env.fileName
88
- })) : [
89
- { label: "Development (.env.dev)", value: "dev" },
90
- { label: "Docker (.env.docker)", value: "docker" },
91
- { label: "Staging (.env.staging)", value: "staging" },
92
- { label: "Testing (.env.testing)", value: "testing" },
93
- { label: "Production (.env)", value: ".env" }
94
- ]
95
- });
96
- const findEnv = customEnvironments?.find((env) => env.fileName === environment);
97
- if (findEnv) {
98
- await setupDotenv({
99
- cwd: findEnv.cwd || silgiConfig.rootDir,
100
- interpolate: findEnv.interpolate,
101
- fileName: findEnv.fileName,
102
- env: findEnv.env
103
- });
104
- } else {
105
- await setupDotenv({
106
- cwd: silgiConfig.rootDir,
107
- interpolate: true,
108
- fileName: environment === "prod" ? ".env" : `.env.${environment}`
109
- });
110
- }
111
- }
112
-
113
- export { prepareEnv as p };