@mono-labs/cli 0.0.179 → 0.0.181
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/package.json +11 -1
- package/src/cdk/index.js +59 -0
- package/src/expo.d.ts +7 -0
- package/src/stack.ts +76 -0
- /package/src/{expo.ts → cdk/cdk.d.ts} +0 -0
- /package/src/{tools.ts → tools.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mono-labs/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.181",
|
|
4
4
|
"description": "A CLI tool for building and deploying projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -17,6 +17,14 @@
|
|
|
17
17
|
"./tools": {
|
|
18
18
|
"types": "./src/tools.d.ts",
|
|
19
19
|
"default": "./src/tools.js"
|
|
20
|
+
},
|
|
21
|
+
"./cdk": {
|
|
22
|
+
"types": "./src/cdk/cdk.d.ts",
|
|
23
|
+
"default": "./src/cdk/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./stacks": {
|
|
26
|
+
"types": "./src/stack.ts",
|
|
27
|
+
"default": "./src/stack.ts"
|
|
20
28
|
}
|
|
21
29
|
},
|
|
22
30
|
"repository": {
|
|
@@ -53,8 +61,10 @@
|
|
|
53
61
|
"dependencies": {
|
|
54
62
|
"@aws-sdk/client-dynamodb": "^3.848.0",
|
|
55
63
|
"@aws-sdk/util-dynamodb": "^3.848.0",
|
|
64
|
+
"aws-cdk-lib": "^2.235.0",
|
|
56
65
|
"chalk": "^4.1.2",
|
|
57
66
|
"commander": "^11.1.0",
|
|
67
|
+
"constructs": "^10.4.5",
|
|
58
68
|
"cross-spawn": "^7.0.6",
|
|
59
69
|
"dotenv": "^17.2.0",
|
|
60
70
|
"inquirer": "^12.8.2",
|
package/src/cdk/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export function replaceTokens(str, env) {
|
|
2
|
+
if (typeof str !== 'string') return str;
|
|
3
|
+
|
|
4
|
+
return str.replace(/\$\{([^}]+)\}|\$([A-Z0-9_]+)/g, (m, k1, k2) => {
|
|
5
|
+
const k = k1 || k2;
|
|
6
|
+
|
|
7
|
+
// existing data layer takes priority (guarded in case not defined)
|
|
8
|
+
if (typeof hasData === 'function' && hasData(k)) {
|
|
9
|
+
const val = typeof getData === 'function' ? getData(k) : undefined;
|
|
10
|
+
return val == null ? '' : String(val);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// environment variables
|
|
14
|
+
if (env && Object.prototype.hasOwnProperty.call(env, k)) {
|
|
15
|
+
const val = env[k];
|
|
16
|
+
return val == null ? '' : String(val);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// fallback
|
|
20
|
+
return '';
|
|
21
|
+
});
|
|
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
|
+
|
|
34
|
+
export function setUpConfig(config) {
|
|
35
|
+
const { extra = {}, ...other } = config.expo || {};
|
|
36
|
+
const router =
|
|
37
|
+
extra['router'] ?
|
|
38
|
+
{ origin: false, ...extra['router'] }
|
|
39
|
+
: {
|
|
40
|
+
origin: false,
|
|
41
|
+
};
|
|
42
|
+
const appConfig = {
|
|
43
|
+
...config,
|
|
44
|
+
|
|
45
|
+
expo: {
|
|
46
|
+
...other,
|
|
47
|
+
extra: {
|
|
48
|
+
...filterEnvByPrefix(process.env, 'NEXT_PUBLIC_'),
|
|
49
|
+
eas: {
|
|
50
|
+
projectId: process.env.EAS_PROJECT_ID,
|
|
51
|
+
},
|
|
52
|
+
router,
|
|
53
|
+
...extra,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return appConfig;
|
|
59
|
+
}
|
package/src/expo.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Type definitions for mono-labs CLI
|
|
2
|
+
import type { AppJSONConfig, ExpoConfig } from 'expo/config';
|
|
3
|
+
export declare function setUpConfig(config: AppJSONConfig): ExpoConfig;
|
|
4
|
+
export declare function replaceTokens(
|
|
5
|
+
input: string,
|
|
6
|
+
tokens: Record<string, string>
|
|
7
|
+
): string;
|
package/src/stack.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as cdk from 'aws-cdk-lib';
|
|
2
|
+
import { Construct } from 'constructs';
|
|
3
|
+
import dotenv from 'dotenv';
|
|
4
|
+
|
|
5
|
+
dotenv.config();
|
|
6
|
+
//cdk deploy --context owner=cody --context region=us-west-1
|
|
7
|
+
|
|
8
|
+
const dev = 'dev';
|
|
9
|
+
export interface ICustomStack extends cdk.Stack {
|
|
10
|
+
ownerName: string;
|
|
11
|
+
region: string;
|
|
12
|
+
enableNATGateway: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface CustomStackProps extends cdk.StackProps {
|
|
16
|
+
ownerName?: string;
|
|
17
|
+
region?: string;
|
|
18
|
+
enableNATGateway?: boolean;
|
|
19
|
+
domainName?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export abstract class CustomStack extends cdk.Stack {
|
|
23
|
+
public ownerName: string;
|
|
24
|
+
public region: string;
|
|
25
|
+
public domainName?: string;
|
|
26
|
+
protected enableNATGateway: boolean = false;
|
|
27
|
+
|
|
28
|
+
constructor(scope: Construct, id: string, props: CustomStackProps = {}) {
|
|
29
|
+
// 🔑 Resolve account + region BEFORE super()
|
|
30
|
+
const resolvedEnv: cdk.Environment | undefined = {
|
|
31
|
+
account:
|
|
32
|
+
props.env?.account ??
|
|
33
|
+
process.env.CDK_DEPLOY_ACCOUNT ??
|
|
34
|
+
cdk.Aws.ACCOUNT_ID, // final fallback (lazy token)
|
|
35
|
+
region: props.env?.region ?? process.env.CDK_DEPLOY_REGION ?? 'us-east-2',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
super(scope, id, {
|
|
39
|
+
...props,
|
|
40
|
+
env: resolvedEnv,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// ✅ Now it’s safe to read these
|
|
44
|
+
this.ownerName = props.ownerName ?? 'dev';
|
|
45
|
+
this.domainName = props.domainName;
|
|
46
|
+
this.region = resolvedEnv.region!;
|
|
47
|
+
this.enableNATGateway = props.enableNATGateway ?? false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public initializeStackConfig(): void {
|
|
51
|
+
// Context overrides (deploy-time flags)
|
|
52
|
+
const ctxOwner = this.node.tryGetContext('owner') || dev;
|
|
53
|
+
const ctxRegion = this.node.tryGetContext('region') || 'us-east-2';
|
|
54
|
+
const ctxNat = this.node.tryGetContext('enableNATGateway');
|
|
55
|
+
|
|
56
|
+
if (ctxOwner) this.ownerName = ctxOwner;
|
|
57
|
+
if (ctxRegion) this.region = ctxRegion;
|
|
58
|
+
|
|
59
|
+
// NAT logic
|
|
60
|
+
if (ctxNat !== undefined) {
|
|
61
|
+
this.enableNATGateway = ctxNat === 'true';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Production default
|
|
65
|
+
if (this.ownerName === 'prod' || this.ownerName === 'production') {
|
|
66
|
+
this.enableNATGateway = ctxNat !== 'false';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
console.log('[Stack Config]', {
|
|
70
|
+
owner: this.ownerName,
|
|
71
|
+
region: this.region,
|
|
72
|
+
account: this.account,
|
|
73
|
+
natGateway: this.enableNATGateway,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
File without changes
|
|
File without changes
|