@achs/env 4.0.1 → 4.1.2
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/arguments.d.ts +25 -25
- package/arguments.js +125 -125
- package/commands/env.command.d.ts +7 -7
- package/commands/env.command.js +78 -78
- package/commands/export.command.d.ts +7 -7
- package/commands/export.command.js +53 -53
- package/commands/index.d.ts +5 -5
- package/commands/index.js +13 -13
- package/commands/pull.command.d.ts +6 -6
- package/commands/pull.command.js +38 -38
- package/commands/push.command.d.ts +6 -6
- package/commands/push.command.js +37 -37
- package/commands/schema.command.d.ts +3 -3
- package/commands/schema.command.js +18 -18
- package/exec.d.ts +2 -2
- package/exec.js +145 -146
- package/exec.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +19 -19
- package/interfaces/index.d.ts +1 -1
- package/interfaces/index.js +17 -17
- package/interfaces/loader.interface.d.ts +20 -20
- package/interfaces/loader.interface.js +2 -2
- package/main.d.ts +2 -2
- package/main.js +5 -5
- package/package.json +15 -15
- package/providers/app-settings.provider.d.ts +7 -7
- package/providers/app-settings.provider.d.ts.map +1 -1
- package/providers/app-settings.provider.js +51 -47
- package/providers/app-settings.provider.js.map +1 -1
- package/providers/azure-key-vault.provider.d.ts +19 -19
- package/providers/azure-key-vault.provider.js +148 -148
- package/providers/index.d.ts +6 -6
- package/providers/index.js +29 -29
- package/providers/local.provider.d.ts +7 -7
- package/providers/local.provider.js +41 -41
- package/providers/package-json.provider.d.ts +7 -7
- package/providers/package-json.provider.js +29 -29
- package/tsconfig.build.tsbuildinfo +1 -1
- package/utils/command.util.d.ts +12 -12
- package/utils/command.util.js +134 -135
- package/utils/command.util.js.map +1 -1
- package/utils/index.d.ts +6 -6
- package/utils/index.js +22 -22
- package/utils/interpolate.util.d.ts +3 -3
- package/utils/interpolate.util.js +32 -32
- package/utils/json.util.d.ts +4 -4
- package/utils/json.util.js +47 -47
- package/utils/logger.d.ts +2 -2
- package/utils/logger.js +17 -17
- package/utils/normalize.util.d.ts +2 -2
- package/utils/normalize.util.js +60 -60
- package/utils/schema.util.d.ts +10 -10
- package/utils/schema.util.js +99 -99
package/arguments.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { JSONSchemaType } from 'ajv';
|
|
2
|
-
import { Arguments, Options } from 'yargs';
|
|
3
|
-
import { EnvProviderConfig } from './interfaces';
|
|
4
|
-
export interface CommandArguments extends Arguments {
|
|
5
|
-
env: string;
|
|
6
|
-
modes?: string[];
|
|
7
|
-
projectInfo: Record<string, string>;
|
|
8
|
-
schema?: Record<string, JSONSchemaType<object>>;
|
|
9
|
-
providers: EnvProviderConfig[];
|
|
10
|
-
ci: boolean;
|
|
11
|
-
nestingDelimiter: string;
|
|
12
|
-
arrayDescomposition: boolean;
|
|
13
|
-
expand: boolean;
|
|
14
|
-
root: string;
|
|
15
|
-
configFile: string;
|
|
16
|
-
schemaFile: string;
|
|
17
|
-
packageJson: string;
|
|
18
|
-
resolve: 'merge' | 'override';
|
|
19
|
-
nullable: boolean;
|
|
20
|
-
detectFormat: boolean;
|
|
21
|
-
logLevel?: 'silly' | 'trace' | 'debug' | 'info' | 'warn' | 'error';
|
|
22
|
-
logMaskAnyRegEx?: string[];
|
|
23
|
-
logMaskValuesOfKeys?: string[];
|
|
24
|
-
}
|
|
25
|
-
export declare const args: Record<keyof CommandArguments, Options>;
|
|
1
|
+
import { JSONSchemaType } from 'ajv';
|
|
2
|
+
import { Arguments, Options } from 'yargs';
|
|
3
|
+
import { EnvProviderConfig } from './interfaces';
|
|
4
|
+
export interface CommandArguments extends Arguments {
|
|
5
|
+
env: string;
|
|
6
|
+
modes?: string[];
|
|
7
|
+
projectInfo: Record<string, string>;
|
|
8
|
+
schema?: Record<string, JSONSchemaType<object>>;
|
|
9
|
+
providers: EnvProviderConfig[];
|
|
10
|
+
ci: boolean;
|
|
11
|
+
nestingDelimiter: string;
|
|
12
|
+
arrayDescomposition: boolean;
|
|
13
|
+
expand: boolean;
|
|
14
|
+
root: string;
|
|
15
|
+
configFile: string;
|
|
16
|
+
schemaFile: string;
|
|
17
|
+
packageJson: string;
|
|
18
|
+
resolve: 'merge' | 'override';
|
|
19
|
+
nullable: boolean;
|
|
20
|
+
detectFormat: boolean;
|
|
21
|
+
logLevel?: 'silly' | 'trace' | 'debug' | 'info' | 'warn' | 'error';
|
|
22
|
+
logMaskAnyRegEx?: string[];
|
|
23
|
+
logMaskValuesOfKeys?: string[];
|
|
24
|
+
}
|
|
25
|
+
export declare const args: Record<keyof CommandArguments, Options>;
|
|
26
26
|
//# sourceMappingURL=arguments.d.ts.map
|
package/arguments.js
CHANGED
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.args = void 0;
|
|
7
|
-
const ci_detect_1 = __importDefault(require("@npmcli/ci-detect"));
|
|
8
|
-
const providers_1 = require("./providers");
|
|
9
|
-
const GROUPS = {
|
|
10
|
-
LOG_WORKSPACE: 'Logger Options',
|
|
11
|
-
GROUP_WORKSPACE: 'Workspace Options',
|
|
12
|
-
JSON_SCHEMA_WORKSPACE: 'JSON Schema Options'
|
|
13
|
-
};
|
|
14
|
-
exports.args = {
|
|
15
|
-
env: {
|
|
16
|
-
alias: 'e',
|
|
17
|
-
type: 'string',
|
|
18
|
-
describe: 'Environment for load, i.e. dev, prod'
|
|
19
|
-
},
|
|
20
|
-
modes: {
|
|
21
|
-
alias: 'm',
|
|
22
|
-
type: 'array',
|
|
23
|
-
describe: 'Execution modes, i.e. debug, test'
|
|
24
|
-
},
|
|
25
|
-
providers: {
|
|
26
|
-
type: 'array',
|
|
27
|
-
hidden: true,
|
|
28
|
-
default: providers_1.IntegratedProviderConfig,
|
|
29
|
-
describe: 'Providers handling variables loading'
|
|
30
|
-
},
|
|
31
|
-
ci: {
|
|
32
|
-
alias: 'ci',
|
|
33
|
-
type: 'boolean',
|
|
34
|
-
default: (0, ci_detect_1.default)(),
|
|
35
|
-
describe: 'Whether providers executes in continuous integration mode'
|
|
36
|
-
},
|
|
37
|
-
nestingDelimiter: {
|
|
38
|
-
alias: 'nd',
|
|
39
|
-
type: 'string',
|
|
40
|
-
default: '__',
|
|
41
|
-
describe: 'Nesting level delimiter for flatten, i.e. { l1: { l2: "value" } } turns into { l1__l2: "value" }'
|
|
42
|
-
},
|
|
43
|
-
arrayDescomposition: {
|
|
44
|
-
alias: 'arrDesc',
|
|
45
|
-
type: 'boolean',
|
|
46
|
-
default: false,
|
|
47
|
-
describe: 'Whether serialize or break down arrays'
|
|
48
|
-
},
|
|
49
|
-
expand: {
|
|
50
|
-
alias: 'x',
|
|
51
|
-
type: 'boolean',
|
|
52
|
-
default: false,
|
|
53
|
-
describe: 'Interpolates environment variables using itself'
|
|
54
|
-
},
|
|
55
|
-
root: {
|
|
56
|
-
group: GROUPS.GROUP_WORKSPACE,
|
|
57
|
-
type: 'string',
|
|
58
|
-
default: 'env',
|
|
59
|
-
describe: 'Default environment folder path'
|
|
60
|
-
},
|
|
61
|
-
configFile: {
|
|
62
|
-
group: GROUPS.GROUP_WORKSPACE,
|
|
63
|
-
alias: 'c',
|
|
64
|
-
type: 'string',
|
|
65
|
-
default: '[[root]]/settings/settings.json',
|
|
66
|
-
describe: 'Config JSON file path'
|
|
67
|
-
},
|
|
68
|
-
schemaFile: {
|
|
69
|
-
group: GROUPS.GROUP_WORKSPACE,
|
|
70
|
-
alias: ['s', 'schema'],
|
|
71
|
-
type: 'string',
|
|
72
|
-
default: '[[root]]/settings/schema.json',
|
|
73
|
-
describe: 'Environment Schema JSON file path'
|
|
74
|
-
},
|
|
75
|
-
packageJson: {
|
|
76
|
-
group: GROUPS.GROUP_WORKSPACE,
|
|
77
|
-
alias: ['pkg'],
|
|
78
|
-
type: 'string',
|
|
79
|
-
default: '',
|
|
80
|
-
describe: 'package.json path'
|
|
81
|
-
},
|
|
82
|
-
resolve: {
|
|
83
|
-
group: GROUPS.JSON_SCHEMA_WORKSPACE,
|
|
84
|
-
alias: 'r',
|
|
85
|
-
type: 'string',
|
|
86
|
-
default: 'merge',
|
|
87
|
-
choices: ['merge', 'override'],
|
|
88
|
-
describe: 'Whether merges new schema or override'
|
|
89
|
-
},
|
|
90
|
-
nullable: {
|
|
91
|
-
group: GROUPS.JSON_SCHEMA_WORKSPACE,
|
|
92
|
-
alias: 'null',
|
|
93
|
-
type: 'boolean',
|
|
94
|
-
default: true,
|
|
95
|
-
describe: 'Whether variables are nullable'
|
|
96
|
-
},
|
|
97
|
-
detectFormat: {
|
|
98
|
-
group: GROUPS.JSON_SCHEMA_WORKSPACE,
|
|
99
|
-
alias: 'df',
|
|
100
|
-
type: 'boolean',
|
|
101
|
-
default: true,
|
|
102
|
-
describe: 'Whether format of strings variables are included in schema'
|
|
103
|
-
},
|
|
104
|
-
logLevel: {
|
|
105
|
-
group: GROUPS.LOG_WORKSPACE,
|
|
106
|
-
alias: 'log',
|
|
107
|
-
type: 'string',
|
|
108
|
-
default: 'info',
|
|
109
|
-
choices: ['silly', 'trace', 'debug', 'info', 'warn', 'error']
|
|
110
|
-
},
|
|
111
|
-
logMaskAnyRegEx: {
|
|
112
|
-
group: GROUPS.LOG_WORKSPACE,
|
|
113
|
-
alias: 'mrx',
|
|
114
|
-
type: 'array',
|
|
115
|
-
hidden: true,
|
|
116
|
-
default: []
|
|
117
|
-
},
|
|
118
|
-
logMaskValuesOfKeys: {
|
|
119
|
-
group: GROUPS.LOG_WORKSPACE,
|
|
120
|
-
alias: 'mvk',
|
|
121
|
-
type: 'array',
|
|
122
|
-
hidden: true,
|
|
123
|
-
default: []
|
|
124
|
-
}
|
|
125
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.args = void 0;
|
|
7
|
+
const ci_detect_1 = __importDefault(require("@npmcli/ci-detect"));
|
|
8
|
+
const providers_1 = require("./providers");
|
|
9
|
+
const GROUPS = {
|
|
10
|
+
LOG_WORKSPACE: 'Logger Options',
|
|
11
|
+
GROUP_WORKSPACE: 'Workspace Options',
|
|
12
|
+
JSON_SCHEMA_WORKSPACE: 'JSON Schema Options'
|
|
13
|
+
};
|
|
14
|
+
exports.args = {
|
|
15
|
+
env: {
|
|
16
|
+
alias: 'e',
|
|
17
|
+
type: 'string',
|
|
18
|
+
describe: 'Environment for load, i.e. dev, prod'
|
|
19
|
+
},
|
|
20
|
+
modes: {
|
|
21
|
+
alias: 'm',
|
|
22
|
+
type: 'array',
|
|
23
|
+
describe: 'Execution modes, i.e. debug, test'
|
|
24
|
+
},
|
|
25
|
+
providers: {
|
|
26
|
+
type: 'array',
|
|
27
|
+
hidden: true,
|
|
28
|
+
default: providers_1.IntegratedProviderConfig,
|
|
29
|
+
describe: 'Providers handling variables loading'
|
|
30
|
+
},
|
|
31
|
+
ci: {
|
|
32
|
+
alias: 'ci',
|
|
33
|
+
type: 'boolean',
|
|
34
|
+
default: (0, ci_detect_1.default)(),
|
|
35
|
+
describe: 'Whether providers executes in continuous integration mode'
|
|
36
|
+
},
|
|
37
|
+
nestingDelimiter: {
|
|
38
|
+
alias: 'nd',
|
|
39
|
+
type: 'string',
|
|
40
|
+
default: '__',
|
|
41
|
+
describe: 'Nesting level delimiter for flatten, i.e. { l1: { l2: "value" } } turns into { l1__l2: "value" }'
|
|
42
|
+
},
|
|
43
|
+
arrayDescomposition: {
|
|
44
|
+
alias: 'arrDesc',
|
|
45
|
+
type: 'boolean',
|
|
46
|
+
default: false,
|
|
47
|
+
describe: 'Whether serialize or break down arrays'
|
|
48
|
+
},
|
|
49
|
+
expand: {
|
|
50
|
+
alias: 'x',
|
|
51
|
+
type: 'boolean',
|
|
52
|
+
default: false,
|
|
53
|
+
describe: 'Interpolates environment variables using itself'
|
|
54
|
+
},
|
|
55
|
+
root: {
|
|
56
|
+
group: GROUPS.GROUP_WORKSPACE,
|
|
57
|
+
type: 'string',
|
|
58
|
+
default: 'env',
|
|
59
|
+
describe: 'Default environment folder path'
|
|
60
|
+
},
|
|
61
|
+
configFile: {
|
|
62
|
+
group: GROUPS.GROUP_WORKSPACE,
|
|
63
|
+
alias: 'c',
|
|
64
|
+
type: 'string',
|
|
65
|
+
default: '[[root]]/settings/settings.json',
|
|
66
|
+
describe: 'Config JSON file path'
|
|
67
|
+
},
|
|
68
|
+
schemaFile: {
|
|
69
|
+
group: GROUPS.GROUP_WORKSPACE,
|
|
70
|
+
alias: ['s', 'schema'],
|
|
71
|
+
type: 'string',
|
|
72
|
+
default: '[[root]]/settings/schema.json',
|
|
73
|
+
describe: 'Environment Schema JSON file path'
|
|
74
|
+
},
|
|
75
|
+
packageJson: {
|
|
76
|
+
group: GROUPS.GROUP_WORKSPACE,
|
|
77
|
+
alias: ['pkg'],
|
|
78
|
+
type: 'string',
|
|
79
|
+
default: '',
|
|
80
|
+
describe: 'package.json path'
|
|
81
|
+
},
|
|
82
|
+
resolve: {
|
|
83
|
+
group: GROUPS.JSON_SCHEMA_WORKSPACE,
|
|
84
|
+
alias: 'r',
|
|
85
|
+
type: 'string',
|
|
86
|
+
default: 'merge',
|
|
87
|
+
choices: ['merge', 'override'],
|
|
88
|
+
describe: 'Whether merges new schema or override'
|
|
89
|
+
},
|
|
90
|
+
nullable: {
|
|
91
|
+
group: GROUPS.JSON_SCHEMA_WORKSPACE,
|
|
92
|
+
alias: 'null',
|
|
93
|
+
type: 'boolean',
|
|
94
|
+
default: true,
|
|
95
|
+
describe: 'Whether variables are nullable'
|
|
96
|
+
},
|
|
97
|
+
detectFormat: {
|
|
98
|
+
group: GROUPS.JSON_SCHEMA_WORKSPACE,
|
|
99
|
+
alias: 'df',
|
|
100
|
+
type: 'boolean',
|
|
101
|
+
default: true,
|
|
102
|
+
describe: 'Whether format of strings variables are included in schema'
|
|
103
|
+
},
|
|
104
|
+
logLevel: {
|
|
105
|
+
group: GROUPS.LOG_WORKSPACE,
|
|
106
|
+
alias: 'log',
|
|
107
|
+
type: 'string',
|
|
108
|
+
default: 'info',
|
|
109
|
+
choices: ['silly', 'trace', 'debug', 'info', 'warn', 'error']
|
|
110
|
+
},
|
|
111
|
+
logMaskAnyRegEx: {
|
|
112
|
+
group: GROUPS.LOG_WORKSPACE,
|
|
113
|
+
alias: 'mrx',
|
|
114
|
+
type: 'array',
|
|
115
|
+
hidden: true,
|
|
116
|
+
default: []
|
|
117
|
+
},
|
|
118
|
+
logMaskValuesOfKeys: {
|
|
119
|
+
group: GROUPS.LOG_WORKSPACE,
|
|
120
|
+
alias: 'mvk',
|
|
121
|
+
type: 'array',
|
|
122
|
+
hidden: true,
|
|
123
|
+
default: []
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
126
|
//# sourceMappingURL=arguments.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CommandModule } from 'yargs';
|
|
2
|
-
import { CommandArguments } from '../arguments';
|
|
3
|
-
export interface EnvCommandArguments extends CommandArguments {
|
|
4
|
-
subcmd: string[];
|
|
5
|
-
schemaValidate: boolean;
|
|
6
|
-
}
|
|
7
|
-
export declare const envCommand: CommandModule<any, EnvCommandArguments>;
|
|
1
|
+
import { CommandModule } from 'yargs';
|
|
2
|
+
import { CommandArguments } from '../arguments';
|
|
3
|
+
export interface EnvCommandArguments extends CommandArguments {
|
|
4
|
+
subcmd: string[];
|
|
5
|
+
schemaValidate: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const envCommand: CommandModule<any, EnvCommandArguments>;
|
|
8
8
|
//# sourceMappingURL=env.command.d.ts.map
|
package/commands/env.command.js
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.envCommand = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const merge_deep_1 = __importDefault(require("merge-deep"));
|
|
9
|
-
const child_process_1 = require("child_process");
|
|
10
|
-
const utils_1 = require("../utils");
|
|
11
|
-
exports.envCommand = {
|
|
12
|
-
command: '$0 [options..] [: <subcmd> :]',
|
|
13
|
-
describe: 'Inject environment variables into process',
|
|
14
|
-
builder: (builder) => {
|
|
15
|
-
builder
|
|
16
|
-
.options({
|
|
17
|
-
subcmd: {
|
|
18
|
-
type: 'array',
|
|
19
|
-
describe: 'Command for inject environment variables'
|
|
20
|
-
},
|
|
21
|
-
schemaValidate: {
|
|
22
|
-
alias: 'validate',
|
|
23
|
-
type: 'boolean',
|
|
24
|
-
default: true,
|
|
25
|
-
describe: 'Whether validates variables using JSON schema'
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
.example('env -e dev -m test unit : npm test', 'Loads "dev" environment variables, in "test" and "unit" modes, for "npm start" command')
|
|
29
|
-
.example('env -e dev -m debug : npm start : -c my-config.json', 'Loads "dev" environment variables, in "debug" mode, for "npm test" command and custom config file')
|
|
30
|
-
.example('env -e dev -m debug -c [[root]]/[[env]].env.json : npm start', 'Loads custom config file placed in root folder and named same as the env')
|
|
31
|
-
.check((argv) => {
|
|
32
|
-
if (argv._.length === 0 && !argv.subcmd) {
|
|
33
|
-
utils_1.logger.error('No one subcommand provided for exec surrounded by :');
|
|
34
|
-
process.exit(1);
|
|
35
|
-
}
|
|
36
|
-
return true;
|
|
37
|
-
});
|
|
38
|
-
return builder;
|
|
39
|
-
},
|
|
40
|
-
handler: async ({ providers, schemaValidate, expand, ...argv }) => {
|
|
41
|
-
var _a;
|
|
42
|
-
const results = await (0, utils_1.loadVariablesFromProviders)(providers, argv);
|
|
43
|
-
let env = (0, merge_deep_1.default)({ NODE_ENV: 'development' }, ...(0, utils_1.flatResults)(results));
|
|
44
|
-
env = (0, utils_1.flatten)(env, argv.nestingDelimiter);
|
|
45
|
-
if (schemaValidate) {
|
|
46
|
-
let schema = {};
|
|
47
|
-
for (const { handler: { key } } of providers) {
|
|
48
|
-
const providerSchema = (_a = argv.schema) === null || _a === void 0 ? void 0 : _a[key];
|
|
49
|
-
if (providerSchema) {
|
|
50
|
-
schema = Object.assign(schema, (0, utils_1.flatSchema)(providerSchema, '', argv.nestingDelimiter));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const validator = (0, utils_1.createValidator)({
|
|
54
|
-
type: 'object',
|
|
55
|
-
properties: schema
|
|
56
|
-
});
|
|
57
|
-
if (!validator(env)) {
|
|
58
|
-
utils_1.logger.error('schema validation failed', validator.errors);
|
|
59
|
-
process.exit(1);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
env = (0, utils_1.normalize)(env, argv.nestingDelimiter, argv.arrayDescomposition);
|
|
63
|
-
if (expand)
|
|
64
|
-
env = (0, utils_1.interpolate)(env, env);
|
|
65
|
-
utils_1.logger.debug('environment loaded:', env);
|
|
66
|
-
process.env = {
|
|
67
|
-
...process.env,
|
|
68
|
-
...env
|
|
69
|
-
};
|
|
70
|
-
utils_1.logger.info('executing command >', chalk_1.default.bold.yellow(argv.subcmd.join(' ')));
|
|
71
|
-
(0, child_process_1.spawn)(argv.subcmd[0], argv.subcmd.slice(1), {
|
|
72
|
-
stdio: 'inherit',
|
|
73
|
-
shell: true
|
|
74
|
-
}).on('exit', (code) => {
|
|
75
|
-
utils_1.logger.info('process finished');
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.envCommand = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const merge_deep_1 = __importDefault(require("merge-deep"));
|
|
9
|
+
const child_process_1 = require("child_process");
|
|
10
|
+
const utils_1 = require("../utils");
|
|
11
|
+
exports.envCommand = {
|
|
12
|
+
command: '$0 [options..] [: <subcmd> :]',
|
|
13
|
+
describe: 'Inject environment variables into process',
|
|
14
|
+
builder: (builder) => {
|
|
15
|
+
builder
|
|
16
|
+
.options({
|
|
17
|
+
subcmd: {
|
|
18
|
+
type: 'array',
|
|
19
|
+
describe: 'Command for inject environment variables'
|
|
20
|
+
},
|
|
21
|
+
schemaValidate: {
|
|
22
|
+
alias: 'validate',
|
|
23
|
+
type: 'boolean',
|
|
24
|
+
default: true,
|
|
25
|
+
describe: 'Whether validates variables using JSON schema'
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
.example('env -e dev -m test unit : npm test', 'Loads "dev" environment variables, in "test" and "unit" modes, for "npm start" command')
|
|
29
|
+
.example('env -e dev -m debug : npm start : -c my-config.json', 'Loads "dev" environment variables, in "debug" mode, for "npm test" command and custom config file')
|
|
30
|
+
.example('env -e dev -m debug -c [[root]]/[[env]].env.json : npm start', 'Loads custom config file placed in root folder and named same as the env')
|
|
31
|
+
.check((argv) => {
|
|
32
|
+
if (argv._.length === 0 && !argv.subcmd) {
|
|
33
|
+
utils_1.logger.error('No one subcommand provided for exec surrounded by :');
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
});
|
|
38
|
+
return builder;
|
|
39
|
+
},
|
|
40
|
+
handler: async ({ providers, schemaValidate, expand, ...argv }) => {
|
|
41
|
+
var _a;
|
|
42
|
+
const results = await (0, utils_1.loadVariablesFromProviders)(providers, argv);
|
|
43
|
+
let env = (0, merge_deep_1.default)({ NODE_ENV: 'development' }, ...(0, utils_1.flatResults)(results));
|
|
44
|
+
env = (0, utils_1.flatten)(env, argv.nestingDelimiter);
|
|
45
|
+
if (schemaValidate) {
|
|
46
|
+
let schema = {};
|
|
47
|
+
for (const { handler: { key } } of providers) {
|
|
48
|
+
const providerSchema = (_a = argv.schema) === null || _a === void 0 ? void 0 : _a[key];
|
|
49
|
+
if (providerSchema) {
|
|
50
|
+
schema = Object.assign(schema, (0, utils_1.flatSchema)(providerSchema, '', argv.nestingDelimiter));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const validator = (0, utils_1.createValidator)({
|
|
54
|
+
type: 'object',
|
|
55
|
+
properties: schema
|
|
56
|
+
});
|
|
57
|
+
if (!validator(env)) {
|
|
58
|
+
utils_1.logger.error('schema validation failed', validator.errors);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
env = (0, utils_1.normalize)(env, argv.nestingDelimiter, argv.arrayDescomposition);
|
|
63
|
+
if (expand)
|
|
64
|
+
env = (0, utils_1.interpolate)(env, env);
|
|
65
|
+
utils_1.logger.debug('environment loaded:', env);
|
|
66
|
+
process.env = {
|
|
67
|
+
...process.env,
|
|
68
|
+
...env
|
|
69
|
+
};
|
|
70
|
+
utils_1.logger.info('executing command >', chalk_1.default.bold.yellow(argv.subcmd.join(' ')));
|
|
71
|
+
(0, child_process_1.spawn)(argv.subcmd[0], argv.subcmd.slice(1), {
|
|
72
|
+
stdio: 'inherit',
|
|
73
|
+
shell: true
|
|
74
|
+
}).on('exit', (code) => {
|
|
75
|
+
utils_1.logger.info('process finished');
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
79
|
//# sourceMappingURL=env.command.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CommandModule } from 'yargs';
|
|
2
|
-
import { CommandArguments } from '../arguments';
|
|
3
|
-
export interface ExportCommandArguments extends CommandArguments {
|
|
4
|
-
format: 'json' | 'dotenv';
|
|
5
|
-
uri: string;
|
|
6
|
-
}
|
|
7
|
-
export declare const exportCommand: CommandModule<any, ExportCommandArguments>;
|
|
1
|
+
import { CommandModule } from 'yargs';
|
|
2
|
+
import { CommandArguments } from '../arguments';
|
|
3
|
+
export interface ExportCommandArguments extends CommandArguments {
|
|
4
|
+
format: 'json' | 'dotenv';
|
|
5
|
+
uri: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const exportCommand: CommandModule<any, ExportCommandArguments>;
|
|
8
8
|
//# sourceMappingURL=export.command.d.ts.map
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.exportCommand = void 0;
|
|
7
|
-
const merge_deep_1 = __importDefault(require("merge-deep"));
|
|
8
|
-
const utils_1 = require("../utils");
|
|
9
|
-
exports.exportCommand = {
|
|
10
|
-
command: 'export [options..]',
|
|
11
|
-
describe: 'Export unified environment variables to a file from providers',
|
|
12
|
-
builder: (builder) => {
|
|
13
|
-
builder
|
|
14
|
-
.options({
|
|
15
|
-
uri: {
|
|
16
|
-
alias: ['u', 'p', 'path'],
|
|
17
|
-
type: 'string',
|
|
18
|
-
default: '.env',
|
|
19
|
-
describe: 'Uri for export file with variables'
|
|
20
|
-
},
|
|
21
|
-
format: {
|
|
22
|
-
alias: 'f',
|
|
23
|
-
type: 'string',
|
|
24
|
-
default: 'dotenv',
|
|
25
|
-
choices: ['json', 'dotenv'],
|
|
26
|
-
describe: 'Format for export variables'
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
.example('env export -e dev -m build', 'Exports "dev" variables to a dotenv file at root as ".env"')
|
|
30
|
-
.example('env export -e prod -m build -f json --uri [[env]].env.json', 'Exports "prod" variables to a json file at root as "prod.env.json"');
|
|
31
|
-
return builder;
|
|
32
|
-
},
|
|
33
|
-
handler: async ({ providers, expand, ...argv }) => {
|
|
34
|
-
const results = await (0, utils_1.loadVariablesFromProviders)(providers, argv);
|
|
35
|
-
let env = (0, merge_deep_1.default)({ NODE_ENV: 'development' }, ...(0, utils_1.flatAndValidateResults)(results, argv));
|
|
36
|
-
env = (0, utils_1.flatten)(env, argv.nestingDelimiter);
|
|
37
|
-
env = (0, utils_1.normalize)(env, argv.nestingDelimiter, argv.arrayDescomposition);
|
|
38
|
-
if (expand)
|
|
39
|
-
env = (0, utils_1.interpolate)(env, env);
|
|
40
|
-
utils_1.logger.debug('environment loaded:', env);
|
|
41
|
-
const { format, uri } = argv;
|
|
42
|
-
switch (format) {
|
|
43
|
-
case 'dotenv':
|
|
44
|
-
await (0, utils_1.writeEnvFromJson)(uri, env, true);
|
|
45
|
-
break;
|
|
46
|
-
case 'json':
|
|
47
|
-
await (0, utils_1.writeJson)(uri, env, true);
|
|
48
|
-
break;
|
|
49
|
-
default:
|
|
50
|
-
utils_1.logger.error(`format ${format} not recognized`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.exportCommand = void 0;
|
|
7
|
+
const merge_deep_1 = __importDefault(require("merge-deep"));
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
exports.exportCommand = {
|
|
10
|
+
command: 'export [options..]',
|
|
11
|
+
describe: 'Export unified environment variables to a file from providers',
|
|
12
|
+
builder: (builder) => {
|
|
13
|
+
builder
|
|
14
|
+
.options({
|
|
15
|
+
uri: {
|
|
16
|
+
alias: ['u', 'p', 'path'],
|
|
17
|
+
type: 'string',
|
|
18
|
+
default: '.env',
|
|
19
|
+
describe: 'Uri for export file with variables'
|
|
20
|
+
},
|
|
21
|
+
format: {
|
|
22
|
+
alias: 'f',
|
|
23
|
+
type: 'string',
|
|
24
|
+
default: 'dotenv',
|
|
25
|
+
choices: ['json', 'dotenv'],
|
|
26
|
+
describe: 'Format for export variables'
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
.example('env export -e dev -m build', 'Exports "dev" variables to a dotenv file at root as ".env"')
|
|
30
|
+
.example('env export -e prod -m build -f json --uri [[env]].env.json', 'Exports "prod" variables to a json file at root as "prod.env.json"');
|
|
31
|
+
return builder;
|
|
32
|
+
},
|
|
33
|
+
handler: async ({ providers, expand, ...argv }) => {
|
|
34
|
+
const results = await (0, utils_1.loadVariablesFromProviders)(providers, argv);
|
|
35
|
+
let env = (0, merge_deep_1.default)({ NODE_ENV: 'development' }, ...(0, utils_1.flatAndValidateResults)(results, argv));
|
|
36
|
+
env = (0, utils_1.flatten)(env, argv.nestingDelimiter);
|
|
37
|
+
env = (0, utils_1.normalize)(env, argv.nestingDelimiter, argv.arrayDescomposition);
|
|
38
|
+
if (expand)
|
|
39
|
+
env = (0, utils_1.interpolate)(env, env);
|
|
40
|
+
utils_1.logger.debug('environment loaded:', env);
|
|
41
|
+
const { format, uri } = argv;
|
|
42
|
+
switch (format) {
|
|
43
|
+
case 'dotenv':
|
|
44
|
+
await (0, utils_1.writeEnvFromJson)(uri, env, true);
|
|
45
|
+
break;
|
|
46
|
+
case 'json':
|
|
47
|
+
await (0, utils_1.writeJson)(uri, env, true);
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
utils_1.logger.error(`format ${format} not recognized`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
54
|
//# sourceMappingURL=export.command.js.map
|
package/commands/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { envCommand } from './env.command';
|
|
2
|
-
export { exportCommand } from './export.command';
|
|
3
|
-
export { pullCommand } from './pull.command';
|
|
4
|
-
export { pushCommand } from './push.command';
|
|
5
|
-
export { schemaCommand } from './schema.command';
|
|
1
|
+
export { envCommand } from './env.command';
|
|
2
|
+
export { exportCommand } from './export.command';
|
|
3
|
+
export { pullCommand } from './pull.command';
|
|
4
|
+
export { pushCommand } from './push.command';
|
|
5
|
+
export { schemaCommand } from './schema.command';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/commands/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.schemaCommand = exports.pushCommand = exports.pullCommand = exports.exportCommand = exports.envCommand = void 0;
|
|
4
|
-
var env_command_1 = require("./env.command");
|
|
5
|
-
Object.defineProperty(exports, "envCommand", { enumerable: true, get: function () { return env_command_1.envCommand; } });
|
|
6
|
-
var export_command_1 = require("./export.command");
|
|
7
|
-
Object.defineProperty(exports, "exportCommand", { enumerable: true, get: function () { return export_command_1.exportCommand; } });
|
|
8
|
-
var pull_command_1 = require("./pull.command");
|
|
9
|
-
Object.defineProperty(exports, "pullCommand", { enumerable: true, get: function () { return pull_command_1.pullCommand; } });
|
|
10
|
-
var push_command_1 = require("./push.command");
|
|
11
|
-
Object.defineProperty(exports, "pushCommand", { enumerable: true, get: function () { return push_command_1.pushCommand; } });
|
|
12
|
-
var schema_command_1 = require("./schema.command");
|
|
13
|
-
Object.defineProperty(exports, "schemaCommand", { enumerable: true, get: function () { return schema_command_1.schemaCommand; } });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.schemaCommand = exports.pushCommand = exports.pullCommand = exports.exportCommand = exports.envCommand = void 0;
|
|
4
|
+
var env_command_1 = require("./env.command");
|
|
5
|
+
Object.defineProperty(exports, "envCommand", { enumerable: true, get: function () { return env_command_1.envCommand; } });
|
|
6
|
+
var export_command_1 = require("./export.command");
|
|
7
|
+
Object.defineProperty(exports, "exportCommand", { enumerable: true, get: function () { return export_command_1.exportCommand; } });
|
|
8
|
+
var pull_command_1 = require("./pull.command");
|
|
9
|
+
Object.defineProperty(exports, "pullCommand", { enumerable: true, get: function () { return pull_command_1.pullCommand; } });
|
|
10
|
+
var push_command_1 = require("./push.command");
|
|
11
|
+
Object.defineProperty(exports, "pushCommand", { enumerable: true, get: function () { return push_command_1.pushCommand; } });
|
|
12
|
+
var schema_command_1 = require("./schema.command");
|
|
13
|
+
Object.defineProperty(exports, "schemaCommand", { enumerable: true, get: function () { return schema_command_1.schemaCommand; } });
|
|
14
14
|
//# sourceMappingURL=index.js.map
|