@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
- const { config } = getHasteConfig();
46
- Object.entries(files).forEach(([commandName, configObject]) => {
47
- const optionsData = configObject.options || {};
48
-
49
- let current = program
50
- .command(commandName)
51
- .description(configObject.description || 'Haste command');
52
- const argInfo = configObject.argument;
53
- // Argument
54
- if (argInfo) {
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
- if (
103
- argInfo &&
104
- optionValueList &&
105
- !actualOptions.includes(arg ?? argInfo.default)
106
- ) {
107
- throw new Error(
108
- `Invalid argument value for ${commandName}, must be one of: ${actualOptions.join(
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
- optionsDataList.map((item) => {
121
- if (item.default) {
122
- envDefaults[item.name] = item.default;
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
- // optionsData
127
- // .filter((item) => item.default !== undefined)
128
- // .forEach((item) => {
129
- // envDefaults[item] = item.default;
130
- // });
116
+ const optionsDataList = Object.keys(optionsData).map((key) => ({
117
+ ...optionsData[key],
118
+ name: key,
119
+ }));
131
120
 
132
- const optionVals = { ...envDefaults, ...(cmd.opts ? cmd.opts() : cmd) };
121
+ optionsDataList.map((item) => {
122
+ if (item.default) {
123
+ envDefaults[item.name] = item.default;
124
+ }
125
+ });
133
126
 
134
- Object.keys(optionVals).forEach((k) => {
135
- optionVals[k] = verifyOptionValue(k, optionVals[k], optionsData);
136
- });
137
- optionVals['prod'] = optionVals[config.prodFlag] || false;
127
+ // optionsData
128
+ // .filter((item) => item.default !== undefined)
129
+ // .forEach((item) => {
130
+ // envDefaults[item] = item.default;
131
+ // });
138
132
 
139
- const argVal = arg || configObject.argument?.default;
133
+ const optionVals = { ...envDefaults, ...(cmd.opts ? cmd.opts() : cmd) };
140
134
 
141
- mergeData({ ...optionVals, arg: argVal });
142
- await runHasteCommand(configObject, optionVals);
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
- try {
17
- const { config } = getHasteConfig();
18
- const devConfig = configObject.environments?.dev ?? {};
16
+ const { config } = getHasteConfig();
17
+ const devConfig = configObject.environments?.dev ?? {};
19
18
 
20
- // Usage:
21
- const envPath = path.resolve(process.cwd(), '.env');
22
- const keymap = parseEnvFile(envPath);
19
+ // Usage:
20
+ const envPath = path.resolve(process.cwd(), '.env');
21
+ const keymap = parseEnvFile(envPath);
23
22
 
24
- const prodConfig = configObject.environments?.prod ?? {};
25
- const awsProfile = process.env.CDK_DEPLOY_PROFILE || 'default';
26
- const envObjBase = options.prod ? { ...prodConfig } : { ...devConfig };
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
- Object.keys(envObjBase).forEach((k) => {
29
- if (
30
- typeof envObjBase[k] === 'string' &&
31
- envObjBase[k].startsWith('$') &&
32
- !envObjBase[k].startsWith('${')
33
- ) {
34
- const refKey = envObjBase[k].substring(1);
35
- envObjBase[k] = keymap[refKey] || '';
36
- }
37
- });
38
- envObjBase.AWS_PROFILE = awsProfile;
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
- const envKeys = Object.keys(process.env).filter((k) =>
41
- k.startsWith('MONO_')
42
- );
43
- const envMapList = config.envMap ?? ['FAILURE'];
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
- envKeys.map((k) => {
48
- envMapList.map((item) => {
49
- envMapVals[k.replace('MONO', item)] = combinedEnv[k];
50
- });
44
+ envKeys.map((k) => {
45
+ envMapList.map((item) => {
46
+ envMapVals[k.replace('MONO', item)] = combinedEnv[k];
51
47
  });
48
+ });
52
49
 
53
- const envObj = { ...envObjBase, ...envMapVals };
50
+ const envObj = { ...envObjBase, ...envMapVals };
54
51
 
55
- const preactions = configObject.preactions ?? [];
56
- const actions = configObject.actions ?? [];
52
+ const preactions = configObject.preactions ?? [];
53
+ const actions = configObject.actions ?? [];
57
54
 
58
- console.log(
59
- `→ Executing haste command: ${configObject.name || 'Unnamed Command'}`
60
- );
61
- console.log(`→ Using AWS profile: ${awsProfile}`);
62
- console.log(`→ Using environment: ${options.stage ? 'stage' : 'dev'}`);
63
- console.log('→ Environment variables:', envObj);
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
- // Run preactions sequentially
66
- for (const cmd of preactions) {
67
- console.log(`→ pre-action: ${cmd}`);
68
- await runForeground(cmd, envObj, options);
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
- if (actions.length === 0) return;
68
+ if (actions.length === 0) return;
72
69
 
73
- const bg = actions.slice(0, -1);
74
- const fg = actions[actions.length - 1];
70
+ const bg = actions.slice(0, -1);
71
+ const fg = actions[actions.length - 1];
75
72
 
76
- for (const cmd of bg) {
77
- console.log(`→ background action: ${cmd}`);
78
- runBackground(cmd, envObj, options);
79
- }
73
+ for (const cmd of bg) {
74
+ console.log(`→ background action: ${cmd}`);
75
+ runBackground(cmd, envObj, options);
76
+ }
80
77
 
81
- console.log(`→ foreground action (attached): ${fg}`);
82
- console.log('options:', options);
83
- try {
84
- await runBackground(fg, envObj, options, true);
85
- } finally {
86
- killAllBackground();
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mono-labs/cli",
3
- "version": "0.0.157",
3
+ "version": "0.0.159",
4
4
  "description": "A CLI tool for building and deploying projects",
5
5
  "type": "module",
6
6
  "main": "index.js",