@mono-labs/cli 0.0.131 → 0.0.133
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/lib/commands/build-process/runners/runBackground.js +5 -1
- package/lib/commands/build-process/runners/runForeground.js +6 -0
- package/lib/commands/submit/index.js +5 -1
- package/lib/index.js +5 -6
- package/package.json +1 -1
- package/lib/commands/build/index.js +0 -68
- package/lib/commands/deploy/index.js +0 -41
- package/lib/commands/destroy.js +0 -26
- package/lib/commands/dev/dev-editor.js +0 -270
- package/lib/commands/dev/index.js +0 -22
- package/lib/commands/dev/ngrok.js +0 -88
- package/lib/commands/init/index.js +0 -36
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { spawn } from 'child_process';
|
|
2
2
|
import { getData, replaceTokens } from '../dataLayer.js';
|
|
3
3
|
import { registerBackground } from './processManager.js';
|
|
4
|
-
|
|
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);
|
|
5
8
|
function createdExpandedEnv(envObj) {
|
|
6
9
|
const expandedEnv = {};
|
|
7
10
|
for (const k of Object.keys(envObj)) {
|
|
@@ -30,6 +33,7 @@ export function runBackground(
|
|
|
30
33
|
const child = spawn(outCmd, {
|
|
31
34
|
shell: true,
|
|
32
35
|
stdio: attached ? 'inherit' : 'ignore',
|
|
36
|
+
//env: { ...process.env, ...expandedEnv, PATH },
|
|
33
37
|
env: { ...process.env, ...expandedEnv },
|
|
34
38
|
detached: !attached && !isWin,
|
|
35
39
|
windowsHide: !attached && isWin,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { spawn } from 'child_process';
|
|
2
2
|
import { replaceTokens, setData } from '../dataLayer.js';
|
|
3
3
|
import { filterUnwantedEnvVars } from '../../../../lib/filterUnwantedEnvVars.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);
|
|
4
8
|
// Regex to capture tokens like: {out:field value}
|
|
5
9
|
const TOKEN_RX = /\{out:(?<field>[^\s}]+)\s+(?<value>[^\s}]+)\}/g;
|
|
6
10
|
|
|
@@ -8,6 +12,7 @@ const TOKEN_RX = /\{out:(?<field>[^\s}]+)\s+(?<value>[^\s}]+)\}/g;
|
|
|
8
12
|
* Run a command in the foreground, capturing stdout/stderr. Extracts token patterns
|
|
9
13
|
* of the form {out:field value} and stores them in the shared dataLayer.
|
|
10
14
|
*/
|
|
15
|
+
|
|
11
16
|
export function runForeground(cmd, envObj = {}, options = {}) {
|
|
12
17
|
const filteredEnv = filterUnwantedEnvVars(process.env);
|
|
13
18
|
const newEnv = { ...filteredEnv, ...envObj };
|
|
@@ -19,6 +24,7 @@ export function runForeground(cmd, envObj = {}, options = {}) {
|
|
|
19
24
|
|
|
20
25
|
const child = spawn(newCmd, {
|
|
21
26
|
shell: true,
|
|
27
|
+
//env: { ...newEnv, PATH },
|
|
22
28
|
env: { ...newEnv },
|
|
23
29
|
stdio: ['inherit', 'pipe', 'pipe'],
|
|
24
30
|
});
|
|
@@ -3,7 +3,10 @@ import { spawn } from 'child_process';
|
|
|
3
3
|
import { program } from '../../app.js';
|
|
4
4
|
import { generateEnvValues } from '../../app.js';
|
|
5
5
|
import { STAGING_URL } from '../../config.js';
|
|
6
|
-
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
const homeBin = path.join(os.homedir(), 'bin');
|
|
9
|
+
const PATH = [homeBin, process.env.PATH].filter(Boolean).join(path.delimiter);
|
|
7
10
|
program
|
|
8
11
|
.command('submit')
|
|
9
12
|
.description('Execute eas build command')
|
|
@@ -25,6 +28,7 @@ program
|
|
|
25
28
|
shell: true, // required if using shell-style commands or cross-platform support
|
|
26
29
|
env: {
|
|
27
30
|
...envObj,
|
|
31
|
+
PATH,
|
|
28
32
|
},
|
|
29
33
|
});
|
|
30
34
|
|
package/lib/index.js
CHANGED
|
@@ -2,12 +2,7 @@ import 'dotenv/config';
|
|
|
2
2
|
import spawn from 'cross-spawn';
|
|
3
3
|
|
|
4
4
|
import { program } from './app.js';
|
|
5
|
-
import './commands/build/index.js';
|
|
6
|
-
import './commands/deploy/index.js';
|
|
7
|
-
import './commands/destroy.js';
|
|
8
|
-
import './commands/dev/index.js';
|
|
9
5
|
import './commands/generate/index.js';
|
|
10
|
-
import './commands/init/index.js';
|
|
11
6
|
import './commands/prune/index.js';
|
|
12
7
|
import './commands/seed/index.js';
|
|
13
8
|
import './commands/submit/index.js';
|
|
@@ -15,6 +10,10 @@ import './commands/update/index.js';
|
|
|
15
10
|
import './commands/build-process/index.js';
|
|
16
11
|
import { getHasteConfig } from './commands/loadFromRoot.js';
|
|
17
12
|
import { executeCommandsIfWorkspaceAction } from './commands/build-process/test.js';
|
|
13
|
+
import os from 'node:os';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
const homeBin = path.join(os.homedir(), 'bin');
|
|
16
|
+
const PATH = [homeBin, process.env.PATH].filter(Boolean).join(path.delimiter);
|
|
18
17
|
|
|
19
18
|
const { config } = getHasteConfig();
|
|
20
19
|
|
|
@@ -48,7 +47,7 @@ program.on('command:*', (operands) => {
|
|
|
48
47
|
const child = spawn('yarn', args, {
|
|
49
48
|
stdio: 'inherit',
|
|
50
49
|
shell: process.platform === 'win32',
|
|
51
|
-
env: { ...process.env, ...envObj },
|
|
50
|
+
env: { ...process.env, ...envObj, PATH },
|
|
52
51
|
});
|
|
53
52
|
child.on('exit', (code) => {
|
|
54
53
|
console.log('Child process exited with code:', code);
|
package/package.json
CHANGED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'child_process';
|
|
2
|
-
|
|
3
|
-
import { program } from '../../app.js';
|
|
4
|
-
import { generateEnvValues } from '../../app.js';
|
|
5
|
-
import { STAGING_URL } from '../../config.js';
|
|
6
|
-
|
|
7
|
-
const allowedPlatforms = ['ios', 'android'];
|
|
8
|
-
function selectPlatform(platform) {
|
|
9
|
-
if (!allowedPlatforms.includes(platform))
|
|
10
|
-
throw new Error(
|
|
11
|
-
`Invalid platform selected, must be one of ${allowedPlatforms.join(', ')}`
|
|
12
|
-
);
|
|
13
|
-
return platform;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function selectProfile(dev, preview, prod, profile) {
|
|
17
|
-
if (profile && (dev || preview || prod)) {
|
|
18
|
-
throw new Error('Conflict between profile and dev/preview/prod');
|
|
19
|
-
}
|
|
20
|
-
if (dev) return 'development';
|
|
21
|
-
if (preview) return 'preview';
|
|
22
|
-
if (prod) return 'production';
|
|
23
|
-
if (profile) return profile;
|
|
24
|
-
return 'development';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
program
|
|
28
|
-
.command('build2')
|
|
29
|
-
.description('Execute eas build command')
|
|
30
|
-
.option('-d', 'Build to target development profile')
|
|
31
|
-
.option('-p', 'Build to target preview profile')
|
|
32
|
-
.option('--live', 'Build to target production profile')
|
|
33
|
-
.option('--profile <string>', 'Build profile to use')
|
|
34
|
-
.option('--os, --platform <string>', 'Platform to build', 'ios')
|
|
35
|
-
.option('-f, --force', 'Force build to target production server')
|
|
36
|
-
.action((str, options) => {
|
|
37
|
-
const platform = selectPlatform(str.platform);
|
|
38
|
-
const profile = selectProfile(str.d, str.p, str.live, str.profile);
|
|
39
|
-
const isDev = profile === 'development';
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
const NEXT_FORCE_PROD = str.force || isDev ? 'false' : 'true';
|
|
43
|
-
|
|
44
|
-
let envObj = generateEnvValues(NEXT_FORCE_PROD, '', false);
|
|
45
|
-
if (!isDev) {
|
|
46
|
-
envObj.NEXT_PUBLIC_API_URL = `${STAGING_URL}`;
|
|
47
|
-
envObj.NEXT_FORCE_PROD = 'true';
|
|
48
|
-
} else {
|
|
49
|
-
const publicUrl = process.env.NEXT_PUBLIC_API_URL || `${STAGING_URL}`;
|
|
50
|
-
envObj.NEXT_PUBLIC_API_URL = publicUrl;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
envObj.EAS_BUILD_PROFILE = profile; // your custom variable
|
|
54
|
-
|
|
55
|
-
const command = `mono app eas build --profile ${profile} --platform ${platform}`;
|
|
56
|
-
|
|
57
|
-
const child = spawn('yarn', [command], {
|
|
58
|
-
stdio: 'inherit',
|
|
59
|
-
shell: true, // required if using shell-style commands or cross-platform support
|
|
60
|
-
env: {
|
|
61
|
-
...envObj,
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
child.on('exit', (code) => {
|
|
66
|
-
process.exit(code ?? 0);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
2
|
-
import { spawn } from 'child_process';
|
|
3
|
-
import { readFileSync } from 'fs';
|
|
4
|
-
|
|
5
|
-
import { program } from '../../app.js';
|
|
6
|
-
import { join } from 'node:path';
|
|
7
|
-
const packageJSON = JSON.parse(
|
|
8
|
-
readFileSync(join(process.cwd(), 'package.json'), 'utf8')
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
const awsObject = packageJSON['aws'] || {};
|
|
12
|
-
|
|
13
|
-
// const awsProfile = awsObject['profile'] || 'default'
|
|
14
|
-
const accountId = process.env.CDK_DEPLOY_ACCOUNT;
|
|
15
|
-
const awsProfile = process.env.CDK_DEPLOY_PROFILE || 'default';
|
|
16
|
-
|
|
17
|
-
program
|
|
18
|
-
.command('deploy2')
|
|
19
|
-
.description('Execute cdk deploy command')
|
|
20
|
-
.argument('[<string>]', 'Environment to deploy')
|
|
21
|
-
.option('-d, --dev', 'Deploy to dev environment')
|
|
22
|
-
.option('-r, --region <region>', 'Region to deploy to')
|
|
23
|
-
.action((str, options) => {
|
|
24
|
-
const owner = str || 'dev';
|
|
25
|
-
const region = options.region || 'us-east-2';
|
|
26
|
-
|
|
27
|
-
const command = `workspace infra deploy`;
|
|
28
|
-
const inputs = `-c owner=${owner} -c region=${region}`;
|
|
29
|
-
|
|
30
|
-
const child = spawn('yarn', [`${command} ${inputs}`], {
|
|
31
|
-
stdio: 'inherit',
|
|
32
|
-
shell: true, // required if using shell-style commands or cross-platform support
|
|
33
|
-
env: {
|
|
34
|
-
AWS_PROFILE: awsProfile,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
child.on('exit', (code) => {
|
|
39
|
-
process.exit(code ?? 0);
|
|
40
|
-
});
|
|
41
|
-
});
|
package/lib/commands/destroy.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'child_process';
|
|
2
|
-
|
|
3
|
-
import { program } from '../app.js';
|
|
4
|
-
|
|
5
|
-
program
|
|
6
|
-
.command('destroy2')
|
|
7
|
-
.description('Destroys the current or specified cdk construct')
|
|
8
|
-
.argument('[<string>]', 'Environment to deploy')
|
|
9
|
-
.option('-d, --dev', 'Deploy to dev environment')
|
|
10
|
-
.option('-r, --region <region>', 'Region to deploy to')
|
|
11
|
-
.action((str, options) => {
|
|
12
|
-
const owner = str || 'dev';
|
|
13
|
-
const region = options.region || 'us-east-2';
|
|
14
|
-
|
|
15
|
-
const command = `workspace infra cdk destroy`;
|
|
16
|
-
const inputs = `-c owner=${owner} -c region=${region}`;
|
|
17
|
-
|
|
18
|
-
const child = spawn('yarn', [`${command} ${inputs}`], {
|
|
19
|
-
stdio: 'inherit',
|
|
20
|
-
shell: true, // required if using shell-style commands or cross-platform support
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
child.on('exit', (code) => {
|
|
24
|
-
process.exit(code ?? 0);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'child_process';
|
|
2
|
-
import 'dotenv/config';
|
|
3
|
-
import inquirer from 'inquirer';
|
|
4
|
-
import treeKill from 'tree-kill';
|
|
5
|
-
|
|
6
|
-
import { generateEnvValues } from '../../app.js';
|
|
7
|
-
import { STAGING_URL } from '../../config.js';
|
|
8
|
-
import { getNgrokUrl } from './ngrok.js';
|
|
9
|
-
|
|
10
|
-
// EXPO_UNSTABLE_ATLAS = false;
|
|
11
|
-
|
|
12
|
-
// Import the runDevCommand function
|
|
13
|
-
const colors = {
|
|
14
|
-
red: '\x1b[31m',
|
|
15
|
-
green: '\x1b[32m',
|
|
16
|
-
yellow: '\x1b[33m',
|
|
17
|
-
white: '\x1b[37m',
|
|
18
|
-
blue: '\x1b[34m',
|
|
19
|
-
magenta: '\x1b[35m',
|
|
20
|
-
cyan: '\x1b[36m',
|
|
21
|
-
reset: '\x1b[0m',
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
function getContinuedServices() {
|
|
25
|
-
const continuedServices = Object.keys(devServices).filter(
|
|
26
|
-
(key) => devServices[key].continue
|
|
27
|
-
);
|
|
28
|
-
return continuedServices;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function getPrepServices() {
|
|
32
|
-
const continuedServices = Object.keys(devServices).filter(
|
|
33
|
-
(key) => !devServices[key].continue
|
|
34
|
-
);
|
|
35
|
-
return continuedServices;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const devServicesRoot = {
|
|
39
|
-
docker: {
|
|
40
|
-
command: 'docker compose up -d',
|
|
41
|
-
key: '?',
|
|
42
|
-
icon: '🐳',
|
|
43
|
-
stdio: 'ignore',
|
|
44
|
-
},
|
|
45
|
-
backend: {
|
|
46
|
-
command: 'yarn backend server',
|
|
47
|
-
key: 'b',
|
|
48
|
-
color: colors.yellow,
|
|
49
|
-
continue: true,
|
|
50
|
-
icon: '🦾',
|
|
51
|
-
},
|
|
52
|
-
// app: {
|
|
53
|
-
// command: 'yarn workspace app expo start -c --tunnel --dev-client',
|
|
54
|
-
// key: 'a',
|
|
55
|
-
// color: colors.white,
|
|
56
|
-
// continue: true,
|
|
57
|
-
// icon: '📱',
|
|
58
|
-
// stdio: ['inherit', 'inherit', 'inherit'],
|
|
59
|
-
// },
|
|
60
|
-
dynamo: {
|
|
61
|
-
command:
|
|
62
|
-
'yarn backend dynamodb-admin -p 8082 --dynamo-endpoint=http://localhost:8000',
|
|
63
|
-
key: 'd',
|
|
64
|
-
continue: true,
|
|
65
|
-
icon: '📦',
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const devServices = {};
|
|
70
|
-
Object.keys(devServicesRoot).forEach((key) => {
|
|
71
|
-
const service = devServicesRoot[key];
|
|
72
|
-
devServices[key] = {
|
|
73
|
-
...service,
|
|
74
|
-
name: key,
|
|
75
|
-
};
|
|
76
|
-
});
|
|
77
|
-
const childProcesses = {};
|
|
78
|
-
let allowRestart = true;
|
|
79
|
-
|
|
80
|
-
const totalRetries = 5;
|
|
81
|
-
|
|
82
|
-
function startService(key, forceProd, ngrokUrl, stage, envObj) {
|
|
83
|
-
const { command, stdio } = devServices[key];
|
|
84
|
-
const isContinued = devServices[key].continue;
|
|
85
|
-
|
|
86
|
-
const child = spawn(command, {
|
|
87
|
-
stdio: stdio ? stdio : ['ignore', 'pipe', 'pipe'],
|
|
88
|
-
shell: true,
|
|
89
|
-
env: {
|
|
90
|
-
...envObj,
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
childProcesses[key] = child;
|
|
95
|
-
childManager(child, devServices[key], false, () => {
|
|
96
|
-
if (isContinued && allowRestart && key !== 'backend') {
|
|
97
|
-
setTimeout(
|
|
98
|
-
() => startService(key, forceProd, ngrokUrl, stage, envObj),
|
|
99
|
-
2000
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const write = (color, message) => {
|
|
106
|
-
process.stdout.write(`${color}${message}${colors.reset}\n`);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const serviceSigInt = {};
|
|
110
|
-
|
|
111
|
-
function childManager(
|
|
112
|
-
child,
|
|
113
|
-
service,
|
|
114
|
-
nowrite = false,
|
|
115
|
-
restartCallback = undefined
|
|
116
|
-
) {
|
|
117
|
-
const color = service.color || undefined;
|
|
118
|
-
const writeToBox = (data) => {
|
|
119
|
-
if (color) write(color, data.toString());
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
if (!nowrite) {
|
|
123
|
-
child.stdout?.on('data', writeToBox);
|
|
124
|
-
child.stderr?.on('data', writeToBox);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
child.on('sigint', (code) => {
|
|
128
|
-
console.log(
|
|
129
|
-
`\n${service.icon || '🔚'} ${service.name || 'Service'} exited with code ${code}`
|
|
130
|
-
);
|
|
131
|
-
if (restartCallback) restartCallback();
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
child.on('exit', (code) => {
|
|
135
|
-
if (!serviceSigInt[service.name] && restartCallback) {
|
|
136
|
-
restartCallback();
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export async function dev(_forceProd, useAtlas, argServices, stage) {
|
|
142
|
-
const forceProd = stage === true ? true : _forceProd;
|
|
143
|
-
let acceptedServices = argServices || undefined;
|
|
144
|
-
if (acceptedServices === undefined && !stage) {
|
|
145
|
-
const { acceptedServices: services } = await inquirer.prompt([
|
|
146
|
-
{
|
|
147
|
-
type: 'checkbox',
|
|
148
|
-
name: 'acceptedServices',
|
|
149
|
-
message: 'Select services to run:',
|
|
150
|
-
choices: Object.keys(devServices).map((key) => ({
|
|
151
|
-
name: key,
|
|
152
|
-
value: key,
|
|
153
|
-
})),
|
|
154
|
-
default: Object.keys(devServices).map((key) => key),
|
|
155
|
-
},
|
|
156
|
-
]);
|
|
157
|
-
|
|
158
|
-
acceptedServices = services;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
let ngrokUrl = '';
|
|
162
|
-
if (!forceProd && !stage) {
|
|
163
|
-
let envObj = generateEnvValues(forceProd);
|
|
164
|
-
getPrepServices().forEach((key) => {
|
|
165
|
-
const { command, stdio } = devServices[key];
|
|
166
|
-
if (acceptedServices.includes(key)) {
|
|
167
|
-
console.log(`Running command for service ${key}: ${command}`);
|
|
168
|
-
const child = spawn(command, {
|
|
169
|
-
stdio: ['pipe', 'inherit', 'pipe'], // Read from terminal, but capture output
|
|
170
|
-
shell: true,
|
|
171
|
-
env: {
|
|
172
|
-
...envObj,
|
|
173
|
-
},
|
|
174
|
-
});
|
|
175
|
-
if (key === 'app') {
|
|
176
|
-
child.on('sigint', () => {
|
|
177
|
-
console.log('SIGINT received for app service');
|
|
178
|
-
});
|
|
179
|
-
child.on('exit', () => {
|
|
180
|
-
console.log('exit received for app service');
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
childProcesses[key] = child;
|
|
185
|
-
childManager(child, devServices[key], true);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
while (!ngrokUrl) {
|
|
190
|
-
try {
|
|
191
|
-
ngrokUrl = (await getNgrokUrl()) + '/';
|
|
192
|
-
} catch (e) {
|
|
193
|
-
console.log('Ngrok failed to start. Retrying in 2 seconds...');
|
|
194
|
-
console.log(e);
|
|
195
|
-
await new Promise((res) => setTimeout(res, 2000)); // Delay before retry
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
let envObj = generateEnvValues(forceProd, ngrokUrl, useAtlas);
|
|
201
|
-
if (stage) {
|
|
202
|
-
envObj.NEXT_PUBLIC_API_URL = `${STAGING_URL}`;
|
|
203
|
-
envObj.ApiUrl = `${STAGING_URL}`;
|
|
204
|
-
envObj.NEXT_FORCE_PROD = 'true';
|
|
205
|
-
} else {
|
|
206
|
-
const publicUrl = process.env.NEXT_PUBLIC_API_URL || `${STAGING_URL}`;
|
|
207
|
-
envObj.NEXT_PUBLIC_API_URL = publicUrl;
|
|
208
|
-
envObj.ApiUrl = `${STAGING_URL}`;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
setTimeout(
|
|
212
|
-
() => {
|
|
213
|
-
getContinuedServices().forEach((key) => {
|
|
214
|
-
if (stage && key === 'app') {
|
|
215
|
-
startService(key, forceProd, ngrokUrl, stage, envObj);
|
|
216
|
-
} else {
|
|
217
|
-
if (!stage && acceptedServices.includes(key)) {
|
|
218
|
-
startService(key, forceProd, ngrokUrl, stage, envObj);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
},
|
|
223
|
-
!forceProd ? 5000 : 100
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
async function shutdown() {
|
|
227
|
-
console.log('\n🛑 Shutting down all services...');
|
|
228
|
-
for (const [key, child] of Object.entries(childProcesses)) {
|
|
229
|
-
if (
|
|
230
|
-
child &&
|
|
231
|
-
child.pid &&
|
|
232
|
-
!child.killed &&
|
|
233
|
-
devServices[key].continue &&
|
|
234
|
-
!['docker'].includes(key)
|
|
235
|
-
) {
|
|
236
|
-
console.log(`→ Killing service: ${key}`);
|
|
237
|
-
await new Promise((resolve) => {
|
|
238
|
-
treeKill(child.pid, 'SIGTERM', (err) => {
|
|
239
|
-
if (!err) {
|
|
240
|
-
console.log(`✅ ${key} has been tree-killed.`);
|
|
241
|
-
}
|
|
242
|
-
resolve();
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
if (key === ' docker') {
|
|
247
|
-
spawn(command, {
|
|
248
|
-
stdio: 'docker-compose down', // Read from terminal, but capture output
|
|
249
|
-
shell: true,
|
|
250
|
-
env: {
|
|
251
|
-
...envObj,
|
|
252
|
-
},
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
process.on('SIGINT', () => {
|
|
259
|
-
shutdown().then(() => process.exit(0));
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
process.on('SIGTERM', () => {
|
|
263
|
-
shutdown().then(() => process.exit(0));
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
// Exit signal
|
|
267
|
-
process.on('exit', () => {
|
|
268
|
-
console.log('👋 Process exiting...');
|
|
269
|
-
});
|
|
270
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { program } from '../../app.js';
|
|
2
|
-
import { dev } from './dev-editor.js';
|
|
3
|
-
|
|
4
|
-
program
|
|
5
|
-
.command('dev2')
|
|
6
|
-
.description('Run local dev environment')
|
|
7
|
-
.option('-d, --dev', 'Deploy to dev environment')
|
|
8
|
-
.option('-a, --atlas', 'Region to deploy to')
|
|
9
|
-
.option('--app', 'Runs just the native app')
|
|
10
|
-
.option('--host', 'Runs just the backend host app')
|
|
11
|
-
.option('--stage', 'Connect to staging environment')
|
|
12
|
-
.action(async (str, options) => {
|
|
13
|
-
let services = undefined;
|
|
14
|
-
|
|
15
|
-
if (str.app || str.host) {
|
|
16
|
-
if (str.app) services = ['app'];
|
|
17
|
-
if (str.host) services = ['backend'];
|
|
18
|
-
}
|
|
19
|
-
const stage = str.stage || false;
|
|
20
|
-
|
|
21
|
-
dev(str.dev || false, str.atlas || false, services, stage);
|
|
22
|
-
});
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import http from 'http';
|
|
3
|
-
import https from 'https';
|
|
4
|
-
|
|
5
|
-
// Define the path to your .env file
|
|
6
|
-
const envFilePath = '../.env';
|
|
7
|
-
|
|
8
|
-
// Fetch the ngrok public URL from localhost:4040 (ngrok web interface)
|
|
9
|
-
export function getNgrokUrl() {
|
|
10
|
-
return new Promise((resolve, reject) => {
|
|
11
|
-
const options = {
|
|
12
|
-
hostname: 'localhost',
|
|
13
|
-
port: 4040,
|
|
14
|
-
path: '/api/tunnels',
|
|
15
|
-
method: 'GET',
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const req = (options.port === 443 ? https : http).request(
|
|
19
|
-
options,
|
|
20
|
-
(res) => {
|
|
21
|
-
let data = '';
|
|
22
|
-
res.on('data', (chunk) => {
|
|
23
|
-
data += chunk;
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
res.on('end', () => {
|
|
27
|
-
try {
|
|
28
|
-
const jsonResponse = JSON.parse(data);
|
|
29
|
-
const publicUrl =
|
|
30
|
-
jsonResponse.tunnels && jsonResponse.tunnels[0]?.public_url;
|
|
31
|
-
if (publicUrl) {
|
|
32
|
-
resolve(publicUrl);
|
|
33
|
-
} else {
|
|
34
|
-
reject('Could not find public URL in the response');
|
|
35
|
-
}
|
|
36
|
-
} catch (err) {
|
|
37
|
-
reject('Error parsing JSON response');
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
req.on('error', (error) => {
|
|
44
|
-
reject(error);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
req.end();
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Update the .env file with the new NGROK_URL value
|
|
52
|
-
function updateEnvFile(ngrokUrl) {
|
|
53
|
-
fs.readFile(envFilePath, 'utf8', (err, data) => {
|
|
54
|
-
if (err) {
|
|
55
|
-
console.error('Error reading .env file:', err);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
let newData;
|
|
60
|
-
if (data.includes('EXPO_PRIVATE_API_URL=')) {
|
|
61
|
-
// If NGROK_URL exists, replace it
|
|
62
|
-
newData = data.replace(
|
|
63
|
-
/EXPO_PRIVATE_API_URL=.*/,
|
|
64
|
-
`EXPO_PRIVATE_API_URL=${ngrokUrl}/`
|
|
65
|
-
);
|
|
66
|
-
} else {
|
|
67
|
-
// If NGROK_URL doesn't exist, add it to the file
|
|
68
|
-
newData = `${data}\nEXPO_PRIVATE_API_URL=${ngrokUrl}/`;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Write the updated data back to the .env file
|
|
72
|
-
fs.writeFile(envFilePath, newData, 'utf8', (writeErr) => {
|
|
73
|
-
if (writeErr) {
|
|
74
|
-
console.error('Error writing to .env file:', writeErr);
|
|
75
|
-
} else {
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
// Main function to get the ngrok URL and update the .env file
|
|
81
|
-
export async function updateNgrokUrl() {
|
|
82
|
-
try {
|
|
83
|
-
const ngrokUrl = await getNgrokUrl();
|
|
84
|
-
updateEnvFile(ngrokUrl);
|
|
85
|
-
} catch (error) {
|
|
86
|
-
console.error('Error:', error);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
2
|
-
import { spawn } from 'child_process';
|
|
3
|
-
import { readFileSync } from 'fs';
|
|
4
|
-
|
|
5
|
-
import { program } from '../../app.js';
|
|
6
|
-
|
|
7
|
-
import { join } from 'node:path';
|
|
8
|
-
const packageJSON = JSON.parse(
|
|
9
|
-
readFileSync(join(process.cwd(), 'package.json'), 'utf8')
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
const awsObject = packageJSON['aws'] || {};
|
|
13
|
-
|
|
14
|
-
const accountId = process.env.CDK_DEPLOY_ACCOUNT;
|
|
15
|
-
const awsProfile = process.env.CDK_DEPLOY_PROFILE || 'default';
|
|
16
|
-
|
|
17
|
-
program
|
|
18
|
-
.command('init2')
|
|
19
|
-
.description('Execute cdk deploy command')
|
|
20
|
-
.action((str, options) => {
|
|
21
|
-
const owner = str || 'dev';
|
|
22
|
-
const region = options.region || 'us-east-2';
|
|
23
|
-
|
|
24
|
-
const command = `workspace infra cdk bootstrap`;
|
|
25
|
-
const child = spawn('yarn', [`${command}`], {
|
|
26
|
-
stdio: 'inherit',
|
|
27
|
-
shell: true, // required if using shell-style commands or cross-platform support
|
|
28
|
-
env: {
|
|
29
|
-
AWS_PROFILE: awsProfile,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
child.on('exit', (code) => {
|
|
34
|
-
process.exit(code ?? 0);
|
|
35
|
-
});
|
|
36
|
-
});
|