carlin 1.48.3 → 1.49.0
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/index.js +40 -86
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -813,34 +813,7 @@ var saveEnvironmentOutput = /* @__PURE__ */ __name(async ({ outputs, stackName }
|
|
|
813
813
|
const latestFilePath = path.join(dotCarlinFolderPath, LATEST_DEPLOY_OUTPUTS_FILENAME);
|
|
814
814
|
await fs3.promises.writeFile(latestFilePath, JSON.stringify(envFile, null, 2));
|
|
815
815
|
}, "saveEnvironmentOutput");
|
|
816
|
-
var
|
|
817
|
-
const githubEnvFile = process.env.GITHUB_ENV;
|
|
818
|
-
for (const [cfOutputKey, envVarName] of Object.entries(envExport)) {
|
|
819
|
-
const output = outputs.find(({ OutputKey }) => {
|
|
820
|
-
return OutputKey === cfOutputKey;
|
|
821
|
-
});
|
|
822
|
-
if (!output?.OutputValue) {
|
|
823
|
-
log5.warn(logPrefix3, `envExport: CloudFormation output "${cfOutputKey}" not found or has no value. Skipping export of "${envVarName}".`);
|
|
824
|
-
continue;
|
|
825
|
-
}
|
|
826
|
-
const value = output.OutputValue;
|
|
827
|
-
if (githubEnvFile) {
|
|
828
|
-
if (value.includes("\n")) {
|
|
829
|
-
log5.warn(logPrefix3, `envExport: value for "${cfOutputKey}" contains newlines and cannot be exported to GITHUB_ENV safely. Skipping.`);
|
|
830
|
-
continue;
|
|
831
|
-
}
|
|
832
|
-
await fs3.promises.appendFile(githubEnvFile, `${envVarName}=${value}
|
|
833
|
-
`);
|
|
834
|
-
log5.info(logPrefix3, `envExport: wrote ${envVarName} to GITHUB_ENV`);
|
|
835
|
-
} else {
|
|
836
|
-
const escapedValue = value.replace(/'/g, `'\\''`);
|
|
837
|
-
process.stdout.write(`export ${envVarName}='${escapedValue}'
|
|
838
|
-
`);
|
|
839
|
-
log5.info(logPrefix3, `envExport: printed export ${envVarName} to stdout`);
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
}, "exportEnvVars");
|
|
843
|
-
var printStackOutputsAfterDeploy = /* @__PURE__ */ __name(async ({ stackName, envExport }) => {
|
|
816
|
+
var printStackOutputsAfterDeploy = /* @__PURE__ */ __name(async ({ stackName }) => {
|
|
844
817
|
const { EnableTerminationProtection, StackName, Outputs = [] } = await describeStack({
|
|
845
818
|
stackName
|
|
846
819
|
});
|
|
@@ -861,12 +834,6 @@ var printStackOutputsAfterDeploy = /* @__PURE__ */ __name(async ({ stackName, en
|
|
|
861
834
|
""
|
|
862
835
|
].join("\n"));
|
|
863
836
|
}
|
|
864
|
-
if (envExport && Object.keys(envExport).length > 0) {
|
|
865
|
-
await exportEnvVars({
|
|
866
|
-
outputs: Outputs,
|
|
867
|
-
envExport
|
|
868
|
-
});
|
|
869
|
-
}
|
|
870
837
|
}, "printStackOutputsAfterDeploy");
|
|
871
838
|
var deleteStack = /* @__PURE__ */ __name(async ({ stackName }) => {
|
|
872
839
|
log5.info(logPrefix3, `Deleting stack ${stackName}...`);
|
|
@@ -939,7 +906,7 @@ var enableTerminationProtection = /* @__PURE__ */ __name(async ({ stackName }) =
|
|
|
939
906
|
throw error;
|
|
940
907
|
}
|
|
941
908
|
}, "enableTerminationProtection");
|
|
942
|
-
var deploy = /* @__PURE__ */ __name(async ({ terminationProtection = false,
|
|
909
|
+
var deploy = /* @__PURE__ */ __name(async ({ terminationProtection = false, ...paramsAndTemplate }) => {
|
|
943
910
|
const { params, template } = await addDefaults(paramsAndTemplate);
|
|
944
911
|
const stackName = params.StackName;
|
|
945
912
|
if (!stackName) {
|
|
@@ -978,8 +945,7 @@ var deploy = /* @__PURE__ */ __name(async ({ terminationProtection = false, envE
|
|
|
978
945
|
});
|
|
979
946
|
}
|
|
980
947
|
await printStackOutputsAfterDeploy({
|
|
981
|
-
stackName
|
|
982
|
-
envExport
|
|
948
|
+
stackName
|
|
983
949
|
});
|
|
984
950
|
return describeStack({
|
|
985
951
|
stackName
|
|
@@ -3492,7 +3458,7 @@ var getCloudformationTemplateOptions = /* @__PURE__ */ __name(({ cliOptions, sta
|
|
|
3492
3458
|
}, "getCloudformationTemplateOptions");
|
|
3493
3459
|
var deployCloudFormation = /* @__PURE__ */ __name(async (cliOptions) => {
|
|
3494
3460
|
try {
|
|
3495
|
-
const { lambdaDockerfile, lambdaEntryPoints, lambdaEntryPointsBaseDir, lambdaImage, lambdaExternal, lambdaFormat, lambdaOutdir, parameters, template, templatePath
|
|
3461
|
+
const { lambdaDockerfile, lambdaEntryPoints, lambdaEntryPointsBaseDir, lambdaImage, lambdaExternal, lambdaFormat, lambdaOutdir, parameters, template, templatePath } = cliOptions;
|
|
3496
3462
|
const { stackName } = await handleDeployInitialization({
|
|
3497
3463
|
logPrefix: logPrefix12
|
|
3498
3464
|
});
|
|
@@ -3653,8 +3619,7 @@ var deployCloudFormation = /* @__PURE__ */ __name(async (cliOptions) => {
|
|
|
3653
3619
|
await deployCloudFormationDeployLambdaCode();
|
|
3654
3620
|
const output = await deploy({
|
|
3655
3621
|
params,
|
|
3656
|
-
template: cloudFormationTemplate
|
|
3657
|
-
envExport
|
|
3622
|
+
template: cloudFormationTemplate
|
|
3658
3623
|
});
|
|
3659
3624
|
return output;
|
|
3660
3625
|
} catch (error) {
|
|
@@ -5063,50 +5028,6 @@ var options6 = {
|
|
|
5063
5028
|
describe: "Set the stack name.",
|
|
5064
5029
|
type: "string"
|
|
5065
5030
|
},
|
|
5066
|
-
/**
|
|
5067
|
-
* Mapping of CloudFormation output keys to environment variable names.
|
|
5068
|
-
* After a successful deployment, carlin reads the stack outputs and exports
|
|
5069
|
-
* the mapped variables to the CI/CD runner environment:
|
|
5070
|
-
*
|
|
5071
|
-
* - **GitHub Actions**: appends `KEY=VALUE` lines to `$GITHUB_ENV`.
|
|
5072
|
-
* - **Generic shell**: prints `export KEY=VALUE` lines to stdout.
|
|
5073
|
-
*
|
|
5074
|
-
* Configure in your `carlin.ts`:
|
|
5075
|
-
*
|
|
5076
|
-
* ```ts
|
|
5077
|
-
* export default {
|
|
5078
|
-
* envExport: {
|
|
5079
|
-
* AppSyncApiGraphQLUrl: 'VITE_APPSYNC_GRAPHQL_ENDPOINT',
|
|
5080
|
-
* AppSyncApiArn: 'APPSYNC_API_ARN',
|
|
5081
|
-
* },
|
|
5082
|
-
* };
|
|
5083
|
-
* ```
|
|
5084
|
-
*
|
|
5085
|
-
* Can also be combined with per-environment config:
|
|
5086
|
-
*
|
|
5087
|
-
* ```ts
|
|
5088
|
-
* export default {
|
|
5089
|
-
* environments: {
|
|
5090
|
-
* Staging: {
|
|
5091
|
-
* envExport: {
|
|
5092
|
-
* AppSyncApiGraphQLUrl: 'VITE_APPSYNC_GRAPHQL_ENDPOINT',
|
|
5093
|
-
* },
|
|
5094
|
-
* },
|
|
5095
|
-
* },
|
|
5096
|
-
* };
|
|
5097
|
-
* ```
|
|
5098
|
-
*/
|
|
5099
|
-
"env-export": {
|
|
5100
|
-
describe: "Mapping of CloudFormation output keys to environment variable names to export after deployment.",
|
|
5101
|
-
coerce: /* @__PURE__ */ __name((arg) => {
|
|
5102
|
-
if (typeof arg === "object" && arg !== null && !Array.isArray(arg) && Object.values(arg).every((v) => {
|
|
5103
|
-
return typeof v === "string";
|
|
5104
|
-
})) {
|
|
5105
|
-
return arg;
|
|
5106
|
-
}
|
|
5107
|
-
return void 0;
|
|
5108
|
-
}, "coerce")
|
|
5109
|
-
},
|
|
5110
5031
|
"template-path": {
|
|
5111
5032
|
alias: "t",
|
|
5112
5033
|
describe: "Path to the CloudFormation template.",
|
|
@@ -5257,7 +5178,34 @@ var readEnvFile = /* @__PURE__ */ __name(async ({ envFileName, envsPath }) => {
|
|
|
5257
5178
|
var writeEnvFile = /* @__PURE__ */ __name(async ({ envFileName, content }) => {
|
|
5258
5179
|
return fs3.promises.writeFile(path.resolve(process.cwd(), envFileName), content);
|
|
5259
5180
|
}, "writeEnvFile");
|
|
5260
|
-
var
|
|
5181
|
+
var readDeployOutputLines = /* @__PURE__ */ __name(async ({ envFromDeployOutputs }) => {
|
|
5182
|
+
const lines = [];
|
|
5183
|
+
for (const { dir, variables } of envFromDeployOutputs) {
|
|
5184
|
+
const latestDeployPath = path.resolve(process.cwd(), dir, ".carlin", LATEST_DEPLOY_OUTPUTS_FILENAME);
|
|
5185
|
+
let latestDeploy;
|
|
5186
|
+
try {
|
|
5187
|
+
const raw = await fs3.promises.readFile(latestDeployPath, "utf8");
|
|
5188
|
+
latestDeploy = JSON.parse(raw);
|
|
5189
|
+
} catch {
|
|
5190
|
+
log5.warn(logPrefix23, "Could not read latest-deploy.json from %s. Skipping.", latestDeployPath);
|
|
5191
|
+
continue;
|
|
5192
|
+
}
|
|
5193
|
+
const outputs = latestDeploy.outputs ?? {};
|
|
5194
|
+
for (const [envVarName, outputPath] of Object.entries(variables)) {
|
|
5195
|
+
const dotIndex = outputPath.indexOf(".");
|
|
5196
|
+
const outputKey = dotIndex === -1 ? outputPath : outputPath.slice(0, dotIndex);
|
|
5197
|
+
const field = dotIndex === -1 ? "OutputValue" : outputPath.slice(dotIndex + 1);
|
|
5198
|
+
const outputValue = outputs[outputKey]?.[field];
|
|
5199
|
+
if (outputValue === void 0) {
|
|
5200
|
+
log5.warn(logPrefix23, 'Output path "%s" not found in %s. Skipping %s.', outputPath, latestDeployPath, envVarName);
|
|
5201
|
+
continue;
|
|
5202
|
+
}
|
|
5203
|
+
lines.push(`${envVarName}=${outputValue}`);
|
|
5204
|
+
}
|
|
5205
|
+
}
|
|
5206
|
+
return lines;
|
|
5207
|
+
}, "readDeployOutputLines");
|
|
5208
|
+
var generateEnv = /* @__PURE__ */ __name(async ({ defaultEnvironment, envFromDeployOutputs, path: envsPath }) => {
|
|
5261
5209
|
const environment = getEnvironment() || defaultEnvironment;
|
|
5262
5210
|
const envFileName = `.env.${environment}`;
|
|
5263
5211
|
const envFile = await readEnvFile({
|
|
@@ -5268,8 +5216,14 @@ var generateEnv = /* @__PURE__ */ __name(async ({ defaultEnvironment, path: envs
|
|
|
5268
5216
|
log5.info(logPrefix23, "Env file %s doesn't exist. Skip generating env file.", envFileName);
|
|
5269
5217
|
return;
|
|
5270
5218
|
}
|
|
5219
|
+
const deployOutputLines = envFromDeployOutputs && envFromDeployOutputs.length > 0 ? await readDeployOutputLines({
|
|
5220
|
+
envFromDeployOutputs
|
|
5221
|
+
}) : [];
|
|
5222
|
+
const content = deployOutputLines.length > 0 ? `${envFile}
|
|
5223
|
+
${deployOutputLines.join("\n")}
|
|
5224
|
+
` : envFile;
|
|
5271
5225
|
await writeEnvFile({
|
|
5272
|
-
content
|
|
5226
|
+
content,
|
|
5273
5227
|
envFileName: ".env"
|
|
5274
5228
|
});
|
|
5275
5229
|
log5.info(logPrefix23, "Generate env file %s from %s successfully.", ".env", envFileName);
|