silgi 0.8.3 → 0.8.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.
@@ -1,4 +1,4 @@
1
- const version = "0.8.3";
1
+ const version = "0.8.5";
2
2
  const packageJson = {
3
3
  version: version};
4
4
 
package/dist/cli/run.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { execSync } from 'node:child_process';
2
- import { readFileSync } from 'node:fs';
2
+ import { existsSync, promises, readFileSync } from 'node:fs';
3
3
  import * as p from '@clack/prompts';
4
4
  import { defineCommand } from 'citty';
5
5
  import { consola } from 'consola';
@@ -7,6 +7,7 @@ import { resolve } from 'pathe';
7
7
  import color from 'picocolors';
8
8
  import { version } from 'silgi/meta';
9
9
  import { c as commonArgs } from './common.mjs';
10
+ import * as dotenv from 'dotenv';
10
11
  import { l as loadOptions } from './loader.mjs';
11
12
  import 'c12';
12
13
  import 'compatx';
@@ -20,6 +21,77 @@ import 'silgi/kit';
20
21
  import 'silgi/runtime/meta';
21
22
  import 'ufo';
22
23
 
24
+ async function setupDotenv(options) {
25
+ const targetEnvironment = options.env ?? process.env;
26
+ const environment = await loadDotenv({
27
+ cwd: options.cwd,
28
+ fileName: options.fileName ?? ".env",
29
+ env: targetEnvironment,
30
+ interpolate: options.interpolate ?? true
31
+ });
32
+ for (const key in environment) {
33
+ if (!key.startsWith("_") && targetEnvironment[key] === void 0) {
34
+ targetEnvironment[key] = environment[key];
35
+ }
36
+ }
37
+ return environment;
38
+ }
39
+ async function loadDotenv(options) {
40
+ const environment = /* @__PURE__ */ Object.create(null);
41
+ const dotenvFile = resolve(options.cwd, options.fileName);
42
+ if (existsSync(dotenvFile)) {
43
+ const parsed = dotenv.parse(await promises.readFile(dotenvFile, "utf8"));
44
+ Object.assign(environment, parsed);
45
+ }
46
+ if (!options.env?._applied) {
47
+ Object.assign(environment, options.env);
48
+ environment._applied = true;
49
+ }
50
+ if (options.interpolate) {
51
+ interpolate(environment);
52
+ }
53
+ return environment;
54
+ }
55
+ function interpolate(target, source = {}, parse = (v) => v) {
56
+ function getValue(key) {
57
+ return source[key] === void 0 ? target[key] : source[key];
58
+ }
59
+ function interpolate2(value, parents = []) {
60
+ if (typeof value !== "string") {
61
+ return value;
62
+ }
63
+ const matches = value.match(/(.?\$\{?[\w:]*\}?)/g) || [];
64
+ return parse(
65
+ matches.reduce((newValue, match) => {
66
+ const parts = /(.?)\$\{?([\w:]+)?\}?/.exec(match) || [];
67
+ const prefix = parts[1];
68
+ let value2, replacePart;
69
+ if (prefix === "\\") {
70
+ replacePart = parts[0] || "";
71
+ value2 = replacePart.replace(String.raw`\$`, "$");
72
+ } else {
73
+ const key = parts[2];
74
+ replacePart = (parts[0] || "").slice(prefix.length);
75
+ if (parents.includes(key)) {
76
+ console.warn(
77
+ `Please avoid recursive environment variables ( loop: ${parents.join(
78
+ " > "
79
+ )} > ${key} )`
80
+ );
81
+ return "";
82
+ }
83
+ value2 = getValue(key);
84
+ value2 = interpolate2(value2, [...parents, key]);
85
+ }
86
+ return value2 === void 0 ? newValue : newValue.replace(replacePart, value2);
87
+ }, value)
88
+ );
89
+ }
90
+ for (const key in target) {
91
+ target[key] = interpolate2(getValue(key));
92
+ }
93
+ }
94
+
23
95
  const run = defineCommand({
24
96
  meta: {
25
97
  name: "run",
@@ -43,6 +115,33 @@ const run = defineCommand({
43
115
  consola.info("Empty command list, maybe forgot pnpm silgi prepare?");
44
116
  return;
45
117
  }
118
+ const customEnvironments = silgiConfig.environments;
119
+ const environment = await p.select({
120
+ message: "Select an environment",
121
+ options: customEnvironments.length > 0 ? customEnvironments.map((env) => ({
122
+ label: env.fileName,
123
+ value: env.fileName
124
+ })) : [
125
+ { label: "Development (.env)", value: "dev" },
126
+ { label: "Production (.env.prod)", value: "prod" },
127
+ { label: "Docker (.env.docker)", value: "docker" }
128
+ ]
129
+ });
130
+ const findEnv = customEnvironments.find((env) => env.fileName === environment);
131
+ if (findEnv) {
132
+ await setupDotenv({
133
+ cwd: findEnv.cwd || silgiConfig.rootDir,
134
+ interpolate: findEnv.interpolate,
135
+ fileName: findEnv.fileName,
136
+ env: findEnv.env
137
+ });
138
+ } else {
139
+ await setupDotenv({
140
+ cwd: silgiConfig.rootDir,
141
+ interpolate: true,
142
+ fileName: `.env.${environment}`
143
+ });
144
+ }
46
145
  const commandName = await p.select({
47
146
  message: "Select a command to run",
48
147
  options: Object.keys(cliJson).map((key) => ({
@@ -51,7 +150,6 @@ const run = defineCommand({
51
150
  }))
52
151
  });
53
152
  const scripts = cliJson[commandName];
54
- console.log("scripts", scripts);
55
153
  const scriptName = await p.select({
56
154
  message: "Select a script to run",
57
155
  options: Object.keys(scripts).map((key) => ({
@@ -1,3 +1,3 @@
1
- const version = "0.8.3";
1
+ const version = "0.8.5";
2
2
 
3
3
  export { version };
@@ -1,3 +1,3 @@
1
- const version = "0.8.3";
1
+ const version = "0.8.5";
2
2
 
3
3
  export { version };
@@ -6,7 +6,7 @@ import { Hookable, NestedHooks } from 'hookable';
6
6
  import { Ignore, Options } from 'ignore';
7
7
  import { TSConfig } from 'pkg-types';
8
8
  import { PresetName, PresetOptions, PresetNameInput } from 'silgi/presets';
9
- import { ResolvedServiceType as ResolvedServiceType$1, SilgiRuntimeShareds as SilgiRuntimeShareds$1, SilgiRuntimeOptions as SilgiRuntimeOptions$1, ModuleMeta as ModuleMeta$1, SilgiCLIHooks as SilgiCLIHooks$1, StorageMounts as StorageMounts$1, SilgiTemplate as SilgiTemplate$1, SilgiFrameworkInfo as SilgiFrameworkInfo$1 } from 'silgi/types';
9
+ import { ResolvedServiceType as ResolvedServiceType$1, SilgiRuntimeShareds as SilgiRuntimeShareds$1, SilgiRuntimeOptions as SilgiRuntimeOptions$1, ModuleMeta as ModuleMeta$1, DotenvOptions as DotenvOptions$1, SilgiCLIHooks as SilgiCLIHooks$1, StorageMounts as StorageMounts$1, SilgiTemplate as SilgiTemplate$1, SilgiFrameworkInfo as SilgiFrameworkInfo$1 } from 'silgi/types';
10
10
  import { UnimportPluginOptions } from 'unimport/unplugin';
11
11
  import { StandardSchemaV1 } from '@standard-schema/spec';
12
12
  import { Defu } from 'defu';
@@ -540,6 +540,7 @@ interface SilgiCLIOptions extends PresetOptions {
540
540
  _cli?: {
541
541
  command?: string;
542
542
  };
543
+ environments: DotenvOptions$1[];
543
544
  namespaces: string[];
544
545
  hooks: NestedHooks<SilgiCLIHooks$1>;
545
546
  plugins: {
@@ -944,6 +945,33 @@ interface SilgiRuntimeContext extends Record<string, any> {
944
945
  interface ExtendContext {
945
946
  }
946
947
 
948
+ interface DotenvOptions {
949
+ /**
950
+ * The project root directory (either absolute or relative to the current working directory).
951
+ */
952
+ cwd: string;
953
+ /**
954
+ * What file to look in for environment variables (either absolute or relative
955
+ * to the current working directory). For example, `.env`.
956
+ */
957
+ fileName?: string;
958
+ /**
959
+ * Whether to interpolate variables within .env.
960
+ *
961
+ * @example
962
+ * ```env
963
+ * BASE_DIR="/test"
964
+ * # resolves to "/test/further"
965
+ * ANOTHER_DIR="${BASE_DIR}/further"
966
+ * ```
967
+ */
968
+ interpolate?: boolean;
969
+ /**
970
+ * An object describing environment variables (key, value pairs).
971
+ */
972
+ env?: NodeJS.ProcessEnv;
973
+ }
974
+
947
975
  interface GraphQLJSON {
948
976
  queries: any;
949
977
  mutations: any;
@@ -962,4 +990,4 @@ type Namespaces<T extends BaseNamespaceType> = {
962
990
 
963
991
  declare const autoImportTypes: string[];
964
992
 
965
- export { type AppConfig, type Awaitable, type BaseNamespaceType, type BaseSchemaType, type BaseSilgiMethodType, type BuildConfig, type CaptureError, type CapturedErrorContext, type CoreTs, type CreateScope, type DeepPartial, type DefaultHooks, type DefaultNamespaces, type EventHandlerResponse, type ExtendContext, type ExtendShared, type ExtractInputFromURI, type ExtractOutputFromURI, type ExtractRouterParamsFromURI, type ExtractSourceFromURI, type FrameworkContext, type GenerateAppOptions, type GraphQLJSON, type HookResult, type ImportItem, type LoadConfigOptions, type MergedSilgiSchema, type MethodHandlerType, type ModuleDefinition, type ModuleHookContext, type ModuleMeta, type ModuleOptionsCustom, type ModuleSetupInstallResult, type ModuleSetupReturn, type Namespaces, type NitroBuildInfo, type PrepareCore, type RequiredServiceType, type ResolvedMethodHandlerType, type ResolvedModuleMeta, type ResolvedModuleOptions, type ResolvedServiceType, type ResolvedSilgiTemplate, type SchemaPreparationOptions, type ServiceType, type Silgi, type SilgiAppPlugin, type SilgiCLI, type SilgiCLIConfig, type SilgiCLIDynamicConfig, type SilgiCLIHooks, type SilgiCLIOptions, type SilgiCompatibility, type SilgiCompatibilityIssue, type SilgiCompatibilityIssues, type SilgiConfig, type SilgiEvents, type SilgiFrameworkInfo, type SilgiFunction, type SilgiHooks, type SilgiModule, type SilgiModuleInput, type SilgiModuleOptions, type SilgiNamespaces, type SilgiOperation, type SilgiOptions, type SilgiPreset, type SilgiPresetMeta, type SilgiRouterTypes, type SilgiRuntimeActions, type SilgiRuntimeContext, type SilgiRuntimeHooks, type SilgiRuntimeMethods, type SilgiRuntimeOptions, type SilgiRuntimeSharedExtends, type SilgiRuntimeShareds, type SilgiSchema, type SilgiServiceInterface, type SilgiStorageBase, type SilgiTemplate, type SilgiURIs, type StorageConfig, type StorageKeyGenerator, type StorageKeyParams, type StorageMounts, type TSReference, type URIsTypes, autoImportTypes };
993
+ export { type AppConfig, type Awaitable, type BaseNamespaceType, type BaseSchemaType, type BaseSilgiMethodType, type BuildConfig, type CaptureError, type CapturedErrorContext, type CoreTs, type CreateScope, type DeepPartial, type DefaultHooks, type DefaultNamespaces, type DotenvOptions, type EventHandlerResponse, type ExtendContext, type ExtendShared, type ExtractInputFromURI, type ExtractOutputFromURI, type ExtractRouterParamsFromURI, type ExtractSourceFromURI, type FrameworkContext, type GenerateAppOptions, type GraphQLJSON, type HookResult, type ImportItem, type LoadConfigOptions, type MergedSilgiSchema, type MethodHandlerType, type ModuleDefinition, type ModuleHookContext, type ModuleMeta, type ModuleOptionsCustom, type ModuleSetupInstallResult, type ModuleSetupReturn, type Namespaces, type NitroBuildInfo, type PrepareCore, type RequiredServiceType, type ResolvedMethodHandlerType, type ResolvedModuleMeta, type ResolvedModuleOptions, type ResolvedServiceType, type ResolvedSilgiTemplate, type SchemaPreparationOptions, type ServiceType, type Silgi, type SilgiAppPlugin, type SilgiCLI, type SilgiCLIConfig, type SilgiCLIDynamicConfig, type SilgiCLIHooks, type SilgiCLIOptions, type SilgiCompatibility, type SilgiCompatibilityIssue, type SilgiCompatibilityIssues, type SilgiConfig, type SilgiEvents, type SilgiFrameworkInfo, type SilgiFunction, type SilgiHooks, type SilgiModule, type SilgiModuleInput, type SilgiModuleOptions, type SilgiNamespaces, type SilgiOperation, type SilgiOptions, type SilgiPreset, type SilgiPresetMeta, type SilgiRouterTypes, type SilgiRuntimeActions, type SilgiRuntimeContext, type SilgiRuntimeHooks, type SilgiRuntimeMethods, type SilgiRuntimeOptions, type SilgiRuntimeSharedExtends, type SilgiRuntimeShareds, type SilgiSchema, type SilgiServiceInterface, type SilgiStorageBase, type SilgiTemplate, type SilgiURIs, type StorageConfig, type StorageKeyGenerator, type StorageKeyParams, type StorageMounts, type TSReference, type URIsTypes, autoImportTypes };
@@ -6,7 +6,7 @@ import { Hookable, NestedHooks } from 'hookable';
6
6
  import { Ignore, Options } from 'ignore';
7
7
  import { TSConfig } from 'pkg-types';
8
8
  import { PresetName, PresetOptions, PresetNameInput } from 'silgi/presets';
9
- import { ResolvedServiceType as ResolvedServiceType$1, SilgiRuntimeShareds as SilgiRuntimeShareds$1, SilgiRuntimeOptions as SilgiRuntimeOptions$1, ModuleMeta as ModuleMeta$1, SilgiCLIHooks as SilgiCLIHooks$1, StorageMounts as StorageMounts$1, SilgiTemplate as SilgiTemplate$1, SilgiFrameworkInfo as SilgiFrameworkInfo$1 } from 'silgi/types';
9
+ import { ResolvedServiceType as ResolvedServiceType$1, SilgiRuntimeShareds as SilgiRuntimeShareds$1, SilgiRuntimeOptions as SilgiRuntimeOptions$1, ModuleMeta as ModuleMeta$1, DotenvOptions as DotenvOptions$1, SilgiCLIHooks as SilgiCLIHooks$1, StorageMounts as StorageMounts$1, SilgiTemplate as SilgiTemplate$1, SilgiFrameworkInfo as SilgiFrameworkInfo$1 } from 'silgi/types';
10
10
  import { UnimportPluginOptions } from 'unimport/unplugin';
11
11
  import { StandardSchemaV1 } from '@standard-schema/spec';
12
12
  import { Defu } from 'defu';
@@ -540,6 +540,7 @@ interface SilgiCLIOptions extends PresetOptions {
540
540
  _cli?: {
541
541
  command?: string;
542
542
  };
543
+ environments: DotenvOptions$1[];
543
544
  namespaces: string[];
544
545
  hooks: NestedHooks<SilgiCLIHooks$1>;
545
546
  plugins: {
@@ -944,6 +945,33 @@ interface SilgiRuntimeContext extends Record<string, any> {
944
945
  interface ExtendContext {
945
946
  }
946
947
 
948
+ interface DotenvOptions {
949
+ /**
950
+ * The project root directory (either absolute or relative to the current working directory).
951
+ */
952
+ cwd: string;
953
+ /**
954
+ * What file to look in for environment variables (either absolute or relative
955
+ * to the current working directory). For example, `.env`.
956
+ */
957
+ fileName?: string;
958
+ /**
959
+ * Whether to interpolate variables within .env.
960
+ *
961
+ * @example
962
+ * ```env
963
+ * BASE_DIR="/test"
964
+ * # resolves to "/test/further"
965
+ * ANOTHER_DIR="${BASE_DIR}/further"
966
+ * ```
967
+ */
968
+ interpolate?: boolean;
969
+ /**
970
+ * An object describing environment variables (key, value pairs).
971
+ */
972
+ env?: NodeJS.ProcessEnv;
973
+ }
974
+
947
975
  interface GraphQLJSON {
948
976
  queries: any;
949
977
  mutations: any;
@@ -962,4 +990,4 @@ type Namespaces<T extends BaseNamespaceType> = {
962
990
 
963
991
  declare const autoImportTypes: string[];
964
992
 
965
- export { type AppConfig, type Awaitable, type BaseNamespaceType, type BaseSchemaType, type BaseSilgiMethodType, type BuildConfig, type CaptureError, type CapturedErrorContext, type CoreTs, type CreateScope, type DeepPartial, type DefaultHooks, type DefaultNamespaces, type EventHandlerResponse, type ExtendContext, type ExtendShared, type ExtractInputFromURI, type ExtractOutputFromURI, type ExtractRouterParamsFromURI, type ExtractSourceFromURI, type FrameworkContext, type GenerateAppOptions, type GraphQLJSON, type HookResult, type ImportItem, type LoadConfigOptions, type MergedSilgiSchema, type MethodHandlerType, type ModuleDefinition, type ModuleHookContext, type ModuleMeta, type ModuleOptionsCustom, type ModuleSetupInstallResult, type ModuleSetupReturn, type Namespaces, type NitroBuildInfo, type PrepareCore, type RequiredServiceType, type ResolvedMethodHandlerType, type ResolvedModuleMeta, type ResolvedModuleOptions, type ResolvedServiceType, type ResolvedSilgiTemplate, type SchemaPreparationOptions, type ServiceType, type Silgi, type SilgiAppPlugin, type SilgiCLI, type SilgiCLIConfig, type SilgiCLIDynamicConfig, type SilgiCLIHooks, type SilgiCLIOptions, type SilgiCompatibility, type SilgiCompatibilityIssue, type SilgiCompatibilityIssues, type SilgiConfig, type SilgiEvents, type SilgiFrameworkInfo, type SilgiFunction, type SilgiHooks, type SilgiModule, type SilgiModuleInput, type SilgiModuleOptions, type SilgiNamespaces, type SilgiOperation, type SilgiOptions, type SilgiPreset, type SilgiPresetMeta, type SilgiRouterTypes, type SilgiRuntimeActions, type SilgiRuntimeContext, type SilgiRuntimeHooks, type SilgiRuntimeMethods, type SilgiRuntimeOptions, type SilgiRuntimeSharedExtends, type SilgiRuntimeShareds, type SilgiSchema, type SilgiServiceInterface, type SilgiStorageBase, type SilgiTemplate, type SilgiURIs, type StorageConfig, type StorageKeyGenerator, type StorageKeyParams, type StorageMounts, type TSReference, type URIsTypes, autoImportTypes };
993
+ export { type AppConfig, type Awaitable, type BaseNamespaceType, type BaseSchemaType, type BaseSilgiMethodType, type BuildConfig, type CaptureError, type CapturedErrorContext, type CoreTs, type CreateScope, type DeepPartial, type DefaultHooks, type DefaultNamespaces, type DotenvOptions, type EventHandlerResponse, type ExtendContext, type ExtendShared, type ExtractInputFromURI, type ExtractOutputFromURI, type ExtractRouterParamsFromURI, type ExtractSourceFromURI, type FrameworkContext, type GenerateAppOptions, type GraphQLJSON, type HookResult, type ImportItem, type LoadConfigOptions, type MergedSilgiSchema, type MethodHandlerType, type ModuleDefinition, type ModuleHookContext, type ModuleMeta, type ModuleOptionsCustom, type ModuleSetupInstallResult, type ModuleSetupReturn, type Namespaces, type NitroBuildInfo, type PrepareCore, type RequiredServiceType, type ResolvedMethodHandlerType, type ResolvedModuleMeta, type ResolvedModuleOptions, type ResolvedServiceType, type ResolvedSilgiTemplate, type SchemaPreparationOptions, type ServiceType, type Silgi, type SilgiAppPlugin, type SilgiCLI, type SilgiCLIConfig, type SilgiCLIDynamicConfig, type SilgiCLIHooks, type SilgiCLIOptions, type SilgiCompatibility, type SilgiCompatibilityIssue, type SilgiCompatibilityIssues, type SilgiConfig, type SilgiEvents, type SilgiFrameworkInfo, type SilgiFunction, type SilgiHooks, type SilgiModule, type SilgiModuleInput, type SilgiModuleOptions, type SilgiNamespaces, type SilgiOperation, type SilgiOptions, type SilgiPreset, type SilgiPresetMeta, type SilgiRouterTypes, type SilgiRuntimeActions, type SilgiRuntimeContext, type SilgiRuntimeHooks, type SilgiRuntimeMethods, type SilgiRuntimeOptions, type SilgiRuntimeSharedExtends, type SilgiRuntimeShareds, type SilgiSchema, type SilgiServiceInterface, type SilgiStorageBase, type SilgiTemplate, type SilgiURIs, type StorageConfig, type StorageKeyGenerator, type StorageKeyParams, type StorageMounts, type TSReference, type URIsTypes, autoImportTypes };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.8.3",
4
+ "version": "0.8.5",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {
@@ -120,6 +120,7 @@
120
120
  "defu": "^6.1.4",
121
121
  "dev-jiti": "^2.4.2",
122
122
  "dot-prop": "^9.0.0",
123
+ "dotenv": "^16.4.7",
123
124
  "escape-string-regexp": "^5.0.0",
124
125
  "globby": "^14.1.0",
125
126
  "hookable": "^5.5.3",