@mono-labs/cli 0.0.157 → 0.0.159
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.
|
@@ -42,106 +42,110 @@ export function createCliCommands() {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export function buildCommands(files) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const required = !!argInfo.required;
|
|
56
|
-
const type = argInfo.type || 'string';
|
|
57
|
-
const argSpec = required ? `<${type}>` : `[${type}]`;
|
|
58
|
-
current = current.argument(argSpec, argInfo.description || '');
|
|
59
|
-
}
|
|
60
|
-
console.log('configObject:', JSON.stringify(configObject, null, 2));
|
|
61
|
-
|
|
62
|
-
// Options
|
|
63
|
-
Object.entries(optionsData).forEach(([optionKey, meta]) => {
|
|
64
|
-
const type = meta.type || 'boolean';
|
|
65
|
-
const shortcut = meta.shortcut ? `-${meta.shortcut}, ` : '';
|
|
66
|
-
if (type === 'string') {
|
|
67
|
-
current = current.option(
|
|
68
|
-
`${shortcut}--${optionKey} <${optionKey}>`,
|
|
69
|
-
meta.description || ''
|
|
70
|
-
);
|
|
71
|
-
if (meta.default !== undefined) setData(optionKey, meta.default);
|
|
72
|
-
} else {
|
|
73
|
-
current = current.option(
|
|
74
|
-
`${shortcut}--${optionKey}`,
|
|
75
|
-
meta.description || ''
|
|
76
|
-
);
|
|
77
|
-
if (meta.default !== undefined) setData(optionKey, meta.default);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
config.prodFlag = config.prodFlag || 'prod';
|
|
81
|
-
|
|
82
|
-
current = current.option(
|
|
83
|
-
`--${config.prodFlag}`,
|
|
84
|
-
'Process execution mode: prduction or dev',
|
|
85
|
-
false
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
current.action(async (arg, cmd) => {
|
|
89
|
-
let envDefaults = {};
|
|
90
|
-
const optionValueList = argInfo.options;
|
|
91
|
-
console.log('argInfo:', argInfo);
|
|
92
|
-
console.log('optionValueList:', optionValueList);
|
|
93
|
-
let actualOptions = optionValueList;
|
|
94
|
-
if (optionValueList) {
|
|
95
|
-
actualOptions =
|
|
96
|
-
argInfo?.allowAll ?
|
|
97
|
-
[...optionValueList, 'all']
|
|
98
|
-
: [...optionValueList];
|
|
99
|
-
}
|
|
100
|
-
|
|
45
|
+
try {
|
|
46
|
+
const { config } = getHasteConfig();
|
|
47
|
+
Object.entries(files).forEach(([commandName, configObject]) => {
|
|
48
|
+
const optionsData = configObject.options || {};
|
|
49
|
+
|
|
50
|
+
let current = program
|
|
51
|
+
.command(commandName)
|
|
52
|
+
.description(configObject.description || 'Haste command');
|
|
53
|
+
const argInfo = configObject.argument;
|
|
54
|
+
// Argument
|
|
101
55
|
if (argInfo) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
56
|
+
const required = !!argInfo.required;
|
|
57
|
+
const type = argInfo.type || 'string';
|
|
58
|
+
const argSpec = required ? `<${type}>` : `[${type}]`;
|
|
59
|
+
current = current.argument(argSpec, argInfo.description || '');
|
|
60
|
+
}
|
|
61
|
+
console.log('configObject:', JSON.stringify(configObject, null, 2));
|
|
62
|
+
|
|
63
|
+
// Options
|
|
64
|
+
Object.entries(optionsData).forEach(([optionKey, meta]) => {
|
|
65
|
+
const type = meta.type || 'boolean';
|
|
66
|
+
const shortcut = meta.shortcut ? `-${meta.shortcut}, ` : '';
|
|
67
|
+
if (type === 'string') {
|
|
68
|
+
current = current.option(
|
|
69
|
+
`${shortcut}--${optionKey} <${optionKey}>`,
|
|
70
|
+
meta.description || ''
|
|
71
|
+
);
|
|
72
|
+
if (meta.default !== undefined) setData(optionKey, meta.default);
|
|
73
|
+
} else {
|
|
74
|
+
current = current.option(
|
|
75
|
+
`${shortcut}--${optionKey}`,
|
|
76
|
+
meta.description || ''
|
|
111
77
|
);
|
|
78
|
+
if (meta.default !== undefined) setData(optionKey, meta.default);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
config.prodFlag = config.prodFlag || 'prod';
|
|
82
|
+
|
|
83
|
+
current = current.option(
|
|
84
|
+
`--${config.prodFlag}`,
|
|
85
|
+
'Process execution mode: prduction or dev',
|
|
86
|
+
false
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
current.action(async (arg, cmd) => {
|
|
90
|
+
let envDefaults = {};
|
|
91
|
+
const optionValueList = argInfo.options;
|
|
92
|
+
console.log('argInfo:', argInfo);
|
|
93
|
+
console.log('optionValueList:', optionValueList);
|
|
94
|
+
let actualOptions = optionValueList;
|
|
95
|
+
if (optionValueList) {
|
|
96
|
+
actualOptions =
|
|
97
|
+
argInfo?.allowAll ?
|
|
98
|
+
[...optionValueList, 'all']
|
|
99
|
+
: [...optionValueList];
|
|
112
100
|
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const optionsDataList = Object.keys(optionsData).map((key) => ({
|
|
116
|
-
...optionsData[key],
|
|
117
|
-
name: key,
|
|
118
|
-
}));
|
|
119
101
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
102
|
+
if (argInfo) {
|
|
103
|
+
if (
|
|
104
|
+
argInfo &&
|
|
105
|
+
optionValueList &&
|
|
106
|
+
!actualOptions.includes(arg ?? argInfo.default)
|
|
107
|
+
) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`Invalid argument value for ${commandName}, must be one of: ${actualOptions.join(
|
|
110
|
+
', '
|
|
111
|
+
)}`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
123
114
|
}
|
|
124
|
-
});
|
|
125
115
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
// });
|
|
116
|
+
const optionsDataList = Object.keys(optionsData).map((key) => ({
|
|
117
|
+
...optionsData[key],
|
|
118
|
+
name: key,
|
|
119
|
+
}));
|
|
131
120
|
|
|
132
|
-
|
|
121
|
+
optionsDataList.map((item) => {
|
|
122
|
+
if (item.default) {
|
|
123
|
+
envDefaults[item.name] = item.default;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
133
126
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
127
|
+
// optionsData
|
|
128
|
+
// .filter((item) => item.default !== undefined)
|
|
129
|
+
// .forEach((item) => {
|
|
130
|
+
// envDefaults[item] = item.default;
|
|
131
|
+
// });
|
|
138
132
|
|
|
139
|
-
|
|
133
|
+
const optionVals = { ...envDefaults, ...(cmd.opts ? cmd.opts() : cmd) };
|
|
140
134
|
|
|
141
|
-
|
|
142
|
-
|
|
135
|
+
Object.keys(optionVals).forEach((k) => {
|
|
136
|
+
optionVals[k] = verifyOptionValue(k, optionVals[k], optionsData);
|
|
137
|
+
});
|
|
138
|
+
optionVals['prod'] = optionVals[config.prodFlag] || false;
|
|
139
|
+
|
|
140
|
+
const argVal = arg || configObject.argument?.default;
|
|
141
|
+
|
|
142
|
+
mergeData({ ...optionVals, arg: argVal });
|
|
143
|
+
await runHasteCommand(configObject, optionVals);
|
|
144
|
+
});
|
|
143
145
|
});
|
|
144
|
-
})
|
|
146
|
+
} catch (err) {
|
|
147
|
+
console.error('Error executing mono command:', err);
|
|
148
|
+
}
|
|
145
149
|
}
|
|
146
150
|
|
|
147
151
|
export default buildCommands;
|
|
@@ -13,81 +13,74 @@ import path from 'node:path';
|
|
|
13
13
|
* Environment selection based on --stage flag and injection of AWS_PROFILE.
|
|
14
14
|
*/
|
|
15
15
|
export async function runHasteCommand(configObject, options = {}) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const devConfig = configObject.environments?.dev ?? {};
|
|
16
|
+
const { config } = getHasteConfig();
|
|
17
|
+
const devConfig = configObject.environments?.dev ?? {};
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
// Usage:
|
|
20
|
+
const envPath = path.resolve(process.cwd(), '.env');
|
|
21
|
+
const keymap = parseEnvFile(envPath);
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const prodConfig = configObject.environments?.prod ?? {};
|
|
24
|
+
const awsProfile = process.env.CDK_DEPLOY_PROFILE || 'default';
|
|
25
|
+
const envObjBase = options.prod ? { ...prodConfig } : { ...devConfig };
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
Object.keys(envObjBase).forEach((k) => {
|
|
28
|
+
if (
|
|
29
|
+
typeof envObjBase[k] === 'string' &&
|
|
30
|
+
envObjBase[k].startsWith('$') &&
|
|
31
|
+
!envObjBase[k].startsWith('${')
|
|
32
|
+
) {
|
|
33
|
+
const refKey = envObjBase[k].substring(1);
|
|
34
|
+
envObjBase[k] = keymap[refKey] || '';
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
envObjBase.AWS_PROFILE = awsProfile;
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const combinedEnv = { ...process.env, ...envObjBase };
|
|
45
|
-
let envMapVals = {};
|
|
39
|
+
const envKeys = Object.keys(process.env).filter((k) => k.startsWith('MONO_'));
|
|
40
|
+
const envMapList = config.envMap ?? ['FAILURE'];
|
|
41
|
+
const combinedEnv = { ...process.env, ...envObjBase };
|
|
42
|
+
let envMapVals = {};
|
|
46
43
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
44
|
+
envKeys.map((k) => {
|
|
45
|
+
envMapList.map((item) => {
|
|
46
|
+
envMapVals[k.replace('MONO', item)] = combinedEnv[k];
|
|
51
47
|
});
|
|
48
|
+
});
|
|
52
49
|
|
|
53
|
-
|
|
50
|
+
const envObj = { ...envObjBase, ...envMapVals };
|
|
54
51
|
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
const preactions = configObject.preactions ?? [];
|
|
53
|
+
const actions = configObject.actions ?? [];
|
|
57
54
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
console.log(
|
|
56
|
+
`→ Executing haste command: ${configObject.name || 'Unnamed Command'}`
|
|
57
|
+
);
|
|
58
|
+
console.log(`→ Using AWS profile: ${awsProfile}`);
|
|
59
|
+
console.log(`→ Using environment: ${options.stage ? 'stage' : 'dev'}`);
|
|
60
|
+
console.log('→ Environment variables:', envObj);
|
|
64
61
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
// Run preactions sequentially
|
|
63
|
+
for (const cmd of preactions) {
|
|
64
|
+
console.log(`→ pre-action: ${cmd}`);
|
|
65
|
+
await runForeground(cmd, envObj, options);
|
|
66
|
+
}
|
|
70
67
|
|
|
71
|
-
|
|
68
|
+
if (actions.length === 0) return;
|
|
72
69
|
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
const bg = actions.slice(0, -1);
|
|
71
|
+
const fg = actions[actions.length - 1];
|
|
75
72
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
for (const cmd of bg) {
|
|
74
|
+
console.log(`→ background action: ${cmd}`);
|
|
75
|
+
runBackground(cmd, envObj, options);
|
|
76
|
+
}
|
|
80
77
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
} catch (err) {
|
|
89
|
-
console.error('Error executing mono command:', err);
|
|
90
|
-
throw err;
|
|
78
|
+
console.log(`→ foreground action (attached): ${fg}`);
|
|
79
|
+
console.log('options:', options);
|
|
80
|
+
try {
|
|
81
|
+
await runBackground(fg, envObj, options, true);
|
|
82
|
+
} finally {
|
|
83
|
+
killAllBackground();
|
|
91
84
|
}
|
|
92
85
|
}
|
|
93
86
|
|