appstage 0.2.26 → 0.2.28

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/dist/bin.js CHANGED
@@ -29,49 +29,102 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
29
  var require_dist = __commonJS({
30
30
  "node_modules/args-json/dist/index.cjs"(exports) {
31
31
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
32
+ function getDefaultInput() {
33
+ return typeof process === "undefined" ? [] : process.argv;
34
+ }
35
+ var offValues = /* @__PURE__ */ new Set([
36
+ "0",
37
+ "false",
38
+ "null",
39
+ "undefined",
40
+ "off"
41
+ ]);
42
+ function isOff(x) {
43
+ return offValues.has(String(x));
44
+ }
45
+ function isExplicitlyOff(x) {
46
+ return isOff(x) && String(x) !== "undefined";
47
+ }
32
48
  function isKey2(x) {
33
49
  return x.startsWith("-") && x.length === 2 && x !== "--" || x.startsWith("--") && x.length > 2;
34
50
  }
51
+ var onValues = /* @__PURE__ */ new Set([
52
+ "1",
53
+ "true",
54
+ "on"
55
+ ]);
56
+ function isOn(x) {
57
+ return onValues.has(String(x));
58
+ }
59
+ function normalizeInput(input) {
60
+ let source = input ?? getDefaultInput();
61
+ let result = [];
62
+ for (let s of source) {
63
+ if (s.startsWith("-") && s.includes("=")) {
64
+ let key = s.slice(0, s.indexOf("="));
65
+ if (isKey2(key)) {
66
+ result.push(key, s.slice(key.length + 1));
67
+ continue;
68
+ }
69
+ }
70
+ result.push(s);
71
+ }
72
+ return result;
73
+ }
35
74
  var Args2 = class {
36
- _values;
37
- constructor(values) {
38
- this._values = values ?? process.argv.slice(2);
75
+ _input;
76
+ constructor(input) {
77
+ this._input = normalizeInput(input);
39
78
  }
40
79
  hasKey(x) {
41
- return isKey2(x) && this._values.includes(x);
80
+ return isKey2(x) && this._input.includes(x);
81
+ }
82
+ isOn(key) {
83
+ let args2 = this._input;
84
+ let k = args2.indexOf(key);
85
+ return k !== -1 && (k === args2.length - 1 || isKey2(args2[k + 1]) || isOn(args2[k + 1]));
86
+ }
87
+ isOff(key) {
88
+ let args2 = this._input;
89
+ let k = args2.indexOf(key);
90
+ return k === -1 || isOff(args2[k + 1]);
91
+ }
92
+ isExplicitlyOff(key) {
93
+ let args2 = this._input;
94
+ let k = args2.indexOf(key);
95
+ return k !== -1 && isExplicitlyOff(args2[k + 1]);
42
96
  }
43
97
  getValue(key, fallback) {
44
- let args = this._values;
98
+ let args2 = this._input;
45
99
  let keys = Array.isArray(key) ? key : [key];
46
100
  for (let k of keys) {
47
- let i = args.indexOf(k);
48
- if (i !== -1 && args[i + 1] && !isKey2(args[i + 1])) return args[i + 1];
101
+ let i = args2.indexOf(k);
102
+ if (i !== -1 && args2[i + 1] && !isKey2(args2[i + 1])) return args2[i + 1];
49
103
  }
50
104
  return fallback;
51
105
  }
52
106
  getValues(key, fallback) {
53
- let args = this._values;
107
+ let args2 = this._input;
54
108
  let keys = Array.isArray(key) ? key : [key];
55
109
  let values = [];
56
110
  for (let k of keys) {
57
- let i = args.indexOf(k);
58
- while (i !== -1 && args[i + 1] && !isKey2(args[i + 1])) values.push(args[++i]);
111
+ let i = args2.indexOf(k);
112
+ while (i !== -1 && args2[i + 1] && !isKey2(args2[i + 1])) values.push(args2[++i]);
59
113
  }
60
114
  return values.length === 0 ? fallback : values;
61
115
  }
62
116
  };
117
+ var args = new Args2();
63
118
  function getValue(key, fallback) {
64
- let args = new Args2();
65
119
  if (fallback === void 0) return args.getValue(key);
66
120
  return args.getValue(key, fallback);
67
121
  }
68
122
  function getValues(key, fallback) {
69
- let args = new Args2();
70
123
  if (fallback === void 0) return args.getValues(key);
71
124
  return args.getValues(key, fallback);
72
125
  }
73
126
  function hasKey2(x) {
74
- return new Args2().hasKey(x);
127
+ return args.hasKey(x);
75
128
  }
76
129
  function split(x) {
77
130
  let words = [], word = "";
@@ -101,9 +154,6 @@ var require_dist = __commonJS({
101
154
  if (x.startsWith("-") && x.length === 2) return toCamelCase(x.slice(1));
102
155
  if (x.startsWith("--") && x.length > 2) return toCamelCase(x.slice(2));
103
156
  }
104
- function getDefaultInput() {
105
- return typeof process === "undefined" ? [] : process.argv;
106
- }
107
157
  function parseArgs(input, map) {
108
158
  let normalizedInput;
109
159
  let normalizedMap;
@@ -155,10 +205,14 @@ var require_dist = __commonJS({
155
205
  return parsedArgs;
156
206
  }
157
207
  exports.Args = Args2;
208
+ exports.args = args;
158
209
  exports.getValue = getValue;
159
210
  exports.getValues = getValues;
160
211
  exports.hasKey = hasKey2;
212
+ exports.isExplicitlyOff = isExplicitlyOff;
161
213
  exports.isKey = isKey2;
214
+ exports.isOff = isOff;
215
+ exports.isOn = isOn;
162
216
  exports.parseArgs = parseArgs;
163
217
  }
164
218
  });
@@ -363,6 +417,7 @@ import { rm as rm2 } from "node:fs/promises";
363
417
  // src/scripts/build.ts
364
418
  var import_dateshape = __toESM(require_dist2(), 1);
365
419
  import { spawn } from "node:child_process";
420
+ import { access as access2 } from "node:fs/promises";
366
421
 
367
422
  // src/scripts/utils/buildClient.ts
368
423
  import esbuild from "esbuild";
@@ -609,6 +664,24 @@ function createPostbuildPlugins({ serverDir, clientDir }, onServerRebuild) {
609
664
  }
610
665
 
611
666
  // src/scripts/build.ts
667
+ var envFileNames = {
668
+ development: [".env.development", ".env.dev"],
669
+ production: [".env.production", ".env.prod"]
670
+ };
671
+ async function getEnvFiles() {
672
+ let { NODE_ENV } = process.env;
673
+ let names = [".env"];
674
+ if (NODE_ENV !== void 0 && NODE_ENV in envFileNames)
675
+ names.push(...envFileNames[NODE_ENV]);
676
+ for (let i = names.length - 1; i >= 0; i--) {
677
+ try {
678
+ await access2(names[i]);
679
+ } catch {
680
+ names.splice(i, 1);
681
+ }
682
+ }
683
+ return names;
684
+ }
612
685
  async function build(params) {
613
686
  let startTime = Date.now();
614
687
  let log = params.silent ? () => {
@@ -616,6 +689,12 @@ async function build(params) {
616
689
  log("Build started");
617
690
  let serverProcess = null;
618
691
  let inited = false;
692
+ let nodeArgs = [`${params.serverDir}/server/index.js`];
693
+ if (params.useEnvFiles !== false) {
694
+ let envFiles = await getEnvFiles();
695
+ for (let envFile of envFiles) log(`Using ${envFile}`);
696
+ nodeArgs.unshift(...envFiles.map((file) => `--env-file=${file}`));
697
+ }
619
698
  function handleServerRebuild() {
620
699
  if (serverProcess) {
621
700
  serverProcess.kill();
@@ -626,9 +705,7 @@ async function build(params) {
626
705
  inited = true;
627
706
  }
628
707
  if (params.start)
629
- serverProcess = spawn("node", [`${params.serverDir}/server/index.js`], {
630
- stdio: "inherit"
631
- });
708
+ serverProcess = spawn("node", nodeArgs, { stdio: "inherit" });
632
709
  }
633
710
  let { serverPlugins, serverCSSPlugins } = createPostbuildPlugins(
634
711
  params,
@@ -660,7 +737,8 @@ async function cli(input = []) {
660
737
  watch: args.hasKey("--watch"),
661
738
  watchServer: args.hasKey("--watch-server"),
662
739
  watchClient: args.hasKey("--watch-client"),
663
- start: args.hasKey("--start")
740
+ start: args.hasKey("--start"),
741
+ useEnvFiles: !args.isExplicitlyOff("--use-env-files")
664
742
  };
665
743
  if (args.hasKey("--no-auto-entries")) params.entriesPath = null;
666
744
  if (args.hasKey("--clean-only")) {
package/dist/index.cjs CHANGED
@@ -590,12 +590,33 @@ function createPostbuildPlugins({ serverDir, clientDir }, onServerRebuild) {
590
590
  };
591
591
  }
592
592
 
593
+ const envFileNames = {
594
+ development: [".env.development", ".env.dev"],
595
+ production: [".env.production", ".env.prod"]
596
+ };
597
+ async function getEnvFiles() {
598
+ let { NODE_ENV } = process.env;
599
+ let names = [".env"];
600
+ if (NODE_ENV !== void 0 && NODE_ENV in envFileNames) names.push(...envFileNames[NODE_ENV]);
601
+ for (let i = names.length - 1; i >= 0; i--) try {
602
+ await (0, node_fs_promises.access)(names[i]);
603
+ } catch {
604
+ names.splice(i, 1);
605
+ }
606
+ return names;
607
+ }
593
608
  async function build(params) {
594
609
  let startTime = Date.now();
595
610
  let log = params.silent ? () => {} : console.log;
596
611
  log("Build started");
597
612
  let serverProcess = null;
598
613
  let inited = false;
614
+ let nodeArgs = [`${params.serverDir}/server/index.js`];
615
+ if (params.useEnvFiles !== false) {
616
+ let envFiles = await getEnvFiles();
617
+ for (let envFile of envFiles) log(`Using ${envFile}`);
618
+ nodeArgs.unshift(...envFiles.map((file) => `--env-file=${file}`));
619
+ }
599
620
  function handleServerRebuild() {
600
621
  if (serverProcess) {
601
622
  serverProcess.kill();
@@ -605,7 +626,7 @@ async function build(params) {
605
626
  log(`Build completed +${(0, dateshape.formatDuration)(Date.now() - startTime)}`);
606
627
  inited = true;
607
628
  }
608
- if (params.start) serverProcess = (0, node_child_process.spawn)("node", [`${params.serverDir}/server/index.js`], { stdio: "inherit" });
629
+ if (params.start) serverProcess = (0, node_child_process.spawn)("node", nodeArgs, { stdio: "inherit" });
609
630
  }
610
631
  let { serverPlugins, serverCSSPlugins } = createPostbuildPlugins(params, handleServerRebuild);
611
632
  await Promise.all([
@@ -638,7 +659,8 @@ async function cli(input = []) {
638
659
  watch: args.hasKey("--watch"),
639
660
  watchServer: args.hasKey("--watch-server"),
640
661
  watchClient: args.hasKey("--watch-client"),
641
- start: args.hasKey("--start")
662
+ start: args.hasKey("--start"),
663
+ useEnvFiles: !args.isExplicitlyOff("--use-env-files")
642
664
  };
643
665
  if (args.hasKey("--no-auto-entries")) params.entriesPath = null;
644
666
  if (args.hasKey("--clean-only")) {
package/dist/index.d.ts CHANGED
@@ -119,6 +119,10 @@ type BuildParams = {
119
119
  * @default "src/server/entries.ts"
120
120
  */
121
121
  entriesPath?: string | null;
122
+ /**
123
+ * @default true
124
+ */
125
+ useEnvFiles?: boolean;
122
126
  };
123
127
 
124
128
  declare function build(params: BuildParams): Promise<void>;
package/dist/index.mjs CHANGED
@@ -564,12 +564,33 @@ function createPostbuildPlugins({ serverDir, clientDir }, onServerRebuild) {
564
564
  };
565
565
  }
566
566
 
567
+ const envFileNames = {
568
+ development: [".env.development", ".env.dev"],
569
+ production: [".env.production", ".env.prod"]
570
+ };
571
+ async function getEnvFiles() {
572
+ let { NODE_ENV } = process.env;
573
+ let names = [".env"];
574
+ if (NODE_ENV !== void 0 && NODE_ENV in envFileNames) names.push(...envFileNames[NODE_ENV]);
575
+ for (let i = names.length - 1; i >= 0; i--) try {
576
+ await access(names[i]);
577
+ } catch {
578
+ names.splice(i, 1);
579
+ }
580
+ return names;
581
+ }
567
582
  async function build(params) {
568
583
  let startTime = Date.now();
569
584
  let log = params.silent ? () => {} : console.log;
570
585
  log("Build started");
571
586
  let serverProcess = null;
572
587
  let inited = false;
588
+ let nodeArgs = [`${params.serverDir}/server/index.js`];
589
+ if (params.useEnvFiles !== false) {
590
+ let envFiles = await getEnvFiles();
591
+ for (let envFile of envFiles) log(`Using ${envFile}`);
592
+ nodeArgs.unshift(...envFiles.map((file) => `--env-file=${file}`));
593
+ }
573
594
  function handleServerRebuild() {
574
595
  if (serverProcess) {
575
596
  serverProcess.kill();
@@ -579,7 +600,7 @@ async function build(params) {
579
600
  log(`Build completed +${formatDuration(Date.now() - startTime)}`);
580
601
  inited = true;
581
602
  }
582
- if (params.start) serverProcess = spawn("node", [`${params.serverDir}/server/index.js`], { stdio: "inherit" });
603
+ if (params.start) serverProcess = spawn("node", nodeArgs, { stdio: "inherit" });
583
604
  }
584
605
  let { serverPlugins, serverCSSPlugins } = createPostbuildPlugins(params, handleServerRebuild);
585
606
  await Promise.all([
@@ -612,7 +633,8 @@ async function cli(input = []) {
612
633
  watch: args.hasKey("--watch"),
613
634
  watchServer: args.hasKey("--watch-server"),
614
635
  watchClient: args.hasKey("--watch-client"),
615
- start: args.hasKey("--start")
636
+ start: args.hasKey("--start"),
637
+ useEnvFiles: !args.isExplicitlyOff("--use-env-files")
616
638
  };
617
639
  if (args.hasKey("--no-auto-entries")) params.entriesPath = null;
618
640
  if (args.hasKey("--clean-only")) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "appstage",
3
- "version": "0.2.26",
3
+ "version": "0.2.28",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -29,8 +29,8 @@
29
29
  "@types/node": "^25.4.0"
30
30
  },
31
31
  "dependencies": {
32
- "args-json": "^1.3.3",
32
+ "args-json": "^1.4.3",
33
33
  "dateshape": "^1.1.2",
34
- "esbuild": "^0.27.4"
34
+ "esbuild": "^0.28.0"
35
35
  }
36
36
  }
@@ -1,4 +1,5 @@
1
1
  import { type ChildProcess, spawn } from "node:child_process";
2
+ import { access } from "node:fs/promises";
2
3
  import { formatDuration } from "dateshape";
3
4
  import type { BuildParams } from "./types/BuildParams.ts";
4
5
  import { buildClient } from "./utils/buildClient.ts";
@@ -6,6 +7,29 @@ import { buildServer } from "./utils/buildServer.ts";
6
7
  import { buildServerCSS } from "./utils/buildServerCSS.ts";
7
8
  import { createPostbuildPlugins } from "./utils/createPostbuildPlugins.ts";
8
9
 
10
+ const envFileNames: Record<string, string[]> = {
11
+ development: [".env.development", ".env.dev"],
12
+ production: [".env.production", ".env.prod"],
13
+ };
14
+
15
+ async function getEnvFiles() {
16
+ let { NODE_ENV } = process.env;
17
+ let names = [".env"];
18
+
19
+ if (NODE_ENV !== undefined && NODE_ENV in envFileNames)
20
+ names.push(...envFileNames[NODE_ENV]);
21
+
22
+ for (let i = names.length - 1; i >= 0; i--) {
23
+ try {
24
+ await access(names[i]);
25
+ } catch {
26
+ names.splice(i, 1);
27
+ }
28
+ }
29
+
30
+ return names;
31
+ }
32
+
9
33
  export async function build(params: BuildParams) {
10
34
  let startTime = Date.now();
11
35
  let log = params.silent ? () => {} : console.log;
@@ -14,6 +38,15 @@ export async function build(params: BuildParams) {
14
38
 
15
39
  let serverProcess: ChildProcess | null = null;
16
40
  let inited = false;
41
+ let nodeArgs = [`${params.serverDir}/server/index.js`];
42
+
43
+ if (params.useEnvFiles !== false) {
44
+ let envFiles = await getEnvFiles();
45
+
46
+ for (let envFile of envFiles) log(`Using ${envFile}`);
47
+
48
+ nodeArgs.unshift(...envFiles.map((file) => `--env-file=${file}`));
49
+ }
17
50
 
18
51
  function handleServerRebuild() {
19
52
  if (serverProcess) {
@@ -27,9 +60,7 @@ export async function build(params: BuildParams) {
27
60
  }
28
61
 
29
62
  if (params.start)
30
- serverProcess = spawn("node", [`${params.serverDir}/server/index.js`], {
31
- stdio: "inherit",
32
- });
63
+ serverProcess = spawn("node", nodeArgs, { stdio: "inherit" });
33
64
  }
34
65
 
35
66
  let { serverPlugins, serverCSSPlugins } = createPostbuildPlugins(
@@ -27,6 +27,7 @@ export async function cli(input: string[] = []) {
27
27
  watchServer: args.hasKey("--watch-server"),
28
28
  watchClient: args.hasKey("--watch-client"),
29
29
  start: args.hasKey("--start"),
30
+ useEnvFiles: !args.isExplicitlyOff("--use-env-files"),
30
31
  };
31
32
 
32
33
  if (args.hasKey("--no-auto-entries")) params.entriesPath = null;
@@ -15,4 +15,8 @@ export type BuildParams = {
15
15
  * @default "src/server/entries.ts"
16
16
  */
17
17
  entriesPath?: string | null;
18
+ /**
19
+ * @default true
20
+ */
21
+ useEnvFiles?: boolean;
18
22
  };
@@ -4,7 +4,7 @@ import type { BuildParams } from "../types/BuildParams.ts";
4
4
 
5
5
  export function createPostbuildPlugins(
6
6
  { serverDir, clientDir }: BuildParams,
7
- onServerRebuild: () => void,
7
+ onServerRebuild: (() => void) | (() => Promise<void>),
8
8
  ) {
9
9
  let serverPlugins: Plugin[] = [
10
10
  {