@mono-labs/cli 0.0.215 → 0.0.217
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/dist/project/index.js +67 -31
- package/dist/types/project/index.d.ts +1 -6
- package/package.json +1 -1
- package/src/project/index.ts +111 -59
package/dist/project/index.js
CHANGED
|
@@ -4,19 +4,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.loadMergedEnv = exports.loadProjectConfig = void 0;
|
|
7
|
-
exports.detectWorkspaceAndConfigPath = detectWorkspaceAndConfigPath;
|
|
8
7
|
exports.loadAppConfig = loadAppConfig;
|
|
9
8
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
10
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
const requiredSystemDefaults = {
|
|
11
|
+
ec2User: 'ec2-user',
|
|
12
|
+
regions: ['us-east-1'],
|
|
13
|
+
};
|
|
14
|
+
/* ──────────────────────────────────────────────────────────
|
|
15
|
+
* Environment helpers
|
|
16
|
+
* ────────────────────────────────────────────────────────── */
|
|
17
|
+
function isLambdaRuntime() {
|
|
18
|
+
return !!process.env.AWS_LAMBDA_FUNCTION_NAME;
|
|
19
|
+
}
|
|
20
|
+
/* ──────────────────────────────────────────────────────────
|
|
21
|
+
* Workspace detection (CLI / local dev only)
|
|
22
|
+
* ────────────────────────────────────────────────────────── */
|
|
23
|
+
function detectWorkspaceAndConfigPath(startDir, configFileName) {
|
|
17
24
|
const cwd = node_path_1.default.resolve(startDir);
|
|
18
25
|
const isWorkspaceRootDir = (dir) => {
|
|
19
|
-
// 1) package.json workspaces
|
|
20
26
|
const pkgPath = node_path_1.default.join(dir, 'package.json');
|
|
21
27
|
if (node_fs_1.default.existsSync(pkgPath)) {
|
|
22
28
|
try {
|
|
@@ -28,41 +34,71 @@ function detectWorkspaceAndConfigPath(startDir = process.cwd(), configFileName =
|
|
|
28
34
|
// ignore
|
|
29
35
|
}
|
|
30
36
|
}
|
|
31
|
-
// 2) other common monorepo root markers (fallback)
|
|
32
37
|
const markers = [
|
|
33
38
|
'pnpm-workspace.yaml',
|
|
34
39
|
'lerna.json',
|
|
35
40
|
'turbo.json',
|
|
36
41
|
'nx.json',
|
|
37
|
-
'.git',
|
|
42
|
+
'.git',
|
|
38
43
|
];
|
|
39
44
|
return markers.some((m) => node_fs_1.default.existsSync(node_path_1.default.join(dir, m)));
|
|
40
45
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
let dir = cwd;
|
|
47
|
+
while (true) {
|
|
48
|
+
if (isWorkspaceRootDir(dir)) {
|
|
49
|
+
return {
|
|
50
|
+
cwd,
|
|
51
|
+
workspaceRoot: dir,
|
|
52
|
+
isWorkspaceRoot: dir === cwd,
|
|
53
|
+
configDir: dir,
|
|
54
|
+
configPath: node_path_1.default.join(dir, configFileName),
|
|
55
|
+
};
|
|
50
56
|
}
|
|
57
|
+
const parent = node_path_1.default.dirname(dir);
|
|
58
|
+
if (parent === dir)
|
|
59
|
+
break;
|
|
60
|
+
dir = parent;
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
cwd,
|
|
64
|
+
workspaceRoot: null,
|
|
65
|
+
isWorkspaceRoot: false,
|
|
66
|
+
configDir: cwd,
|
|
67
|
+
configPath: node_path_1.default.join(cwd, configFileName),
|
|
51
68
|
};
|
|
52
|
-
const workspaceRoot = findUp(cwd, isWorkspaceRootDir);
|
|
53
|
-
const isWorkspaceRoot = workspaceRoot !== null && workspaceRoot === cwd;
|
|
54
|
-
// If we are inside a workspace package, config lives at root.
|
|
55
|
-
// If we're already at root, config lives in cwd (same thing).
|
|
56
|
-
const configDir = workspaceRoot ?? cwd;
|
|
57
|
-
const configPath = node_path_1.default.join(configDir, configFileName);
|
|
58
|
-
return { cwd, workspaceRoot, isWorkspaceRoot, configDir, configPath };
|
|
59
69
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
/* ──────────────────────────────────────────────────────────
|
|
71
|
+
* Bundled config loader (Lambda runtime)
|
|
72
|
+
* ────────────────────────────────────────────────────────── */
|
|
73
|
+
function loadConfigFromBundle(fileName) {
|
|
74
|
+
const bundledPath = node_path_1.default.join(__dirname, fileName);
|
|
75
|
+
if (node_fs_1.default.existsSync(bundledPath)) {
|
|
76
|
+
return JSON.parse(node_fs_1.default.readFileSync(bundledPath, 'utf8'));
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
/* ──────────────────────────────────────────────────────────
|
|
81
|
+
* Public API
|
|
82
|
+
* ────────────────────────────────────────────────────────── */
|
|
64
83
|
function loadAppConfig(configType = 'app', startDir = process.cwd()) {
|
|
65
84
|
const fileName = `mono.${configType}.json`;
|
|
85
|
+
// ✅ 1. Lambda runtime: load bundled config if present
|
|
86
|
+
if (isLambdaRuntime()) {
|
|
87
|
+
const bundled = loadConfigFromBundle(fileName);
|
|
88
|
+
if (bundled) {
|
|
89
|
+
return {
|
|
90
|
+
config: bundled,
|
|
91
|
+
meta: {
|
|
92
|
+
cwd: __dirname,
|
|
93
|
+
workspaceRoot: null,
|
|
94
|
+
isWorkspaceRoot: false,
|
|
95
|
+
configDir: __dirname,
|
|
96
|
+
configPath: node_path_1.default.join(__dirname, fileName),
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// ✅ 2. CLI / local dev: workspace discovery
|
|
66
102
|
const meta = detectWorkspaceAndConfigPath(startDir, fileName);
|
|
67
103
|
if (!node_fs_1.default.existsSync(meta.configPath)) {
|
|
68
104
|
const where = meta.workspaceRoot ?
|
|
@@ -72,7 +108,7 @@ function loadAppConfig(configType = 'app', startDir = process.cwd()) {
|
|
|
72
108
|
}
|
|
73
109
|
const raw = node_fs_1.default.readFileSync(meta.configPath, 'utf8');
|
|
74
110
|
const config = JSON.parse(raw);
|
|
75
|
-
// Apply
|
|
111
|
+
// ✅ Apply required system defaults
|
|
76
112
|
if (typeof config === 'object' && config !== null) {
|
|
77
113
|
for (const key of Object.keys(requiredSystemDefaults)) {
|
|
78
114
|
// @ts-ignore: index signature
|
|
@@ -5,12 +5,6 @@ type WorkspaceDetectResult = {
|
|
|
5
5
|
configDir: string;
|
|
6
6
|
configPath: string;
|
|
7
7
|
};
|
|
8
|
-
/**
|
|
9
|
-
* Finds the workspace root by walking up from `startDir`.
|
|
10
|
-
* Works for Yarn/npm workspaces via package.json "workspaces".
|
|
11
|
-
* Also recognizes common mono-repo markers as fallback.
|
|
12
|
-
*/
|
|
13
|
-
export declare function detectWorkspaceAndConfigPath(startDir?: string, configFileName?: string): WorkspaceDetectResult;
|
|
14
8
|
type DefaultAppConfig = {
|
|
15
9
|
appleAppId?: string;
|
|
16
10
|
androidAppId?: string;
|
|
@@ -27,6 +21,7 @@ type DefaultDeployConfig = {
|
|
|
27
21
|
ec2User: string;
|
|
28
22
|
defaultVpcId?: string;
|
|
29
23
|
defaultVpcSecurityGroupId?: string;
|
|
24
|
+
ec2Bridge?: string;
|
|
30
25
|
};
|
|
31
26
|
type ConfigTypeMap = {
|
|
32
27
|
app: DefaultAppConfig;
|
package/package.json
CHANGED
package/src/project/index.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
|
+
/* ──────────────────────────────────────────────────────────
|
|
5
|
+
* Types
|
|
6
|
+
* ────────────────────────────────────────────────────────── */
|
|
7
|
+
|
|
4
8
|
type WorkspaceDetectResult = {
|
|
5
9
|
cwd: string;
|
|
6
10
|
workspaceRoot: string | null;
|
|
@@ -9,64 +13,6 @@ type WorkspaceDetectResult = {
|
|
|
9
13
|
configPath: string;
|
|
10
14
|
};
|
|
11
15
|
|
|
12
|
-
/**
|
|
13
|
-
* Finds the workspace root by walking up from `startDir`.
|
|
14
|
-
* Works for Yarn/npm workspaces via package.json "workspaces".
|
|
15
|
-
* Also recognizes common mono-repo markers as fallback.
|
|
16
|
-
*/
|
|
17
|
-
export function detectWorkspaceAndConfigPath(
|
|
18
|
-
startDir: string = process.cwd(),
|
|
19
|
-
configFileName: string = 'mono.app.json'
|
|
20
|
-
): WorkspaceDetectResult {
|
|
21
|
-
const cwd = path.resolve(startDir);
|
|
22
|
-
|
|
23
|
-
const isWorkspaceRootDir = (dir: string): boolean => {
|
|
24
|
-
// 1) package.json workspaces
|
|
25
|
-
const pkgPath = path.join(dir, 'package.json');
|
|
26
|
-
if (fs.existsSync(pkgPath)) {
|
|
27
|
-
try {
|
|
28
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')) as any;
|
|
29
|
-
if (pkg?.workspaces) return true;
|
|
30
|
-
} catch {
|
|
31
|
-
// ignore
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// 2) other common monorepo root markers (fallback)
|
|
36
|
-
const markers = [
|
|
37
|
-
'pnpm-workspace.yaml',
|
|
38
|
-
'lerna.json',
|
|
39
|
-
'turbo.json',
|
|
40
|
-
'nx.json',
|
|
41
|
-
'.git', // good enough for many repos
|
|
42
|
-
];
|
|
43
|
-
return markers.some((m) => fs.existsSync(path.join(dir, m)));
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const findUp = (
|
|
47
|
-
from: string,
|
|
48
|
-
predicate: (dir: string) => boolean
|
|
49
|
-
): string | null => {
|
|
50
|
-
let dir = path.resolve(from);
|
|
51
|
-
while (true) {
|
|
52
|
-
if (predicate(dir)) return dir;
|
|
53
|
-
const parent = path.dirname(dir);
|
|
54
|
-
if (parent === dir) return null; // reached filesystem root
|
|
55
|
-
dir = parent;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const workspaceRoot = findUp(cwd, isWorkspaceRootDir);
|
|
60
|
-
const isWorkspaceRoot = workspaceRoot !== null && workspaceRoot === cwd;
|
|
61
|
-
|
|
62
|
-
// If we are inside a workspace package, config lives at root.
|
|
63
|
-
// If we're already at root, config lives in cwd (same thing).
|
|
64
|
-
const configDir = workspaceRoot ?? cwd;
|
|
65
|
-
const configPath = path.join(configDir, configFileName);
|
|
66
|
-
|
|
67
|
-
return { cwd, workspaceRoot, isWorkspaceRoot, configDir, configPath };
|
|
68
|
-
}
|
|
69
|
-
|
|
70
16
|
type DefaultAppConfig = {
|
|
71
17
|
appleAppId?: string;
|
|
72
18
|
androidAppId?: string;
|
|
@@ -84,6 +30,7 @@ type DefaultDeployConfig = {
|
|
|
84
30
|
ec2User: string;
|
|
85
31
|
defaultVpcId?: string;
|
|
86
32
|
defaultVpcSecurityGroupId?: string;
|
|
33
|
+
ec2Bridge?: string;
|
|
87
34
|
};
|
|
88
35
|
|
|
89
36
|
const requiredSystemDefaults = {
|
|
@@ -103,11 +50,115 @@ type ConfigTypeMap = {
|
|
|
103
50
|
type ResolveConfig<TType extends string, TCustom = unknown> =
|
|
104
51
|
TType extends keyof ConfigTypeMap ? ConfigTypeMap[TType] : TCustom;
|
|
105
52
|
|
|
53
|
+
/* ──────────────────────────────────────────────────────────
|
|
54
|
+
* Environment helpers
|
|
55
|
+
* ────────────────────────────────────────────────────────── */
|
|
56
|
+
|
|
57
|
+
function isLambdaRuntime(): boolean {
|
|
58
|
+
return !!process.env.AWS_LAMBDA_FUNCTION_NAME;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* ──────────────────────────────────────────────────────────
|
|
62
|
+
* Workspace detection (CLI / local dev only)
|
|
63
|
+
* ────────────────────────────────────────────────────────── */
|
|
64
|
+
|
|
65
|
+
function detectWorkspaceAndConfigPath(
|
|
66
|
+
startDir: string,
|
|
67
|
+
configFileName: string
|
|
68
|
+
): WorkspaceDetectResult {
|
|
69
|
+
const cwd = path.resolve(startDir);
|
|
70
|
+
|
|
71
|
+
const isWorkspaceRootDir = (dir: string): boolean => {
|
|
72
|
+
const pkgPath = path.join(dir, 'package.json');
|
|
73
|
+
if (fs.existsSync(pkgPath)) {
|
|
74
|
+
try {
|
|
75
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
76
|
+
if (pkg?.workspaces) return true;
|
|
77
|
+
} catch {
|
|
78
|
+
// ignore
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const markers = [
|
|
83
|
+
'pnpm-workspace.yaml',
|
|
84
|
+
'lerna.json',
|
|
85
|
+
'turbo.json',
|
|
86
|
+
'nx.json',
|
|
87
|
+
'.git',
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
return markers.some((m) => fs.existsSync(path.join(dir, m)));
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
let dir = cwd;
|
|
94
|
+
while (true) {
|
|
95
|
+
if (isWorkspaceRootDir(dir)) {
|
|
96
|
+
return {
|
|
97
|
+
cwd,
|
|
98
|
+
workspaceRoot: dir,
|
|
99
|
+
isWorkspaceRoot: dir === cwd,
|
|
100
|
+
configDir: dir,
|
|
101
|
+
configPath: path.join(dir, configFileName),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const parent = path.dirname(dir);
|
|
106
|
+
if (parent === dir) break;
|
|
107
|
+
dir = parent;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
cwd,
|
|
112
|
+
workspaceRoot: null,
|
|
113
|
+
isWorkspaceRoot: false,
|
|
114
|
+
configDir: cwd,
|
|
115
|
+
configPath: path.join(cwd, configFileName),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* ──────────────────────────────────────────────────────────
|
|
120
|
+
* Bundled config loader (Lambda runtime)
|
|
121
|
+
* ────────────────────────────────────────────────────────── */
|
|
122
|
+
|
|
123
|
+
function loadConfigFromBundle(fileName: string): unknown | null {
|
|
124
|
+
const bundledPath = path.join(__dirname, fileName);
|
|
125
|
+
|
|
126
|
+
if (fs.existsSync(bundledPath)) {
|
|
127
|
+
return JSON.parse(fs.readFileSync(bundledPath, 'utf8'));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/* ──────────────────────────────────────────────────────────
|
|
134
|
+
* Public API
|
|
135
|
+
* ────────────────────────────────────────────────────────── */
|
|
136
|
+
|
|
106
137
|
export function loadAppConfig<TCustom = unknown, TType extends string = 'app'>(
|
|
107
138
|
configType: TType = 'app' as TType,
|
|
108
139
|
startDir: string = process.cwd()
|
|
109
140
|
): { config: ResolveConfig<TType, TCustom>; meta: WorkspaceDetectResult } {
|
|
110
141
|
const fileName = `mono.${configType}.json`;
|
|
142
|
+
|
|
143
|
+
// ✅ 1. Lambda runtime: load bundled config if present
|
|
144
|
+
if (isLambdaRuntime()) {
|
|
145
|
+
const bundled = loadConfigFromBundle(fileName);
|
|
146
|
+
|
|
147
|
+
if (bundled) {
|
|
148
|
+
return {
|
|
149
|
+
config: bundled as ResolveConfig<TType, TCustom>,
|
|
150
|
+
meta: {
|
|
151
|
+
cwd: __dirname,
|
|
152
|
+
workspaceRoot: null,
|
|
153
|
+
isWorkspaceRoot: false,
|
|
154
|
+
configDir: __dirname,
|
|
155
|
+
configPath: path.join(__dirname, fileName),
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// ✅ 2. CLI / local dev: workspace discovery
|
|
111
162
|
const meta = detectWorkspaceAndConfigPath(startDir, fileName);
|
|
112
163
|
|
|
113
164
|
if (!fs.existsSync(meta.configPath)) {
|
|
@@ -115,6 +166,7 @@ export function loadAppConfig<TCustom = unknown, TType extends string = 'app'>(
|
|
|
115
166
|
meta.workspaceRoot ?
|
|
116
167
|
`workspace root: ${meta.workspaceRoot}`
|
|
117
168
|
: `cwd: ${meta.cwd}`;
|
|
169
|
+
|
|
118
170
|
throw new Error(
|
|
119
171
|
`Could not find ${fileName} at ${meta.configPath} (detected from ${where}).`
|
|
120
172
|
);
|
|
@@ -123,7 +175,7 @@ export function loadAppConfig<TCustom = unknown, TType extends string = 'app'>(
|
|
|
123
175
|
const raw = fs.readFileSync(meta.configPath, 'utf8');
|
|
124
176
|
const config = JSON.parse(raw) as ResolveConfig<TType, TCustom>;
|
|
125
177
|
|
|
126
|
-
// Apply
|
|
178
|
+
// ✅ Apply required system defaults
|
|
127
179
|
if (typeof config === 'object' && config !== null) {
|
|
128
180
|
for (const key of Object.keys(requiredSystemDefaults)) {
|
|
129
181
|
// @ts-ignore: index signature
|