carlin 1.31.5 → 1.31.6
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.
|
@@ -32,12 +32,9 @@ const path = __importStar(require("path"));
|
|
|
32
32
|
const utils_1 = require("../utils");
|
|
33
33
|
const npmlog_1 = __importDefault(require("npmlog"));
|
|
34
34
|
const logPrefix = 'generate-env';
|
|
35
|
-
const
|
|
36
|
-
return path.resolve(process.cwd(), envFileName);
|
|
37
|
-
};
|
|
38
|
-
const readEnvFile = async ({ envFileName }) => {
|
|
35
|
+
const readEnvFile = async ({ envFileName, envsPath, }) => {
|
|
39
36
|
try {
|
|
40
|
-
const content = await fs.promises.readFile(
|
|
37
|
+
const content = await fs.promises.readFile(path.resolve(process.cwd(), envsPath, envFileName), 'utf8');
|
|
41
38
|
return content;
|
|
42
39
|
}
|
|
43
40
|
catch {
|
|
@@ -45,32 +42,23 @@ const readEnvFile = async ({ envFileName }) => {
|
|
|
45
42
|
}
|
|
46
43
|
};
|
|
47
44
|
const writeEnvFile = async ({ envFileName, content, }) => {
|
|
48
|
-
return fs.promises.writeFile(
|
|
45
|
+
return fs.promises.writeFile(path.resolve(process.cwd(), envFileName), content);
|
|
49
46
|
};
|
|
50
47
|
/**
|
|
51
48
|
* Generate environment for packages using `carlin`. If [environment](/docs/CLI#environment)
|
|
52
|
-
* isn't defined, `carlin` will read `.env` file if exists
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* We chose the name `.env.local` because it works for [Next.js](https://nextjs.org/docs/basic-features/environment-variables)
|
|
57
|
-
* and [CRA](https://create-react-app.dev/docs/adding-custom-environment-variables/#what-other-env-files-can-be-used) projects.
|
|
49
|
+
* isn't defined, `carlin` will read `.env.Staging` file if exists and write
|
|
50
|
+
* `.env` file. If it's `Environment`, it'll read `.env.Environment` file instead.
|
|
51
|
+
* For example, if `environment` is `Production`, `carlin` will read `.env.Production`
|
|
58
52
|
*/
|
|
59
|
-
const generateEnv = async () => {
|
|
60
|
-
const environment = (0, utils_1.getEnvironment)();
|
|
61
|
-
const envFileName =
|
|
62
|
-
|
|
53
|
+
const generateEnv = async ({ defaultEnvironment, path: envsPath, }) => {
|
|
54
|
+
const environment = (0, utils_1.getEnvironment)() || defaultEnvironment;
|
|
55
|
+
const envFileName = `.env.${environment}`;
|
|
56
|
+
const envFile = await readEnvFile({ envFileName, envsPath });
|
|
63
57
|
if (!envFile) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
envFile = await readEnvFile({ envFileName: '.env' });
|
|
68
|
-
if (!envFile) {
|
|
69
|
-
npmlog_1.default.info(logPrefix, "Env file %s doesn't exist.", '.env');
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
58
|
+
npmlog_1.default.info(logPrefix, "Env file %s doesn't exist. Skip generating env file.", envFileName);
|
|
59
|
+
return;
|
|
72
60
|
}
|
|
73
|
-
await writeEnvFile({ content: envFile, envFileName: '.env
|
|
74
|
-
npmlog_1.default.info(logPrefix, 'Generate env file %s from %s successfully.', '.env
|
|
61
|
+
await writeEnvFile({ content: envFile, envFileName: '.env' });
|
|
62
|
+
npmlog_1.default.info(logPrefix, 'Generate env file %s from %s successfully.', '.env', envFileName);
|
|
75
63
|
};
|
|
76
64
|
exports.generateEnv = generateEnv;
|
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateEnvCommand = void 0;
|
|
3
|
+
exports.generateEnvCommand = exports.options = exports.DEFAULT_ENVIRONMENT = void 0;
|
|
4
4
|
const generateEnv_1 = require("./generateEnv");
|
|
5
|
+
exports.DEFAULT_ENVIRONMENT = 'Staging';
|
|
6
|
+
exports.options = {
|
|
7
|
+
'default-environment': {
|
|
8
|
+
alias: 'd',
|
|
9
|
+
type: 'string',
|
|
10
|
+
describe: 'Default environment.',
|
|
11
|
+
default: exports.DEFAULT_ENVIRONMENT,
|
|
12
|
+
},
|
|
13
|
+
path: {
|
|
14
|
+
alias: 'p',
|
|
15
|
+
type: 'string',
|
|
16
|
+
describe: 'Path to the directory where envs files are located.',
|
|
17
|
+
default: './',
|
|
18
|
+
},
|
|
19
|
+
};
|
|
5
20
|
exports.generateEnvCommand = {
|
|
6
21
|
command: ['generate-env', 'ge', 'env'],
|
|
7
22
|
describe: 'Generate environment files.',
|
|
8
|
-
|
|
23
|
+
builder: (yargs) => {
|
|
24
|
+
return yargs.options(exports.options);
|
|
25
|
+
},
|
|
26
|
+
handler: (args) => {
|
|
27
|
+
return (0, generateEnv_1.generateEnv)(args);
|
|
28
|
+
},
|
|
9
29
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carlin",
|
|
3
|
-
"version": "1.31.
|
|
3
|
+
"version": "1.31.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"author": "Pedro Arantes <arantespp@gmail.com> (https://twitter.com/arantespp)",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"uglify-js": "^3.17.4",
|
|
46
46
|
"vercel": "^32.5.6",
|
|
47
47
|
"yargs": "^17.7.2",
|
|
48
|
-
"@ttoss/cloudformation": "^0.8.
|
|
48
|
+
"@ttoss/cloudformation": "^0.8.6"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/adm-zip": "^0.5.5",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@types/yargs": "^17.0.32",
|
|
64
64
|
"jest": "^29.7.0",
|
|
65
65
|
"typescript": "~5.2.2",
|
|
66
|
-
"@ttoss/test-utils": "^2.0.
|
|
66
|
+
"@ttoss/test-utils": "^2.0.3"
|
|
67
67
|
},
|
|
68
68
|
"keywords": [],
|
|
69
69
|
"publishConfig": {
|