carlin 1.49.10 → 1.49.12
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 +71 -50
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { __name, __require } from './chunk-3GQAWCBQ.js';
|
|
2
|
-
import 'dotenv/config';
|
|
3
2
|
import * as path2 from 'path';
|
|
4
3
|
import path2__default from 'path';
|
|
5
|
-
import * as
|
|
6
|
-
import
|
|
4
|
+
import * as fs5 from 'fs';
|
|
5
|
+
import fs5__default, { existsSync, statSync, chmodSync, createReadStream } from 'fs';
|
|
7
6
|
import yaml5 from 'js-yaml';
|
|
7
|
+
import { createRequire, builtinModules } from 'module';
|
|
8
8
|
import * as esbuild from 'esbuild';
|
|
9
|
-
import importSync from 'import-sync';
|
|
10
9
|
import AWS2 from 'aws-sdk';
|
|
11
10
|
import { pascalCase, constantCase, kebabCase, camelCase } from 'change-case';
|
|
12
11
|
import deepEqual from 'deep-equal';
|
|
13
12
|
import deepmerge from 'deepmerge';
|
|
13
|
+
import dotenv from 'dotenv';
|
|
14
14
|
import findUpSync from 'findup-sync';
|
|
15
15
|
import yargs from 'yargs';
|
|
16
16
|
import { hideBin } from 'yargs/helpers';
|
|
@@ -25,14 +25,18 @@ import { ListObjectsV2Command, ListObjectVersionsCommand, DeleteObjectsCommand,
|
|
|
25
25
|
import { Upload } from '@aws-sdk/lib-storage';
|
|
26
26
|
import { glob } from 'glob';
|
|
27
27
|
import mime from 'mime-types';
|
|
28
|
-
import { builtinModules } from 'module';
|
|
29
28
|
import { typescriptConfig } from '@ttoss/config';
|
|
30
29
|
import AdmZip from 'adm-zip';
|
|
31
30
|
|
|
31
|
+
var nodeRequire = createRequire(import.meta.url);
|
|
32
32
|
var loadConfig = /* @__PURE__ */ __name((entryPoint) => {
|
|
33
33
|
const lastEntryPointName = entryPoint.split("/").pop();
|
|
34
34
|
const filename = lastEntryPointName?.split(".")[0];
|
|
35
|
-
const
|
|
35
|
+
const entryFileStats = fs5__default.statSync(entryPoint, {
|
|
36
|
+
bigint: true
|
|
37
|
+
});
|
|
38
|
+
const entryFileVersion = `${entryFileStats.mtimeNs}-${entryFileStats.size}`;
|
|
39
|
+
const outfile = path2__default.resolve(process.cwd(), "out", `${filename}-${entryFileVersion}.cjs`);
|
|
36
40
|
const result = esbuild.buildSync({
|
|
37
41
|
bundle: true,
|
|
38
42
|
entryPoints: [
|
|
@@ -55,7 +59,9 @@ var loadConfig = /* @__PURE__ */ __name((entryPoint) => {
|
|
|
55
59
|
throw result.errors;
|
|
56
60
|
}
|
|
57
61
|
try {
|
|
58
|
-
const
|
|
62
|
+
const resolvedOutfile = nodeRequire.resolve(outfile);
|
|
63
|
+
delete nodeRequire.cache[resolvedOutfile];
|
|
64
|
+
const config = nodeRequire(resolvedOutfile);
|
|
59
65
|
return config.default || config.config;
|
|
60
66
|
} catch (error) {
|
|
61
67
|
console.error("Failed importing build config file: ", filename);
|
|
@@ -67,11 +73,11 @@ var loadConfig = /* @__PURE__ */ __name((entryPoint) => {
|
|
|
67
73
|
var readConfigFileSync = /* @__PURE__ */ __name(({ configFilePath, options: options10 }) => {
|
|
68
74
|
const extension = configFilePath.split(".").pop();
|
|
69
75
|
if (extension === "yaml" || extension === "yml") {
|
|
70
|
-
const file =
|
|
76
|
+
const file = fs5__default.readFileSync(configFilePath, "utf8");
|
|
71
77
|
return yaml5.load(file);
|
|
72
78
|
}
|
|
73
79
|
if (extension === "json") {
|
|
74
|
-
const file =
|
|
80
|
+
const file = fs5__default.readFileSync(configFilePath, "utf8");
|
|
75
81
|
return JSON.parse(file);
|
|
76
82
|
}
|
|
77
83
|
if (extension === "js") {
|
|
@@ -248,7 +254,7 @@ var readPackageJson = /* @__PURE__ */ __name(() => {
|
|
|
248
254
|
if (!packageJsonDir) {
|
|
249
255
|
return {};
|
|
250
256
|
}
|
|
251
|
-
return JSON.parse(
|
|
257
|
+
return JSON.parse(fs5__default.readFileSync(packageJsonDir).toString());
|
|
252
258
|
}, "readPackageJson");
|
|
253
259
|
var getPackageJsonProperty = /* @__PURE__ */ __name(({ property }) => {
|
|
254
260
|
try {
|
|
@@ -579,7 +585,7 @@ var uploadFileToS3 = /* @__PURE__ */ __name(async ({ bucket, contentType, file,
|
|
|
579
585
|
params.ContentType = contentType;
|
|
580
586
|
params.Body = file;
|
|
581
587
|
} else if (filePath) {
|
|
582
|
-
const readFile = await
|
|
588
|
+
const readFile = await fs5__default.promises.readFile(filePath);
|
|
583
589
|
params.ContentType = contentType || mime.contentType(path2__default.extname(filePath)) || void 0;
|
|
584
590
|
params.Body = Buffer.from(readFile);
|
|
585
591
|
}
|
|
@@ -601,7 +607,7 @@ var uploadFileToS3 = /* @__PURE__ */ __name(async ({ bucket, contentType, file,
|
|
|
601
607
|
var getAllFilesInsideADirectory = /* @__PURE__ */ __name(async ({ directory }) => {
|
|
602
608
|
const allFilesAndDirectories = await glob(`${directory}/**/*`);
|
|
603
609
|
const allFiles = allFilesAndDirectories.filter((item) => {
|
|
604
|
-
return
|
|
610
|
+
return fs5__default.lstatSync(item).isFile();
|
|
605
611
|
});
|
|
606
612
|
return allFiles;
|
|
607
613
|
}, "getAllFilesInsideADirectory");
|
|
@@ -913,13 +919,13 @@ var saveEnvironmentOutput = /* @__PURE__ */ __name(async ({ outputs, stackName }
|
|
|
913
919
|
};
|
|
914
920
|
}, {});
|
|
915
921
|
const dotCarlinFolderPath = path2.join(process.cwd(), ".carlin");
|
|
916
|
-
if (!
|
|
917
|
-
await
|
|
922
|
+
if (!fs5.existsSync(dotCarlinFolderPath)) {
|
|
923
|
+
await fs5.promises.mkdir(dotCarlinFolderPath);
|
|
918
924
|
}
|
|
919
925
|
const filePath = path2.join(dotCarlinFolderPath, `${stackName}.json`);
|
|
920
|
-
await
|
|
926
|
+
await fs5.promises.writeFile(filePath, JSON.stringify(envFile, null, 2));
|
|
921
927
|
const latestFilePath = path2.join(dotCarlinFolderPath, LATEST_DEPLOY_OUTPUTS_FILENAME);
|
|
922
|
-
await
|
|
928
|
+
await fs5.promises.writeFile(latestFilePath, JSON.stringify(envFile, null, 2));
|
|
923
929
|
}, "saveEnvironmentOutput");
|
|
924
930
|
var printStackOutputsAfterDeploy = /* @__PURE__ */ __name(async ({ stackName }) => {
|
|
925
931
|
const { EnableTerminationProtection, StackName, Outputs = [] } = await describeStack({
|
|
@@ -2856,8 +2862,8 @@ var getCicdTemplate = /* @__PURE__ */ __name(({ pipelines: pipelines2 = [], cpu
|
|
|
2856
2862
|
var logPrefix6 = "lambda";
|
|
2857
2863
|
var buildLambdaCode = /* @__PURE__ */ __name(async ({ lambdaEntryPoints, lambdaEntryPointsBaseDir = ".", lambdaExternal = [], lambdaFormat = "esm", lambdaOutdir }) => {
|
|
2858
2864
|
log6.info(logPrefix6, "Building Lambda single file...");
|
|
2859
|
-
if (
|
|
2860
|
-
|
|
2865
|
+
if (fs5__default.existsSync(lambdaOutdir)) {
|
|
2866
|
+
fs5__default.rmSync(lambdaOutdir, {
|
|
2861
2867
|
recursive: true
|
|
2862
2868
|
});
|
|
2863
2869
|
}
|
|
@@ -3053,7 +3059,7 @@ var deployLambdaLayers = /* @__PURE__ */ __name(async ({ lambdaExternal = [] })
|
|
|
3053
3059
|
log6.info(logPrefix8, `--lambda-externals [${lambdaExternal.join(", ")}] was found. Creating other layers...`);
|
|
3054
3060
|
const { dependencies = {} } = (() => {
|
|
3055
3061
|
try {
|
|
3056
|
-
return JSON.parse(
|
|
3062
|
+
return JSON.parse(fs5.readFileSync(path2.resolve(process.cwd(), "package.json"), "utf8"));
|
|
3057
3063
|
} catch (err) {
|
|
3058
3064
|
log6.error(logPrefix8, "Cannot read package.json. Error message: %j", err.message);
|
|
3059
3065
|
return {};
|
|
@@ -3086,8 +3092,8 @@ var uploadCodeToS3 = /* @__PURE__ */ __name(async ({ stackName, lambdaOutdir })
|
|
|
3086
3092
|
log6.info(logPrefix9, `Uploading code to S3...`);
|
|
3087
3093
|
const zip = new AdmZip();
|
|
3088
3094
|
const zipFile = `${lambdaOutdir}/${zipFileName}`;
|
|
3089
|
-
if (
|
|
3090
|
-
await
|
|
3095
|
+
if (fs5__default.existsSync(zipFile)) {
|
|
3096
|
+
await fs5__default.promises.rm(zipFile);
|
|
3091
3097
|
}
|
|
3092
3098
|
zip.addLocalFolder(lambdaOutdir);
|
|
3093
3099
|
zip.writeZip(`${lambdaOutdir}/${zipFileName}`);
|
|
@@ -3109,7 +3115,7 @@ var deployLambdaCode = /* @__PURE__ */ __name(async ({ lambdaDockerfile, lambdaE
|
|
|
3109
3115
|
log6.info(logPrefix10, "Deploying Lambda code...");
|
|
3110
3116
|
for (const entryPoint of lambdaEntryPoints) {
|
|
3111
3117
|
const entryPointPath = path2__default.resolve(lambdaEntryPointsBaseDir, entryPoint);
|
|
3112
|
-
if (!
|
|
3118
|
+
if (!fs5__default.existsSync(entryPointPath)) {
|
|
3113
3119
|
throw new Error(`Entry point ${entryPointPath} does not exist.`);
|
|
3114
3120
|
}
|
|
3115
3121
|
}
|
|
@@ -3159,10 +3165,10 @@ var getLambdaInput = /* @__PURE__ */ __name((extension) => {
|
|
|
3159
3165
|
}, "getLambdaInput");
|
|
3160
3166
|
var deployCicdLambdas = /* @__PURE__ */ __name(async ({ stackName }) => {
|
|
3161
3167
|
const lambdaInput = (() => {
|
|
3162
|
-
if (
|
|
3168
|
+
if (fs5.existsSync(getLambdaInput("js"))) {
|
|
3163
3169
|
return getLambdaInput("js");
|
|
3164
3170
|
}
|
|
3165
|
-
if (
|
|
3171
|
+
if (fs5.existsSync(getLambdaInput("ts"))) {
|
|
3166
3172
|
return getLambdaInput("ts");
|
|
3167
3173
|
}
|
|
3168
3174
|
throw new Error("Cannot read CICD lambdas file.");
|
|
@@ -3246,7 +3252,7 @@ var deployCicd = /* @__PURE__ */ __name(async ({ cpu, memory, pipelines: pipelin
|
|
|
3246
3252
|
}
|
|
3247
3253
|
}, "deployCicd");
|
|
3248
3254
|
var readSSHKey = /* @__PURE__ */ __name((dir) => {
|
|
3249
|
-
return
|
|
3255
|
+
return fs5.readFileSync(dir, "utf-8");
|
|
3250
3256
|
}, "readSSHKey");
|
|
3251
3257
|
var logPrefix12 = "deploy-cicd";
|
|
3252
3258
|
var deployCicdCommand = {
|
|
@@ -3414,14 +3420,14 @@ var getTypes = /* @__PURE__ */ __name(() => {
|
|
|
3414
3420
|
options: {
|
|
3415
3421
|
kind: "scalar",
|
|
3416
3422
|
construct: /* @__PURE__ */ __name((filePath) => {
|
|
3417
|
-
return
|
|
3423
|
+
return fs5.readFileSync(path2.resolve(process.cwd(), filePath)).toString();
|
|
3418
3424
|
}, "construct")
|
|
3419
3425
|
}
|
|
3420
3426
|
}
|
|
3421
3427
|
];
|
|
3422
3428
|
}, "getTypes");
|
|
3423
3429
|
var readCloudFormationYamlTemplate = /* @__PURE__ */ __name(({ templatePath }) => {
|
|
3424
|
-
const template =
|
|
3430
|
+
const template = fs5.readFileSync(templatePath).toString();
|
|
3425
3431
|
const parsed = loadCloudFormationTemplate(template, getTypes());
|
|
3426
3432
|
if (!parsed || typeof parsed === "string") {
|
|
3427
3433
|
throw new Error("Cannot parse CloudFormation template.");
|
|
@@ -3444,7 +3450,7 @@ var findAndReadCloudFormationTemplate = /* @__PURE__ */ __name(async ({ template
|
|
|
3444
3450
|
if (acc) {
|
|
3445
3451
|
return acc;
|
|
3446
3452
|
}
|
|
3447
|
-
return
|
|
3453
|
+
return fs5.existsSync(path2.resolve(process.cwd(), cur)) ? cur : acc;
|
|
3448
3454
|
}, "");
|
|
3449
3455
|
if (!templatePath) {
|
|
3450
3456
|
throw new Error("Cannot find a CloudFormation template.");
|
|
@@ -3781,7 +3787,7 @@ var deployLambdaLayerCommand = {
|
|
|
3781
3787
|
};
|
|
3782
3788
|
var readDockerfile = /* @__PURE__ */ __name((dockerfilePath) => {
|
|
3783
3789
|
try {
|
|
3784
|
-
return
|
|
3790
|
+
return fs5.readFileSync(path2.join(process.cwd(), dockerfilePath), "utf8");
|
|
3785
3791
|
} catch {
|
|
3786
3792
|
return "";
|
|
3787
3793
|
}
|
|
@@ -3809,7 +3815,7 @@ var readAllDeployFiles = /* @__PURE__ */ __name(async () => {
|
|
|
3809
3815
|
const results = [];
|
|
3810
3816
|
for (const file of files) {
|
|
3811
3817
|
try {
|
|
3812
|
-
const raw = await
|
|
3818
|
+
const raw = await fs5.promises.readFile(file, "utf-8");
|
|
3813
3819
|
const content = JSON.parse(raw);
|
|
3814
3820
|
if (content.stackName && content.outputs) {
|
|
3815
3821
|
results.push(content);
|
|
@@ -5176,14 +5182,14 @@ var deployCommand = {
|
|
|
5176
5182
|
var logPrefix23 = "generate-env";
|
|
5177
5183
|
var readEnvFile = /* @__PURE__ */ __name(async ({ envFileName, envsPath }) => {
|
|
5178
5184
|
try {
|
|
5179
|
-
const content = await
|
|
5185
|
+
const content = await fs5.promises.readFile(path2.resolve(process.cwd(), envsPath, envFileName), "utf8");
|
|
5180
5186
|
return content;
|
|
5181
5187
|
} catch {
|
|
5182
5188
|
return void 0;
|
|
5183
5189
|
}
|
|
5184
5190
|
}, "readEnvFile");
|
|
5185
5191
|
var writeEnvFile = /* @__PURE__ */ __name(async ({ envFileName, content }) => {
|
|
5186
|
-
return
|
|
5192
|
+
return fs5.promises.writeFile(path2.resolve(process.cwd(), envFileName), content);
|
|
5187
5193
|
}, "writeEnvFile");
|
|
5188
5194
|
var readDeployOutputLines = /* @__PURE__ */ __name(async ({ envFromDeployOutputs }) => {
|
|
5189
5195
|
const lines = [];
|
|
@@ -5191,7 +5197,7 @@ var readDeployOutputLines = /* @__PURE__ */ __name(async ({ envFromDeployOutputs
|
|
|
5191
5197
|
const latestDeployPath = path2.resolve(process.cwd(), dir, ".carlin", LATEST_DEPLOY_OUTPUTS_FILENAME);
|
|
5192
5198
|
let latestDeploy;
|
|
5193
5199
|
try {
|
|
5194
|
-
const raw = await
|
|
5200
|
+
const raw = await fs5.promises.readFile(latestDeployPath, "utf8");
|
|
5195
5201
|
latestDeploy = JSON.parse(raw);
|
|
5196
5202
|
} catch {
|
|
5197
5203
|
log6.warn(logPrefix23, "Could not read latest-deploy.json from %s. Skipping.", latestDeployPath);
|
|
@@ -5408,7 +5414,38 @@ var readConfigFiles = /* @__PURE__ */ __name(() => {
|
|
|
5408
5414
|
});
|
|
5409
5415
|
return deepmerge.all(configs.reverse());
|
|
5410
5416
|
}, "readConfigFiles");
|
|
5417
|
+
var loadDotEnv = /* @__PURE__ */ __name(() => {
|
|
5418
|
+
const { environment } = getConfigFileOptions();
|
|
5419
|
+
if (environment) {
|
|
5420
|
+
const result = dotenv.config({
|
|
5421
|
+
path: path2__default.resolve(process.cwd(), `.env.${environment}`)
|
|
5422
|
+
});
|
|
5423
|
+
if (result.error) {
|
|
5424
|
+
dotenv.config();
|
|
5425
|
+
}
|
|
5426
|
+
} else {
|
|
5427
|
+
dotenv.config();
|
|
5428
|
+
}
|
|
5429
|
+
}, "loadDotEnv");
|
|
5430
|
+
var syncEnvironmentOption = /* @__PURE__ */ __name((argv) => {
|
|
5431
|
+
const finalEnvironment = argv.environment || process.env.ENVIRONMENT;
|
|
5432
|
+
if (finalEnvironment) {
|
|
5433
|
+
setEnvVar("ENVIRONMENT", finalEnvironment);
|
|
5434
|
+
const envKeys = [
|
|
5435
|
+
"environment",
|
|
5436
|
+
...options9.environment.alias
|
|
5437
|
+
];
|
|
5438
|
+
const envEntries = envKeys.map((key) => {
|
|
5439
|
+
return [
|
|
5440
|
+
key,
|
|
5441
|
+
finalEnvironment
|
|
5442
|
+
];
|
|
5443
|
+
});
|
|
5444
|
+
Object.assign(argv, Object.fromEntries(envEntries));
|
|
5445
|
+
}
|
|
5446
|
+
}, "syncEnvironmentOption");
|
|
5411
5447
|
var cli = /* @__PURE__ */ __name(() => {
|
|
5448
|
+
loadDotEnv();
|
|
5412
5449
|
let finalConfig;
|
|
5413
5450
|
const getConfig = /* @__PURE__ */ __name(() => {
|
|
5414
5451
|
return finalConfig = readConfigFiles();
|
|
@@ -5433,23 +5470,7 @@ var cli = /* @__PURE__ */ __name(() => {
|
|
|
5433
5470
|
}
|
|
5434
5471
|
}
|
|
5435
5472
|
}, "handleEnvironments");
|
|
5436
|
-
return yargs(hideBin(process.argv)).strictCommands().scriptName(NAME).env(getEnv()).options(addGroupToOptions(options9, "Common Options")).middleware((
|
|
5437
|
-
const finalEnvironment = argv.environment || process.env.ENVIRONMENT;
|
|
5438
|
-
if (finalEnvironment) {
|
|
5439
|
-
setEnvVar("ENVIRONMENT", finalEnvironment);
|
|
5440
|
-
const envKeys = [
|
|
5441
|
-
"environment",
|
|
5442
|
-
...options9.environment.alias
|
|
5443
|
-
];
|
|
5444
|
-
const envEntries = envKeys.map((key) => {
|
|
5445
|
-
return [
|
|
5446
|
-
key,
|
|
5447
|
-
finalEnvironment
|
|
5448
|
-
];
|
|
5449
|
-
});
|
|
5450
|
-
Object.assign(argv, Object.fromEntries(envEntries));
|
|
5451
|
-
}
|
|
5452
|
-
}).middleware(handleEnvironments).middleware(({ environment }) => {
|
|
5473
|
+
return yargs(hideBin(process.argv)).strictCommands().scriptName(NAME).env(getEnv()).options(addGroupToOptions(options9, "Common Options")).middleware(syncEnvironmentOption).middleware(handleEnvironments).middleware(({ environment }) => {
|
|
5453
5474
|
if (![
|
|
5454
5475
|
"string",
|
|
5455
5476
|
"undefined"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carlin",
|
|
3
|
-
"version": "1.49.
|
|
3
|
+
"version": "1.49.12",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://ttoss.dev/docs/carlin/",
|
|
@@ -58,9 +58,9 @@
|
|
|
58
58
|
"uglify-js": "^3.19.3",
|
|
59
59
|
"vercel": "^39.1.1",
|
|
60
60
|
"yargs": "^17.7.2",
|
|
61
|
-
"@ttoss/
|
|
62
|
-
"@ttoss/
|
|
63
|
-
"@ttoss/
|
|
61
|
+
"@ttoss/cloudformation": "^0.13.2",
|
|
62
|
+
"@ttoss/read-config-file": "^2.2.12",
|
|
63
|
+
"@ttoss/config": "^1.37.11"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@types/adm-zip": "^0.5.6",
|