@mono-labs/cli 0.0.238 → 0.0.242

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.
Files changed (179) hide show
  1. package/bin/mono.js +1 -1
  2. package/dist/index.js +32 -51
  3. package/dist/lib/app.js +52 -0
  4. package/dist/lib/commands/build-process/boot.js +12 -0
  5. package/dist/lib/commands/build-process/cliFactory.js +145 -0
  6. package/dist/lib/commands/build-process/dataLayer.js +56 -0
  7. package/dist/lib/commands/build-process/index.js +11 -0
  8. package/dist/lib/commands/build-process/readEnv.js +34 -0
  9. package/dist/lib/commands/build-process/runMonoCommand.js +82 -0
  10. package/dist/lib/commands/build-process/runners/processManager.js +45 -0
  11. package/dist/lib/commands/build-process/runners/runBackground.js +46 -0
  12. package/dist/lib/commands/build-process/runners/runForeground.js +52 -0
  13. package/dist/lib/commands/build-process/test.js +32 -0
  14. package/dist/lib/commands/build-process/testflag.js +4 -0
  15. package/dist/lib/commands/build-process/validators.js +17 -0
  16. package/dist/lib/commands/loadFromRoot.js +53 -0
  17. package/dist/lib/commands/prune/index.js +10 -0
  18. package/dist/lib/commands/prune/prune.js +49 -0
  19. package/dist/lib/config.js +6 -0
  20. package/dist/lib/filterUnwantedEnvVars.js +88 -0
  21. package/dist/lib/generateNewEnvList.js +17 -0
  22. package/dist/lib/index.js +49 -0
  23. package/dist/src/cdk/cdk.js +6 -0
  24. package/dist/src/cdk/index.js +17 -0
  25. package/dist/{expo.js → src/expo.js} +18 -34
  26. package/dist/src/index.js +56 -0
  27. package/dist/src/merge-env.js +25 -0
  28. package/dist/{project → src/project}/build-mono-readme.js +11 -20
  29. package/dist/{project → src/project}/generate-readme.js +6 -13
  30. package/dist/{project → src/project}/index.js +4 -12
  31. package/dist/{stack.js → src/stack.js} +2 -2
  32. package/dist/src/tools.js +39 -0
  33. package/dist/types/index.d.ts +50 -9
  34. package/dist/types/lib/app.d.ts +3 -0
  35. package/dist/types/lib/commands/build-process/boot.d.ts +8 -0
  36. package/dist/types/lib/commands/build-process/cliFactory.d.ts +32 -0
  37. package/dist/types/lib/commands/build-process/dataLayer.d.ts +7 -0
  38. package/dist/types/lib/commands/build-process/readEnv.d.ts +1 -0
  39. package/dist/types/lib/commands/build-process/runMonoCommand.d.ts +10 -0
  40. package/dist/types/lib/commands/build-process/runners/processManager.d.ts +5 -0
  41. package/dist/types/lib/commands/build-process/runners/runBackground.d.ts +2 -0
  42. package/dist/types/lib/commands/build-process/runners/runForeground.d.ts +6 -0
  43. package/dist/types/lib/commands/build-process/test.d.ts +1 -0
  44. package/dist/types/lib/commands/build-process/testflag.d.ts +1 -0
  45. package/dist/types/lib/commands/build-process/validators.d.ts +1 -0
  46. package/dist/types/lib/commands/loadFromRoot.d.ts +7 -0
  47. package/dist/types/lib/commands/prune/prune.d.ts +1 -0
  48. package/dist/types/lib/config.d.ts +2 -0
  49. package/dist/types/lib/filterUnwantedEnvVars.d.ts +2 -0
  50. package/dist/types/lib/generateNewEnvList.d.ts +1 -0
  51. package/dist/types/lib/index.d.ts +2 -0
  52. package/dist/types/src/cdk/cdk.d.ts +1 -0
  53. package/dist/types/src/cdk/index.d.ts +1 -0
  54. package/dist/types/src/expo.d.ts +4 -0
  55. package/dist/types/src/index.d.ts +15 -0
  56. package/dist/types/src/project/build-mono-readme.d.ts +1 -0
  57. package/dist/types/src/project/generate-readme.d.ts +1 -0
  58. package/dist/types/{project → src/project}/index.d.ts +1 -1
  59. package/dist/types/src/project/merge-env.d.ts +1 -0
  60. package/dist/types/src/tools.d.ts +3 -0
  61. package/lib/app.d.ts +3 -0
  62. package/lib/app.ts +58 -0
  63. package/lib/commands/build-process/boot.d.ts +8 -0
  64. package/lib/commands/build-process/boot.ts +21 -0
  65. package/lib/commands/build-process/cliFactory.d.ts +32 -0
  66. package/lib/commands/build-process/cliFactory.ts +219 -0
  67. package/lib/commands/build-process/dataLayer.d.ts +7 -0
  68. package/lib/commands/build-process/dataLayer.ts +61 -0
  69. package/lib/commands/build-process/index.d.ts +1 -0
  70. package/lib/commands/build-process/index.ts +14 -0
  71. package/lib/commands/build-process/readEnv.d.ts +1 -0
  72. package/lib/commands/build-process/readEnv.ts +37 -0
  73. package/lib/commands/build-process/runMonoCommand.d.ts +10 -0
  74. package/lib/commands/build-process/runMonoCommand.ts +96 -0
  75. package/lib/commands/build-process/runners/processManager.d.ts +5 -0
  76. package/lib/commands/build-process/runners/processManager.ts +42 -0
  77. package/lib/commands/build-process/runners/runBackground.d.ts +2 -0
  78. package/lib/commands/build-process/runners/runBackground.ts +56 -0
  79. package/lib/commands/build-process/runners/runForeground.d.ts +6 -0
  80. package/lib/commands/build-process/runners/runForeground.ts +59 -0
  81. package/lib/commands/build-process/test.d.ts +1 -0
  82. package/lib/commands/build-process/test.ts +42 -0
  83. package/lib/commands/build-process/testflag.d.ts +1 -0
  84. package/lib/commands/build-process/testflag.ts +1 -0
  85. package/lib/commands/build-process/validators.d.ts +1 -0
  86. package/lib/commands/build-process/validators.ts +16 -0
  87. package/lib/commands/loadFromRoot.d.ts +7 -0
  88. package/lib/commands/loadFromRoot.ts +51 -0
  89. package/lib/commands/prune/index.d.ts +1 -0
  90. package/lib/commands/prune/index.ts +9 -0
  91. package/lib/commands/prune/prune.d.ts +1 -0
  92. package/lib/commands/prune/prune.ts +50 -0
  93. package/lib/config.d.ts +2 -0
  94. package/lib/filterUnwantedEnvVars.d.ts +2 -0
  95. package/lib/filterUnwantedEnvVars.ts +95 -0
  96. package/lib/generateNewEnvList.d.ts +1 -0
  97. package/lib/generateNewEnvList.ts +17 -0
  98. package/lib/index.d.ts +2 -0
  99. package/lib/index.ts +59 -0
  100. package/package.json +99 -84
  101. package/src/cdk/cdk.d.ts +1 -7
  102. package/src/cdk/cdk.ts +1 -0
  103. package/src/cdk/index.d.ts +1 -0
  104. package/src/cdk/index.ts +1 -0
  105. package/src/expo-files/filterUnwantedEnvVars.d.ts +3 -0
  106. package/src/expo-files/filterUnwantedEnvVars.ts +141 -144
  107. package/src/expo.d.ts +2 -9
  108. package/src/expo.ts +116 -0
  109. package/src/index.d.ts +22 -0
  110. package/src/index.ts +39 -42
  111. package/src/loadFromRoot.d.ts +32 -0
  112. package/src/merge-env.d.ts +1 -0
  113. package/src/merge-env.ts +24 -0
  114. package/src/project/build-mono-readme.d.ts +1 -0
  115. package/src/project/build-mono-readme.ts +460 -514
  116. package/src/project/build-readme.d.ts +2 -0
  117. package/src/project/generate-docs.d.ts +11 -0
  118. package/src/project/generate-readme.d.ts +1 -0
  119. package/src/project/generate-readme.ts +259 -284
  120. package/src/project/index.d.ts +45 -0
  121. package/src/project/index.ts +134 -144
  122. package/src/project/merge-env.d.ts +1 -0
  123. package/src/stack.d.ts +21 -0
  124. package/src/stack.ts +54 -55
  125. package/src/tools.d.ts +3 -4
  126. package/src/tools.ts +48 -0
  127. package/src/types/expo-config.d.ts +49 -0
  128. package/dist/cdk/index.js +0 -55
  129. package/dist/project/merge-env.js +0 -31
  130. package/dist/tools.js +0 -35
  131. package/dist/types/cdk/index.d.ts +0 -2
  132. package/dist/types/expo.d.ts +0 -3
  133. package/dist/types/merge-env.d.ts +0 -1
  134. package/dist/types/tools.d.ts +0 -1
  135. package/lib/app.js +0 -49
  136. package/lib/commands/build-process/boot.js +0 -15
  137. package/lib/commands/build-process/cliFactory.js +0 -163
  138. package/lib/commands/build-process/dataLayer.js +0 -59
  139. package/lib/commands/build-process/index.js +0 -13
  140. package/lib/commands/build-process/readEnv.js +0 -37
  141. package/lib/commands/build-process/runMonoCommand.js +0 -102
  142. package/lib/commands/build-process/runners/processManager.js +0 -38
  143. package/lib/commands/build-process/runners/runBackground.js +0 -60
  144. package/lib/commands/build-process/runners/runForeground.js +0 -60
  145. package/lib/commands/build-process/test.js +0 -50
  146. package/lib/commands/build-process/testflag.js +0 -1
  147. package/lib/commands/build-process/validators.js +0 -17
  148. package/lib/commands/generate/generateSeed.js +0 -223
  149. package/lib/commands/generate/index.js +0 -30
  150. package/lib/commands/loadFromRoot.js +0 -55
  151. package/lib/commands/prune/index.js +0 -12
  152. package/lib/commands/prune/prune.js +0 -50
  153. package/lib/commands/seed/import.js +0 -30
  154. package/lib/commands/seed/index.js +0 -12
  155. package/lib/commands/submit/index.js +0 -38
  156. package/lib/commands/update/eas.js +0 -39
  157. package/lib/commands/update/index.js +0 -87
  158. package/lib/filterUnwantedEnvVars.js +0 -123
  159. package/lib/generateNewEnvList.js +0 -14
  160. package/lib/index.js +0 -58
  161. package/src/cdk/index.js +0 -59
  162. package/src/expo.js +0 -133
  163. package/src/merge-env.js +0 -32
  164. package/src/tools.js +0 -36
  165. package/types.d.ts +0 -83
  166. /package/dist/{expo-files → src/expo-files}/filterUnwantedEnvVars.js +0 -0
  167. /package/dist/{loadFromRoot.js → src/loadFromRoot.js} +0 -0
  168. /package/dist/{project → src/project}/build-readme.js +0 -0
  169. /package/dist/{project → src/project}/generate-docs.js +0 -0
  170. /package/dist/{merge-env.js → src/project/merge-env.js} +0 -0
  171. /package/dist/types/{project/build-mono-readme.d.ts → lib/commands/build-process/index.d.ts} +0 -0
  172. /package/dist/types/{project/generate-readme.d.ts → lib/commands/prune/index.d.ts} +0 -0
  173. /package/dist/types/{expo-files → src/expo-files}/filterUnwantedEnvVars.d.ts +0 -0
  174. /package/dist/types/{loadFromRoot.d.ts → src/loadFromRoot.d.ts} +0 -0
  175. /package/dist/types/{project → src}/merge-env.d.ts +0 -0
  176. /package/dist/types/{project → src/project}/build-readme.d.ts +0 -0
  177. /package/dist/types/{project → src/project}/generate-docs.d.ts +0 -0
  178. /package/dist/types/{stack.d.ts → src/stack.d.ts} +0 -0
  179. /package/lib/{config.js → config.ts} +0 -0
package/dist/cdk/index.js DELETED
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.replaceTokens = replaceTokens;
4
- exports.setUpConfig = setUpConfig;
5
- function replaceTokens(str, env) {
6
- if (typeof str !== 'string')
7
- return str;
8
- return str.replace(/\$\{([^}]+)\}|\$([A-Z0-9_]+)/g, (m, k1, k2) => {
9
- const k = k1 || k2;
10
- // existing data layer takes priority (guarded in case not defined)
11
- if (typeof hasData === 'function' && hasData(k)) {
12
- const val = typeof getData === 'function' ? getData(k) : undefined;
13
- return val == null ? '' : String(val);
14
- }
15
- // environment variables
16
- if (env && Object.prototype.hasOwnProperty.call(env, k)) {
17
- const val = env[k];
18
- return val == null ? '' : String(val);
19
- }
20
- // fallback
21
- return '';
22
- });
23
- }
24
- function filterEnvByPrefix(env, prefix) {
25
- const filtered = {};
26
- for (const key in env) {
27
- if (key.startsWith(prefix)) {
28
- filtered[key] = env[key];
29
- }
30
- }
31
- return filtered;
32
- }
33
- function setUpConfig(config) {
34
- const { extra = {}, ...other } = config.expo || {};
35
- const router = extra['router'] ?
36
- { origin: false, ...extra['router'] }
37
- : {
38
- origin: false,
39
- };
40
- const appConfig = {
41
- ...config,
42
- expo: {
43
- ...other,
44
- extra: {
45
- ...filterEnvByPrefix(process.env, 'NEXT_PUBLIC_'),
46
- eas: {
47
- projectId: process.env.EAS_PROJECT_ID,
48
- },
49
- router,
50
- ...extra,
51
- },
52
- },
53
- };
54
- return appConfig;
55
- }
@@ -1,31 +0,0 @@
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.loadMergedEnv = loadMergedEnv;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const dotenv_1 = __importDefault(require("dotenv"));
10
- function loadMergedEnv() {
11
- const ENV_PATH = path_1.default.resolve(process.cwd(), '.env');
12
- const ENV_LOCAL_PATH = path_1.default.resolve(process.cwd(), '.env.local');
13
- // Load base .env
14
- const base = fs_1.default.existsSync(ENV_PATH) ? dotenv_1.default.parse(fs_1.default.readFileSync(ENV_PATH)) : {};
15
- // Load overrides .env.local
16
- const local = fs_1.default.existsSync(ENV_LOCAL_PATH) ?
17
- dotenv_1.default.parse(fs_1.default.readFileSync(ENV_LOCAL_PATH))
18
- : {};
19
- // Merge: local overrides base
20
- const merged = {
21
- ...base,
22
- ...local,
23
- };
24
- // Inject into process.env (do NOT overwrite existing real env vars)
25
- for (const [key, value] of Object.entries(merged)) {
26
- if (process.env[key] === undefined) {
27
- process.env[key] = value;
28
- }
29
- }
30
- return process.env;
31
- }
package/dist/tools.js DELETED
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setUpConfig = setUpConfig;
4
- function filterEnvByPrefix(env, prefix) {
5
- const filtered = {};
6
- for (const key in env) {
7
- if (key.startsWith(prefix)) {
8
- filtered[key] = env[key];
9
- }
10
- }
11
- return filtered;
12
- }
13
- function setUpConfig(config) {
14
- const { extra = {}, ...other } = config.expo || {};
15
- const router = extra['router'] ?
16
- { origin: false, ...extra['router'] }
17
- : {
18
- origin: false,
19
- };
20
- const appConfig = {
21
- ...config,
22
- expo: {
23
- ...other,
24
- extra: {
25
- ...filterEnvByPrefix(process.env, 'NEXT_PUBLIC_'),
26
- eas: {
27
- projectId: process.env.EAS_PROJECT_ID,
28
- },
29
- router,
30
- ...extra,
31
- },
32
- },
33
- };
34
- return appConfig;
35
- }
@@ -1,2 +0,0 @@
1
- export function replaceTokens(str: any, env: any): any;
2
- export function setUpConfig(config: any): any;
@@ -1,3 +0,0 @@
1
- export function replaceTokens(str: any, env: any): any;
2
- export function setUpConfig(config: any): any;
3
- export function filterUnwantedEnvVarsEAS(env: any): {};
@@ -1 +0,0 @@
1
- export function loadMergedEnv(): NodeJS.ProcessEnv;
@@ -1 +0,0 @@
1
- export function setUpConfig(config: any): any;
package/lib/app.js DELETED
@@ -1,49 +0,0 @@
1
- import { Command } from 'commander';
2
-
3
- import { STAGING_URL } from './config.js';
4
-
5
- import fs from 'node:fs';
6
- import { fileURLToPath } from 'node:url';
7
- import { dirname, join } from 'node:path';
8
-
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = dirname(__filename);
11
-
12
- const pkgPath = join(__dirname, '../', 'package.json');
13
- const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
14
-
15
- const version = pkg.version || '0.0.1';
16
- export const program = new Command();
17
-
18
- const getBinFromPackageJSON = () => {
19
- const keyList = Object.keys(pkg.bin);
20
- if (keyList.length === 0) {
21
- throw new Error('No bin field found in package.json');
22
- }
23
- return keyList[0];
24
- };
25
-
26
- const programName = getBinFromPackageJSON();
27
-
28
- program
29
- .name(programName)
30
- .description(pkg.description || '')
31
- .version(version);
32
- const NEXT_PUBLIC_API_URL =
33
- (process.env.NEXT_PUBLIC_API_URL &&
34
- process.env.NEXT_PUBLIC_API_URL.length > 0) ||
35
- STAGING_URL;
36
-
37
- export const generateEnvValues = (
38
- forceProd = false,
39
- ngrokUrl = 'localhost:3000',
40
- useAtlas = false
41
- ) => {
42
- return {
43
- ...process.env,
44
- NEXT_PUBLIC_API_URL,
45
- NEXT_FORCE_PROD: forceProd,
46
- EXPO_PRIVATE_API_URL: ngrokUrl,
47
- EXPO_UNSTABLE_ATLAS: useAtlas,
48
- };
49
- };
@@ -1,15 +0,0 @@
1
- // Boot logic: load root + mono configuration
2
- import {
3
- getMonoConfig,
4
- getRootDirectory,
5
- getRootJson,
6
- } from '../loadFromRoot.js';
7
-
8
- export function boot() {
9
- const rootDir = getRootDirectory();
10
- const rootJson = getRootJson();
11
- const { files, config } = getMonoConfig();
12
- return { rootDir, rootJson, files, config };
13
- }
14
-
15
- export default boot;
@@ -1,163 +0,0 @@
1
- import { program } from '../../app.js';
2
- import { Command } from 'commander';
3
- import runMonoCommand from './runMonoCommand.js';
4
- import { verifyOptionValue } from './validators.js';
5
- import { mergeData, setData } from './dataLayer.js';
6
- import { getMonoConfig } from '../loadFromRoot.js';
7
- import { pruneRepo } from '../prune/prune.js';
8
- import { testFlag } from './testflag.js';
9
- /**
10
- * Register commander commands for each mono file definition.
11
- * Handles argument, options, validation, and action wiring.
12
- */
13
- export function createConfigCommands() {
14
- const config = new Command('config').description('Manage configuration');
15
-
16
- config
17
- .command('set <key> <value>')
18
- .description('Set a configuration value')
19
- .action((key, value) => {});
20
-
21
- config
22
- .command('get <key>')
23
- .description('Get a configuration value')
24
- .action((key) => {});
25
-
26
- config
27
- .command('list')
28
- .description('List all configuration values')
29
- .action(() => {});
30
-
31
- return config;
32
- }
33
-
34
- export function createCliCommands() {
35
- const tools = new Command('tools').description('Manage tools');
36
-
37
- tools
38
- .command('prune')
39
- .description('Prune unused branches in git')
40
- .action(() => {});
41
-
42
- return tools;
43
- }
44
-
45
- export function buildCommands(files) {
46
- try {
47
- const { config } = getMonoConfig();
48
- Object.entries(files).forEach(([commandName, configObject]) => {
49
- const optionsData = configObject.options || {};
50
-
51
- let current = program
52
- .command(commandName)
53
- .description(configObject.description || 'Mono command');
54
- const argInfo = configObject.argument;
55
- // Argument
56
- if (argInfo) {
57
- const required = !!argInfo.required;
58
- const type = argInfo.type || 'string';
59
- const argSpec = required ? `<${type}>` : `[${type}]`;
60
- current = current.argument(argSpec, argInfo.description || '');
61
- }
62
- if (testFlag)
63
- console.log(
64
- 'firstConfigObject:',
65
- JSON.stringify(configObject, null, 2)
66
- );
67
-
68
- // Options
69
- Object.entries(optionsData).forEach(([optionKey, meta]) => {
70
- const type = meta.type || 'boolean';
71
- const shortcut = meta.shortcut ? `-${meta.shortcut}, ` : '';
72
- if (type === 'string') {
73
- current = current.option(
74
- `${shortcut}--${optionKey} <${optionKey}>`,
75
- meta.description || ''
76
- );
77
- //if (meta.default !== undefined) setData(optionKey, meta.default);
78
- } else {
79
- current = current.option(
80
- `${shortcut}--${optionKey}`,
81
- meta.description || ''
82
- );
83
- //if (meta.default !== undefined) setData(optionKey, meta.default);
84
- }
85
- });
86
- config.prodFlag = config.prodFlag || 'prod';
87
-
88
- current = current.option(
89
- `--${config.prodFlag}`,
90
- 'Process execution mode: prduction or dev',
91
- false
92
- );
93
-
94
- current.action(async (arg, cmd) => {
95
- let envDefaults = {};
96
- const optionValueList = argInfo.options;
97
- let actualOptions = optionValueList;
98
- if (optionValueList) {
99
- actualOptions =
100
- argInfo?.allowAll ?
101
- [...optionValueList, 'all']
102
- : [...optionValueList];
103
- }
104
-
105
- if (argInfo) {
106
- if (
107
- argInfo &&
108
- optionValueList &&
109
- !actualOptions.includes(arg ?? argInfo.default)
110
- ) {
111
- throw new Error(
112
- `Invalid argument value for ${commandName}, must be one of: ${actualOptions.join(
113
- ', '
114
- )}`
115
- );
116
- }
117
- }
118
-
119
- const optionsDataList = Object.keys(optionsData).map((key) => ({
120
- ...optionsData[key],
121
- name: key,
122
- }));
123
-
124
- optionsDataList.map((item) => {
125
- if (item.default) {
126
- envDefaults[item.name] = item.default;
127
- }
128
- });
129
-
130
- // optionsData
131
- // .filter((item) => item.default !== undefined)
132
- // .forEach((item) => {
133
- // envDefaults[item] = item.default;
134
- // });
135
-
136
- try {
137
- const optionVals = {
138
- ...envDefaults,
139
- ...(cmd.opts ? cmd.opts() : cmd),
140
- };
141
-
142
- Object.keys(optionVals).forEach((k) => {
143
- optionVals[k] = verifyOptionValue(k, optionVals[k], optionsData);
144
- });
145
- optionVals['prod'] = optionVals[config.prodFlag] || false;
146
-
147
- const argVal = arg || configObject.argument?.default;
148
-
149
- console.log('defualts', optionVals);
150
-
151
- mergeData({ ...optionVals, arg: argVal });
152
- await runMonoCommand(configObject, optionVals);
153
- } catch (err) {
154
- console.error('Error executing mono command:', err.message);
155
- }
156
- });
157
- });
158
- } catch (err) {
159
- console.error('Error executing mono command:', err.message);
160
- }
161
- }
162
-
163
- export default buildCommands;
@@ -1,59 +0,0 @@
1
- // Shared mutable key/value store for build-process commands.
2
- // Extracts dynamic values from preactions and holds defaults from options.
3
-
4
- import { testFlag } from './testflag.js';
5
-
6
- const dataLayer = {};
7
-
8
- export function setData(key, value) {
9
- if (testFlag) {
10
- console.log(`→ dataLayer set: ${key} = ${value}`);
11
- }
12
- if (value !== undefined) dataLayer[key] = value;
13
- }
14
-
15
- export function mergeData(obj = {}) {
16
- if (testFlag) {
17
- console.log(`→ dataLayer mergeData: ${JSON.stringify(obj)}`);
18
- }
19
- Object.entries(obj).forEach(([k, v]) => setData(k, v));
20
- return dataLayer;
21
- }
22
-
23
- export function getData(key) {
24
- if (testFlag) {
25
- console.log(`→ dataLayer get: ${key}`);
26
- }
27
- return key ? dataLayer[key] : dataLayer;
28
- }
29
-
30
- export function hasData(key) {
31
- return Object.prototype.hasOwnProperty.call(dataLayer, key);
32
- }
33
-
34
- export function replaceTokens(str, env) {
35
- if (typeof str !== 'string') return str;
36
-
37
- console.log('→ replaceTokens called');
38
- console.log('dataLayer:', dataLayer);
39
- return str.replace(/\$\{([^}]+)\}|\$([A-Z0-9_]+)/g, (m, k1, k2) => {
40
- const k = k1 || k2;
41
-
42
- // existing data layer takes priority (guarded in case not defined)
43
- if (typeof hasData === 'function' && hasData(k)) {
44
- const val = typeof getData === 'function' ? getData(k) : undefined;
45
- return val == null ? '' : String(val);
46
- }
47
-
48
- // environment variables
49
- if (env && Object.prototype.hasOwnProperty.call(env, k)) {
50
- const val = env[k];
51
- return val == null ? '' : String(val);
52
- }
53
-
54
- // fallback
55
- return '';
56
- });
57
- }
58
-
59
- export default dataLayer;
@@ -1,13 +0,0 @@
1
- // Orchestrator for modular build-process command system.
2
- import { boot } from './boot.js';
3
- import { buildCommands, createCliCommands } from './cliFactory.js';
4
- import { ensureSignalHandlers } from './runners/processManager.js';
5
- import { program } from '../../app.js';
6
-
7
- const { files, config, rootDir } = boot();
8
-
9
- ensureSignalHandlers();
10
- buildCommands(files);
11
- program.addCommand(createCliCommands());
12
-
13
- // (No direct export; importing this file registers commands on the shared commander program.)
@@ -1,37 +0,0 @@
1
- // scripts/read-env.mjs
2
- import fs from 'node:fs';
3
-
4
- export function parseEnvFile(filePath) {
5
- if (!fs.existsSync(filePath)) {
6
- return {};
7
- }
8
-
9
- const content = fs.readFileSync(filePath, 'utf8');
10
-
11
- const keymap = {};
12
- for (const line of content.split(/\r?\n/)) {
13
- const trimmed = line.trim();
14
-
15
- // skip empty lines and comments
16
- if (!trimmed || trimmed.startsWith('#')) continue;
17
-
18
- // split on first "=" only
19
- const idx = trimmed.indexOf('=');
20
- if (idx === -1) continue;
21
-
22
- const key = trimmed.slice(0, idx).trim();
23
- let value = trimmed.slice(idx + 1).trim();
24
-
25
- // strip surrounding quotes if present
26
- if (
27
- (value.startsWith('"') && value.endsWith('"')) ||
28
- (value.startsWith("'") && value.endsWith("'"))
29
- ) {
30
- value = value.slice(1, -1);
31
- }
32
-
33
- keymap[key] = value;
34
- }
35
-
36
- return keymap;
37
- }
@@ -1,102 +0,0 @@
1
- import { runForeground } from './runners/runForeground.js';
2
- import { runBackground } from './runners/runBackground.js';
3
- import { killAllBackground } from './runners/processManager.js';
4
- import { getMonoConfig } from '../loadFromRoot.js';
5
- import { parseEnvFile } from './readEnv.js';
6
- import path from 'node:path';
7
- import { testFlag } from './testflag.js';
8
-
9
- export function getAllowAllKeys(cfg) {
10
- const decls = cfg.options ?? {};
11
- return Object.entries(decls)
12
- .filter(
13
- ([, v]) =>
14
- Boolean(v?.allowAll) &&
15
- Array.isArray(v?.options) &&
16
- v.options.length > 0
17
- )
18
- .map(([k]) => k);
19
- }
20
-
21
- /**
22
- * Orchestrate execution of a single mono command definition.
23
- * Phases:
24
- * 1. Preactions (sequential, blocking) via runForeground
25
- * 2. Actions (background except last; last attached) via runBackground
26
- * Environment selection based on --stage flag and injection of AWS_PROFILE.
27
- */
28
- export async function runMonoCommand(configObject, options = {}) {
29
- const { config } = getMonoConfig();
30
- const devConfig = configObject.environments?.dev ?? {};
31
-
32
- // Usage:
33
- const envPath = path.resolve(process.cwd(), '.env');
34
- const keymap = parseEnvFile(envPath);
35
-
36
- const prodConfig = configObject.environments?.prod ?? {};
37
- const awsProfile = process.env.CDK_DEPLOY_PROFILE || 'default';
38
- const envObjBase = options.prod ? { ...prodConfig } : { ...devConfig };
39
-
40
- Object.keys(envObjBase).forEach((k) => {
41
- if (
42
- typeof envObjBase[k] === 'string' &&
43
- envObjBase[k].startsWith('$') &&
44
- !envObjBase[k].startsWith('${')
45
- ) {
46
- const refKey = envObjBase[k].substring(1);
47
- envObjBase[k] = keymap[refKey] || '';
48
- }
49
- });
50
- envObjBase.AWS_PROFILE = awsProfile;
51
-
52
- const envKeys = Object.keys(process.env).filter((k) => k.startsWith('MONO_'));
53
- const envMapList = config.envMap ?? ['FAILURE'];
54
- const combinedEnv = { ...process.env, ...envObjBase };
55
- let envMapVals = {};
56
-
57
- envKeys.map((k) => {
58
- envMapList.map((item) => {
59
- envMapVals[k.replace('MONO', item)] = combinedEnv[k];
60
- });
61
- });
62
-
63
- const envObj = { ...envObjBase, ...envMapVals };
64
-
65
- const preactions = configObject.preactions ?? [];
66
- const actions = configObject.actions ?? [];
67
-
68
- console.log(
69
- `→ Executing mono command: ${configObject.name || 'Unnamed Command'}`
70
- );
71
- console.log(`→ Using AWS profile: ${awsProfile}`);
72
- console.log(`→ Using environment: ${options.stage ? 'stage' : 'dev'}`);
73
- console.log('→ Environment variables:', envObj);
74
-
75
- // Run preactions sequentially
76
- for (const cmd of preactions) {
77
- await runForeground(cmd, envObj, 'pre-action');
78
- }
79
-
80
- if (actions.length === 0) return;
81
-
82
- const bg = actions.slice(0, -1);
83
- const fg = actions[actions.length - 1];
84
-
85
- for (const cmd of bg) {
86
- runBackground(cmd, envObj, 'background');
87
- }
88
- if (testFlag) {
89
- console.log(`→ foreground action (attached): ${fg}`);
90
- console.log('options:', options);
91
- console.log('secondConfigObject:', JSON.stringify(configObject, null, 2));
92
- console.log('config', JSON.stringify(configObject.options || {}, null, 2));
93
- }
94
-
95
- try {
96
- await runBackground(fg, envObj, 'foreground', true);
97
- } finally {
98
- killAllBackground();
99
- }
100
- }
101
-
102
- export default runMonoCommand;
@@ -1,38 +0,0 @@
1
- import { spawn } from 'child_process';
2
-
3
- // Track background processes so we can kill them on exit
4
- export const bgChildren = new Set();
5
-
6
- export function registerBackground(child) {
7
- bgChildren.add(child);
8
- }
9
-
10
- export function killAllBackground() {
11
- for (const child of Array.from(bgChildren)) {
12
- try {
13
- if (process.platform === 'win32') {
14
- spawn('taskkill', ['/PID', String(child.pid), '/T', '/F'], {
15
- shell: true,
16
- stdio: 'ignore',
17
- });
18
- } else {
19
- process.kill(-child.pid, 'SIGTERM');
20
- }
21
- } catch {}
22
- }
23
- bgChildren.clear();
24
- }
25
-
26
- let signalsRegistered = false;
27
- export function ensureSignalHandlers() {
28
- if (signalsRegistered) return;
29
- signalsRegistered = true;
30
- process.on('SIGINT', () => {
31
- killAllBackground();
32
- process.exit(130);
33
- });
34
- process.on('SIGTERM', () => {
35
- killAllBackground();
36
- process.exit(143);
37
- });
38
- }
@@ -1,60 +0,0 @@
1
- import { spawn } from 'child_process';
2
- import { getData, replaceTokens } from '../dataLayer.js';
3
- import { registerBackground } from './processManager.js';
4
- import os from 'node:os';
5
- import path from 'node:path';
6
- const homeBin = path.join(os.homedir(), 'bin');
7
- const PATH = [homeBin, process.env.PATH].filter(Boolean).join(path.delimiter);
8
- function createdExpandedEnv(envObj) {
9
- const expandedEnv = {};
10
- for (const k of Object.keys(envObj)) {
11
- const v = envObj[k];
12
- expandedEnv[k] = typeof v === 'string' ? replaceTokens(v) : v;
13
- }
14
- return expandedEnv;
15
- }
16
-
17
- export function runBackground(
18
- cmd,
19
- envObj = {},
20
- logName = 'background',
21
- attached = false
22
- ) {
23
- const isWin = process.platform === 'win32';
24
-
25
- // Replace ${field} tokens in env values using dataLayer
26
-
27
- const expandedEnv = createdExpandedEnv(envObj);
28
-
29
- // Replace in command string
30
- const outCmd = replaceTokens(cmd);
31
- console.log(`→ ${logName} action ${attached ? '(attached)' : ''}: ${outCmd}`);
32
-
33
- return new Promise((resolve, reject) => {
34
- const child = spawn(outCmd, {
35
- shell: true,
36
- stdio: attached ? 'inherit' : 'ignore',
37
- //env: { ...process.env, ...expandedEnv, PATH },
38
- env: { ...process.env, ...expandedEnv },
39
- detached: !attached && !isWin,
40
- windowsHide: !attached && isWin,
41
- });
42
-
43
- if (!attached && !isWin) child.unref();
44
-
45
- registerBackground(child);
46
-
47
- child.once('error', (err) => {
48
- reject(err);
49
- });
50
-
51
- child.once('exit', (code, signal) => {
52
- if (signal)
53
- return reject(new Error(`${cmd} exited via signal ${signal}`));
54
- if (code === 0) return resolve();
55
- reject(new Error(`${cmd} exited with code ${code}`));
56
- });
57
- });
58
- }
59
-
60
- export default runBackground;