@solid-stack/builder 1.1.6 → 1.1.8
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/README.md +22 -0
- package/dist/bin.js +124 -3
- package/dist/bin.js.map +1 -1
- package/dist/commands/service/command.d.ts.map +1 -1
- package/dist/commands/service/commands/export/command.d.ts +3 -0
- package/dist/commands/service/commands/export/command.d.ts.map +1 -0
- package/dist/commands/service/commands/export/handler.d.ts +9 -0
- package/dist/commands/service/commands/export/handler.d.ts.map +1 -0
- package/dist/core/compileApplicationEnv.d.ts +7 -0
- package/dist/core/compileApplicationEnv.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +125 -4
- package/dist/index.js.map +1 -1
- package/dist/utils/checkDependencies.d.ts +1 -0
- package/dist/utils/checkDependencies.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/commands/service/command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/commands/service/command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASzC,eAAO,MAAM,sBAAsB,QAAS,OAAO,KAAG,IAmCrD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../../../src/commands/service/commands/export/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AAGnD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAqB5D"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface ExportEnvOptions {
|
|
2
|
+
projectDir?: string | undefined;
|
|
3
|
+
full?: boolean | undefined;
|
|
4
|
+
silenceWarnings?: boolean | undefined;
|
|
5
|
+
/** Optional prompt adapter for embedding the command or testing interactions. */
|
|
6
|
+
prompt?: ((question: string) => Promise<string>) | undefined;
|
|
7
|
+
}
|
|
8
|
+
export declare function handleExportEnv(rawStage?: string, options?: ExportEnvOptions): Promise<string[]>;
|
|
9
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../../../src/commands/service/commands/export/handler.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3B,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACtC,iFAAiF;IACjF,MAAM,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC;CAC9D;AAED,wBAAsB,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAsD1G"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Environment } from "../types/index.js";
|
|
2
|
+
import { type CompileEnvironmentOptions } from "./compileEnvironment.js";
|
|
3
|
+
/** Resolve the same compiled configuration that service runners send to Compose. */
|
|
4
|
+
export declare function compileApplicationEnv(stage: Environment, projectDir: string, options?: CompileEnvironmentOptions): Record<string, string>;
|
|
5
|
+
/** Compose dotenv quoting preserves literal dollars, whitespace and multiline values. */
|
|
6
|
+
export declare function serializeApplicationEnv(environment: Record<string, string>): string;
|
|
7
|
+
//# sourceMappingURL=compileApplicationEnv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compileApplicationEnv.d.ts","sourceRoot":"","sources":["../../src/core/compileApplicationEnv.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAsB,KAAK,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAE7F,oFAAoF;AACpF,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,WAAW,EAClB,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,yBAA8B,GACtC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAsBxB;AAED,yFAAyF;AACzF,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAgBnF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./types/index.js";
|
|
|
2
2
|
export { createCli, runCli } from "./cli.js";
|
|
3
3
|
export { compileEnvironment, type CompileEnvironmentOptions, } from "./core/compileEnvironment.js";
|
|
4
4
|
export { compileMeshEnvironment } from "./core/mesh/compileMeshEnvironment.js";
|
|
5
|
+
export { compileApplicationEnv, serializeApplicationEnv } from "./core/compileApplicationEnv.js";
|
|
5
6
|
export { teardownCompose } from "./core/teardownCompose.js";
|
|
6
7
|
export { runCompose } from "./core/runCompose.js";
|
|
7
8
|
export { buildJsonSchema } from "./core/buildSchema.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EACL,kBAAkB,EAClB,KAAK,yBAAyB,GAC/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EACL,kBAAkB,EAClB,KAAK,yBAAyB,GAC/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AACjG,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
1
|
+
import { Command, Argument } from 'commander';
|
|
2
2
|
import pc22 from 'picocolors';
|
|
3
|
-
import fs, { existsSync, readFileSync,
|
|
3
|
+
import fs, { existsSync, readFileSync, mkdirSync, writeFileSync, unlinkSync, statSync } from 'fs';
|
|
4
4
|
import path13 from 'path';
|
|
5
5
|
import { spawnSync, spawn } from 'child_process';
|
|
6
6
|
import { parse, stringify, parseAllDocuments } from 'yaml';
|
|
@@ -9,6 +9,7 @@ import 'crypto';
|
|
|
9
9
|
import os from 'os';
|
|
10
10
|
import net from 'net';
|
|
11
11
|
import { fileURLToPath } from 'url';
|
|
12
|
+
import { createInterface } from 'readline/promises';
|
|
12
13
|
import { createRequire } from 'module';
|
|
13
14
|
|
|
14
15
|
// src/types/index.ts
|
|
@@ -388,7 +389,7 @@ function checkInfra(projectDir = process.cwd()) {
|
|
|
388
389
|
checkComposeContract(buildJson, absProjectDir);
|
|
389
390
|
console.log(pc22.green("\n\u2705 All infrastructure and contract checks passed.\n"));
|
|
390
391
|
}
|
|
391
|
-
function
|
|
392
|
+
function checkComposeAvailability() {
|
|
392
393
|
const composeCheck = spawnSync(
|
|
393
394
|
"docker",
|
|
394
395
|
["compose", "version", "--short"],
|
|
@@ -411,6 +412,9 @@ function checkDependencies() {
|
|
|
411
412
|
`Error: Docker Compose version >= 2.24.0 is required (found ${rawVersion}). Please upgrade Docker Compose to support optional env_file syntax.`
|
|
412
413
|
);
|
|
413
414
|
}
|
|
415
|
+
}
|
|
416
|
+
function checkDependencies() {
|
|
417
|
+
checkComposeAvailability();
|
|
414
418
|
const daemonCheck = spawnSync("docker", ["info"], {
|
|
415
419
|
stdio: "pipe",
|
|
416
420
|
encoding: "utf-8"
|
|
@@ -3627,11 +3631,127 @@ Examples:
|
|
|
3627
3631
|
}
|
|
3628
3632
|
);
|
|
3629
3633
|
};
|
|
3634
|
+
function compileApplicationEnv(stage, projectDir, options = {}) {
|
|
3635
|
+
const dir = resolveProjectDir(projectDir);
|
|
3636
|
+
const yaml = compileEnvironment(stage, dir, options);
|
|
3637
|
+
const result = spawnSync("docker", [
|
|
3638
|
+
"compose",
|
|
3639
|
+
"--project-directory",
|
|
3640
|
+
dir,
|
|
3641
|
+
"-f",
|
|
3642
|
+
"-",
|
|
3643
|
+
"config",
|
|
3644
|
+
"--format",
|
|
3645
|
+
"json"
|
|
3646
|
+
], { cwd: dir, encoding: "utf-8", input: yaml });
|
|
3647
|
+
if (result.error || result.status !== 0) {
|
|
3648
|
+
throw new ScriptError(`Failed to resolve ${stage} application environment: ${result.error?.message || result.stderr || result.stdout}`);
|
|
3649
|
+
}
|
|
3650
|
+
const config = JSON.parse(result.stdout);
|
|
3651
|
+
if (!config.services?.app) {
|
|
3652
|
+
throw new ScriptError(`The ${stage} configuration has no application service ('app').`);
|
|
3653
|
+
}
|
|
3654
|
+
const environment = {};
|
|
3655
|
+
for (const [key, value] of Object.entries(config.services.app.environment ?? {})) {
|
|
3656
|
+
if (value !== null && value !== void 0) {
|
|
3657
|
+
environment[key] = String(value).replace(/\$\$/g, "$");
|
|
3658
|
+
}
|
|
3659
|
+
}
|
|
3660
|
+
return environment;
|
|
3661
|
+
}
|
|
3662
|
+
function serializeApplicationEnv(environment) {
|
|
3663
|
+
return Object.keys(environment).sort().map((key) => {
|
|
3664
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) {
|
|
3665
|
+
throw new ScriptError(`Cannot export invalid environment variable name: ${key}`);
|
|
3666
|
+
}
|
|
3667
|
+
const value = environment[key];
|
|
3668
|
+
if (value.includes("\0")) throw new ScriptError(`Cannot export a NUL character in ${key}.`);
|
|
3669
|
+
const quoted = /'|\\$|\r/.test(value) ? `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t").replace(/\$/g, () => "$$")}"` : `'${value}'`;
|
|
3670
|
+
return `${key}=${quoted}`;
|
|
3671
|
+
}).join("\n") + "\n";
|
|
3672
|
+
}
|
|
3673
|
+
|
|
3674
|
+
// src/commands/service/commands/export/handler.ts
|
|
3675
|
+
var STAGES = ["dev", "prod", "test", "e2e"];
|
|
3676
|
+
async function handleExportEnv(rawStage, options = {}) {
|
|
3677
|
+
const stage = rawStage?.toLowerCase();
|
|
3678
|
+
if (stage !== void 0 && !STAGES.includes(stage)) {
|
|
3679
|
+
throw new ScriptError(`Unknown environment stage: "${rawStage}". Supported stages: ${STAGES.join(", ")}`);
|
|
3680
|
+
}
|
|
3681
|
+
const projectDir = resolveProjectDir(options.projectDir);
|
|
3682
|
+
const stages = stage === void 0 ? STAGES : [stage];
|
|
3683
|
+
const snapshots = stages.map((stage2) => ({
|
|
3684
|
+
stage: stage2,
|
|
3685
|
+
content: serializeApplicationEnv(compileApplicationEnv(stage2, projectDir, options))
|
|
3686
|
+
}));
|
|
3687
|
+
let reader;
|
|
3688
|
+
const ask = async (question) => {
|
|
3689
|
+
if (options.prompt) return options.prompt(question);
|
|
3690
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
3691
|
+
throw new ScriptError("An existing export needs confirmation. Run this command in an interactive terminal to overwrite it or choose another filename.");
|
|
3692
|
+
}
|
|
3693
|
+
reader ??= createInterface({ input: process.stdin, output: process.stdout });
|
|
3694
|
+
return reader.question(question);
|
|
3695
|
+
};
|
|
3696
|
+
const files = [];
|
|
3697
|
+
try {
|
|
3698
|
+
for (const snapshot of snapshots) {
|
|
3699
|
+
let filename = path13.join(projectDir, `.env.${snapshot.stage}`);
|
|
3700
|
+
while (true) {
|
|
3701
|
+
let overwrite = false;
|
|
3702
|
+
if (existsSync(filename)) {
|
|
3703
|
+
const answer = (await ask(`${filename} already exists. Overwrite? [y/N] `)).trim().toLowerCase();
|
|
3704
|
+
overwrite = answer === "y" || answer === "yes";
|
|
3705
|
+
if (!overwrite) {
|
|
3706
|
+
const name = (await ask(`New filename for ${snapshot.stage} (relative to the service directory): `)).trim();
|
|
3707
|
+
if (!name) continue;
|
|
3708
|
+
filename = path13.resolve(projectDir, name);
|
|
3709
|
+
continue;
|
|
3710
|
+
}
|
|
3711
|
+
}
|
|
3712
|
+
mkdirSync(path13.dirname(filename), { recursive: true });
|
|
3713
|
+
try {
|
|
3714
|
+
writeFileSync(filename, snapshot.content, { encoding: "utf-8", flag: overwrite ? "w" : "wx", mode: 384 });
|
|
3715
|
+
} catch (error) {
|
|
3716
|
+
if (!overwrite && error.code === "EEXIST") continue;
|
|
3717
|
+
throw error;
|
|
3718
|
+
}
|
|
3719
|
+
files.push(filename);
|
|
3720
|
+
console.log(pc22.green(`Exported ${snapshot.stage} application environment to ${filename}`));
|
|
3721
|
+
break;
|
|
3722
|
+
}
|
|
3723
|
+
}
|
|
3724
|
+
} finally {
|
|
3725
|
+
reader?.close();
|
|
3726
|
+
}
|
|
3727
|
+
return files;
|
|
3728
|
+
}
|
|
3729
|
+
|
|
3730
|
+
// src/commands/service/commands/export/command.ts
|
|
3731
|
+
function registerExportCommand(service) {
|
|
3732
|
+
const command = service.command("export").description("Export service configuration");
|
|
3733
|
+
command.command("env").description("Export the application's resolved environment for one or all stages").addArgument(new Argument("[stage]", "Stage to export (defaults to all four)").choices(["dev", "prod", "test", "e2e"])).option("-C, --project-dir <dir>", "Service project directory (defaults to cwd)").option("--full", "Export dev with mock dependencies and integrated infra mode").option("--integrated", "Alias for --full").option("--silence-warnings", "Silence non-critical URL templating warnings").addHelpText("after", `
|
|
3734
|
+
Examples:
|
|
3735
|
+
$ builder service export env
|
|
3736
|
+
$ builder service export env dev
|
|
3737
|
+
$ builder service export env e2e -C ./services/backend
|
|
3738
|
+
$ builder service export env dev --full`).action(async (stage, options) => {
|
|
3739
|
+
await handleExportEnv(stage, {
|
|
3740
|
+
projectDir: options.projectDir,
|
|
3741
|
+
full: Boolean(options.full || options.integrated),
|
|
3742
|
+
silenceWarnings: options.silenceWarnings
|
|
3743
|
+
});
|
|
3744
|
+
});
|
|
3745
|
+
}
|
|
3630
3746
|
|
|
3631
3747
|
// src/commands/service/command.ts
|
|
3632
3748
|
var registerServiceCommand = (cmd) => {
|
|
3633
3749
|
const service = cmd.command("service").description("Manage and run services");
|
|
3634
3750
|
service.hook("preAction", async (_thisCommand, actionCommand) => {
|
|
3751
|
+
if (actionCommand.name() === "env" && actionCommand.parent?.name() === "export") {
|
|
3752
|
+
checkComposeAvailability();
|
|
3753
|
+
return;
|
|
3754
|
+
}
|
|
3635
3755
|
checkDependencies();
|
|
3636
3756
|
if (actionCommand.name() === "up") {
|
|
3637
3757
|
const options = actionCommand.opts();
|
|
@@ -3647,6 +3767,7 @@ var registerServiceCommand = (cmd) => {
|
|
|
3647
3767
|
});
|
|
3648
3768
|
registerUpCommand(service);
|
|
3649
3769
|
registerDownCommand(service);
|
|
3770
|
+
registerExportCommand(service);
|
|
3650
3771
|
};
|
|
3651
3772
|
var require2 = createRequire(import.meta.url);
|
|
3652
3773
|
var pkg = require2("../package.json");
|
|
@@ -3757,6 +3878,6 @@ var buildJsonSchema = z.object({
|
|
|
3757
3878
|
tester: buildTesterSchema.optional()
|
|
3758
3879
|
}).strict().describe("Solid Stack service build and deployment configuration");
|
|
3759
3880
|
|
|
3760
|
-
export { NotFoundError, SERVICE_STAGES, ScriptError, buildJsonSchema, compileEnvironment, compileMeshEnvironment, createCli, meshSchema, runCli, runCompose, teardownCompose, version };
|
|
3881
|
+
export { NotFoundError, SERVICE_STAGES, ScriptError, buildJsonSchema, compileApplicationEnv, compileEnvironment, compileMeshEnvironment, createCli, meshSchema, runCli, runCompose, serializeApplicationEnv, teardownCompose, version };
|
|
3761
3882
|
//# sourceMappingURL=index.js.map
|
|
3762
3883
|
//# sourceMappingURL=index.js.map
|