@journeyapps/cloudcode-build-agent 0.0.0-dev.8ebefb0 → 0.0.0-dev.9117f43
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/builder.d.ts +16 -1
- package/dist/builder.js +66 -67
- package/dist/builder.js.map +1 -1
- package/dist/cli.js +7 -2
- package/dist/cli.js.map +1 -1
- package/dist/defs.d.ts +1 -0
- package/dist/defs.js +20 -26
- package/dist/defs.js.map +1 -1
- package/dist/detect_tasks.d.ts +17 -5
- package/dist/detect_tasks.js +23 -9
- package/dist/detect_tasks.js.map +1 -1
- package/dist/installer.d.ts +8 -0
- package/dist/installer.js +39 -34
- package/dist/installer.js.map +1 -1
- package/dist/run.d.ts +0 -1
- package/dist/run.js +1 -2
- package/dist/run.js.map +1 -1
- package/dist/spawn-stream.d.ts +0 -1
- package/dist/spawn-stream.js +1 -2
- package/dist/spawn-stream.js.map +1 -1
- package/package.json +19 -13
- package/src/builder.ts +0 -105
- package/src/cli.ts +0 -51
- package/src/defs.ts +0 -45
- package/src/detect_tasks.ts +0 -74
- package/src/index.ts +0 -1
- package/src/installer.ts +0 -112
- package/src/run.ts +0 -23
- package/src/spawn-stream.ts +0 -73
- package/tsconfig.json +0 -8
- package/tsconfig.tsbuildinfo +0 -1
package/dist/installer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installer.js","sourceRoot":"","sources":["../src/installer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"installer.js","sourceRoot":"","sources":["../src/installer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,0DASC;AAOD,wDAQC;AAED,8BAOC;AAED,8DAsEC;AAjHD,oDAAsC;AACtC,gDAAkC;AAClC,8CAAgC;AAChC,4DAA+B;AAC/B,4CAA8B;AAC9B,4CAA8B;AAC9B,yCAA2B;AAEpB,KAAK,UAAU,uBAAuB,CAAC,YAAoB,EAA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AK,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;gBAEzC,GAAG,CAAC,OAAO,CAAC;oBACV,GAAG,EAAE,MAAM;oBACX,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,IAAI;iBACX,CAAC,CAAC;gBAEH,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAEvC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBAChC,IAAI,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC1B,OAAO,CAAC,KAAK,CAAC,+BAA+B,MAAM,OAAO,IAAI,EAAE,CAAC,CAAC;oBAClE,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAC9B,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,KAAK,CAAC,0BAA0B,MAAM,EAAE,CAAC,CAAC;gBACpD,CAAC;gBAED;;;;;;;;;;;;;;;;;kBAiBE;gBACF,4BAA4B;gBAE5B,OAAO,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,CAAC,GAAG,CAAC,CAAC;YACd,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/run.d.ts
CHANGED
package/dist/run.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runCommand =
|
|
3
|
+
exports.runCommand = runCommand;
|
|
4
4
|
const spawn_stream_1 = require("./spawn-stream");
|
|
5
5
|
async function* runCommand(command, args, options) {
|
|
6
6
|
const { childProcess, stream } = (0, spawn_stream_1.spawnStream)(command, args, { cwd: options?.cwd, splitLines: true, ...options });
|
|
@@ -15,5 +15,4 @@ async function* runCommand(command, args, options) {
|
|
|
15
15
|
throw new Error(`Command failed with code ${exitCode}`);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
exports.runCommand = runCommand;
|
|
19
18
|
//# sourceMappingURL=run.js.map
|
package/dist/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":";;AAGA,gCAmBC;AAtBD,iDAA+D;AAGxD,KAAK,SAAS,CAAC,CAAC,UAAU,CAC/B,OAAe,EACf,IAAc,EACd,OAA+B;IAE/B,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,IAAA,0BAAW,EAAC,OAAO,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAEjH,IAAI,QAAQ,GAAkB,IAAI,CAAC;IAEnC,IAAI,KAAK,EAAE,IAAI,KAAK,IAAI,MAAM,EAAE,CAAC;QAC/B,MAAM,KAAK,CAAC;QACZ,IAAI,KAAK,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAC;YAC3B,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,IAAI,CAAC,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,4BAA4B,QAAQ,EAAE,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC"}
|
package/dist/spawn-stream.d.ts
CHANGED
package/dist/spawn-stream.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.spawnStream =
|
|
3
|
+
exports.spawnStream = spawnStream;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const stream_1 = require("stream");
|
|
6
6
|
function spawnStream(command, args, options) {
|
|
@@ -13,7 +13,6 @@ function spawnStream(command, args, options) {
|
|
|
13
13
|
stream: processToStream(process, options)
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
exports.spawnStream = spawnStream;
|
|
17
16
|
function processToStream(process, options) {
|
|
18
17
|
const combinedStream = new stream_1.PassThrough({ objectMode: true });
|
|
19
18
|
async function* transform(stream, key) {
|
package/dist/spawn-stream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn-stream.js","sourceRoot":"","sources":["../src/spawn-stream.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"spawn-stream.js","sourceRoot":"","sources":["../src/spawn-stream.ts"],"names":[],"mappings":";;AAOA,kCAUC;AAjBD,iDAAkE;AAClE,mCAA+C;AAM/C,SAAgB,WAAW,CAAC,OAAe,EAAE,IAAc,EAAE,OAAqC;IAChG,MAAM,OAAO,GAAG,IAAA,qBAAK,EAAC,OAAO,EAAE,IAAI,EAAE;QACnC,GAAG,OAAO;QACV,KAAK,EAAE,MAAM;KACd,CAAC,CAAC;IAEH,OAAO;QACL,YAAY,EAAE,OAAO;QACrB,MAAM,EAAE,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC;KAC1C,CAAC;AACJ,CAAC;AASD,SAAS,eAAe,CAAC,OAAqB,EAAE,OAAsB;IACpE,MAAM,cAAc,GAAG,IAAI,oBAAW,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;IAE7D,KAAK,SAAS,CAAC,CAAC,SAAS,CAAC,MAAgB,EAAE,GAAwB;QAClE,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC5B,IAAI,QAAQ,GAA0B,MAAM,CAAC;QAC7C,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC;QACD,IAAI,KAAK,EAAE,MAAM,K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IAAI,MAAM,EAAE,CAAC;QACX,MAAM,MAAM,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,31 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@journeyapps/cloudcode-build-agent",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "0.0.0-dev.9117f43",
|
|
4
|
+
"description": "Detect CloudCode tasks in a JourneyApps App and build them for installation on AWS Lambda",
|
|
5
5
|
"main": "./dist/index",
|
|
6
6
|
"types": "./dist/index",
|
|
7
|
-
"
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
8
10
|
"bin": {
|
|
9
11
|
"cloudcode-build-agent": "./bin.js"
|
|
10
12
|
},
|
|
13
|
+
"files": [
|
|
14
|
+
"bin.js",
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
11
17
|
"dependencies": {
|
|
12
18
|
"child-process-promise": "^2.2.1",
|
|
13
19
|
"fs-jetpack": "5.1.0",
|
|
14
20
|
"lodash": "4.17.21",
|
|
15
21
|
"node-fetch": "<3",
|
|
16
|
-
"semver": "7.3
|
|
17
|
-
"tar": "
|
|
18
|
-
"yargs": "17.
|
|
22
|
+
"semver": "7.6.3",
|
|
23
|
+
"tar": "7.4.3",
|
|
24
|
+
"yargs": "17.7.2"
|
|
19
25
|
},
|
|
20
26
|
"devDependencies": {
|
|
21
|
-
"@types/child-process-promise": "2.2.
|
|
22
|
-
"@types/lodash": "4.
|
|
23
|
-
"@types/node": "
|
|
27
|
+
"@types/child-process-promise": "2.2.6",
|
|
28
|
+
"@types/lodash": "4.17.7",
|
|
29
|
+
"@types/node": "22.5.0",
|
|
24
30
|
"@types/node-fetch": "2.6.2",
|
|
25
|
-
"@types/semver": "7.
|
|
26
|
-
"@types/tar": "6.1.
|
|
27
|
-
"@types/yargs": "17.0.
|
|
28
|
-
"typescript": "
|
|
31
|
+
"@types/semver": "7.5.8",
|
|
32
|
+
"@types/tar": "6.1.13",
|
|
33
|
+
"@types/yargs": "17.0.33",
|
|
34
|
+
"typescript": "5.5.4"
|
|
29
35
|
},
|
|
30
36
|
"scripts": {
|
|
31
37
|
"build": "tsc -b"
|
package/src/builder.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
|
-
import * as jetpack from 'fs-jetpack';
|
|
3
|
-
import * as semver from 'semver';
|
|
4
|
-
import * as utils from './installer';
|
|
5
|
-
import { detectTasks } from './detect_tasks';
|
|
6
|
-
import { runCommand } from './run';
|
|
7
|
-
|
|
8
|
-
import * as _ from 'lodash';
|
|
9
|
-
|
|
10
|
-
export type GeneralTaskConfig = {
|
|
11
|
-
app_id: string;
|
|
12
|
-
env: string;
|
|
13
|
-
backend_id: string;
|
|
14
|
-
backend_url: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export async function buildTasks(project_path: string, dest: string, config: GeneralTaskConfig, only?: string) {
|
|
18
|
-
const tasks = await detectTasks(project_path, only);
|
|
19
|
-
|
|
20
|
-
const required_node_versions = _.compact(tasks.map((t) => t.required_node_version));
|
|
21
|
-
const install_node_versions = _.uniq(required_node_versions);
|
|
22
|
-
|
|
23
|
-
// FIXME: Maybe refactor this section into an ensureNodeVersion (or something) that returns the relevant toolpaths?
|
|
24
|
-
const tool_paths: Record<string, { bin_path: string; node_bin: string; npm_bin: string }> = {};
|
|
25
|
-
// Use the version of nodejs that's running this script as the default.
|
|
26
|
-
const default_tool_paths = {
|
|
27
|
-
bin_path: path.dirname(process.execPath),
|
|
28
|
-
node_bin: process.execPath,
|
|
29
|
-
npm_bin: path.join(path.dirname(process.execPath), 'npm')
|
|
30
|
-
};
|
|
31
|
-
tool_paths[process.version] = default_tool_paths;
|
|
32
|
-
|
|
33
|
-
for (const required_node_version of install_node_versions) {
|
|
34
|
-
// FIXME: put this in another directory to avoid leaking into the builder
|
|
35
|
-
const custom_node_path = path.resolve(`node-${semver.major(required_node_version)}`);
|
|
36
|
-
|
|
37
|
-
if (!jetpack.exists(path.join(custom_node_path, 'bin/node'))) {
|
|
38
|
-
console.debug(`installing to ${custom_node_path}`);
|
|
39
|
-
await jetpack.dirAsync(custom_node_path);
|
|
40
|
-
await utils.downloadAndInstallNode(required_node_version, custom_node_path);
|
|
41
|
-
} else {
|
|
42
|
-
console.debug(`already installed in ${custom_node_path}`);
|
|
43
|
-
}
|
|
44
|
-
tool_paths[required_node_version] = utils.nodePaths(custom_node_path);
|
|
45
|
-
}
|
|
46
|
-
// console.debug('----');
|
|
47
|
-
|
|
48
|
-
for (const task of tasks) {
|
|
49
|
-
const node_version = task.required_node_version ?? process.version;
|
|
50
|
-
const builder_package = task.builder_package;
|
|
51
|
-
const builder_script = task.builder_script;
|
|
52
|
-
const { bin_path, node_bin, npm_bin } = tool_paths[node_version];
|
|
53
|
-
const builder_bin = path.resolve(bin_path, builder_script);
|
|
54
|
-
|
|
55
|
-
if (!jetpack.exists(node_bin)) {
|
|
56
|
-
throw new Error(`Node binary not found: ${node_bin}`);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
console.debug(`[${task.task_name}] Installing builder script "${builder_package}" for node ${node_version}`);
|
|
60
|
-
// debug(`Installing builder script "${builder_package}" for node ${node_version}`);
|
|
61
|
-
|
|
62
|
-
const stream1 = runCommand(node_bin, [npm_bin, '--global', 'install', builder_package], {
|
|
63
|
-
cwd: project_path,
|
|
64
|
-
env: process.env
|
|
65
|
-
});
|
|
66
|
-
for await (let event of stream1) {
|
|
67
|
-
const log = event.stdout ?? event.stderr;
|
|
68
|
-
if (log) {
|
|
69
|
-
console.log(`[${task.task_name} - install]`, log.trimRight());
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (!jetpack.exists(builder_bin)) {
|
|
74
|
-
console.error(`[${task.task_name}] ${builder_bin} not found`);
|
|
75
|
-
throw new Error(`Builder script not found for task ${task.task_name}`);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const builder_args: string[] = [];
|
|
79
|
-
// --src ./ --out ./dist/echo --task echo --appId 'appid' --env 'testing' --backendId 'backendid' --backendUrl 'http://run.journeyapps.test'
|
|
80
|
-
builder_args.push(builder_bin);
|
|
81
|
-
builder_args.push('--src', project_path);
|
|
82
|
-
builder_args.push(`--out`, path.join(dest, task.task_name));
|
|
83
|
-
builder_args.push(`--zip`, path.join(dest, `${task.task_name}.zip`));
|
|
84
|
-
builder_args.push(`--task`, `${task.task_name}`);
|
|
85
|
-
builder_args.push(`--appId`, config.app_id);
|
|
86
|
-
builder_args.push(`--env`, config.env);
|
|
87
|
-
builder_args.push(`--backendId`, config.backend_id);
|
|
88
|
-
builder_args.push(`--backendUrl`, config.backend_url);
|
|
89
|
-
// builder_args.push(`--runInstallScripts`, 'true'); // TODO: handle this from feature flags somehow
|
|
90
|
-
|
|
91
|
-
console.debug(`[${task.task_name}] Trying: ${node_bin} ${builder_args.join(' ')}`);
|
|
92
|
-
// debug(`Trying: ${node_bin} ${builder_args.join(' ')}`);
|
|
93
|
-
|
|
94
|
-
const stream2 = runCommand(node_bin, builder_args, { cwd: project_path, env: process.env });
|
|
95
|
-
|
|
96
|
-
for await (let event of stream2) {
|
|
97
|
-
const log = event.stdout ?? event.stderr;
|
|
98
|
-
if (log) {
|
|
99
|
-
console.log(`[${task.task_name} - build]`, log.trimRight());
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// console.debug('----');
|
|
104
|
-
}
|
|
105
|
-
}
|
package/src/cli.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import * as yargs from 'yargs';
|
|
4
|
-
|
|
5
|
-
import { buildTasks } from './';
|
|
6
|
-
|
|
7
|
-
const DEFAULT_SRC_PATH = './';
|
|
8
|
-
const DEFAULT_OUT_PATH = './dist';
|
|
9
|
-
|
|
10
|
-
yargs
|
|
11
|
-
.command(
|
|
12
|
-
['build', '$0'], // $0 means this is the default command
|
|
13
|
-
'build tasks',
|
|
14
|
-
(yargs) => {
|
|
15
|
-
return (
|
|
16
|
-
yargs
|
|
17
|
-
.option('only', { string: true })
|
|
18
|
-
.option('path', { default: DEFAULT_SRC_PATH })
|
|
19
|
-
.option('out', { default: DEFAULT_OUT_PATH })
|
|
20
|
-
// TODO: investigate yargs.config() for reading task config blob from a file. But how to ensure required args?
|
|
21
|
-
.option('appId', { string: true, demandOption: true, describe: "CloudCode's reference id" })
|
|
22
|
-
.option('env', { string: true, demandOption: true })
|
|
23
|
-
.option('backendId', { string: true, demandOption: true })
|
|
24
|
-
.option('backendUrl', { string: true, demandOption: true })
|
|
25
|
-
);
|
|
26
|
-
},
|
|
27
|
-
handled(async (argv) => {
|
|
28
|
-
const config = {
|
|
29
|
-
app_id: argv.appId,
|
|
30
|
-
env: argv.env,
|
|
31
|
-
backend_id: argv.backendId,
|
|
32
|
-
backend_url: argv.backendUrl
|
|
33
|
-
};
|
|
34
|
-
await buildTasks(argv.path, argv.out, config, argv.only);
|
|
35
|
-
})
|
|
36
|
-
)
|
|
37
|
-
.option('verbose', {
|
|
38
|
-
alias: 'v',
|
|
39
|
-
default: false
|
|
40
|
-
}).argv;
|
|
41
|
-
|
|
42
|
-
function handled<T>(fn: (argv: T) => Promise<void>): (argv: T) => Promise<void> {
|
|
43
|
-
return async (argv: T) => {
|
|
44
|
-
try {
|
|
45
|
-
await fn(argv);
|
|
46
|
-
} catch (err) {
|
|
47
|
-
console.error(err.stack);
|
|
48
|
-
process.exit(1);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}
|
package/src/defs.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// TODO: maybe publish (some of) this from the CC service?
|
|
2
|
-
export const SUPPORTED_VERSIONS = [
|
|
3
|
-
{
|
|
4
|
-
// proposed
|
|
5
|
-
version: '1.13.0',
|
|
6
|
-
node: '16.19.1',
|
|
7
|
-
builder_package: '@journeyapps/cloudcode-build@1.13.0',
|
|
8
|
-
builder_script: 'cloudcode-build'
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
version: '1.12.0',
|
|
12
|
-
node: '16.19.1', // FIXME: maybe the very specific node version here is too brittle?
|
|
13
|
-
// builder_package: '@journeyapps/cloudcode-build-legacy@1.12.0'
|
|
14
|
-
// DEV HACK:
|
|
15
|
-
builder_package: '~/src/journey-cloudcode/packages/cloudcode-build-legacy',
|
|
16
|
-
builder_script: 'cloudcode-build-legacy'
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
version: '1.11.2',
|
|
20
|
-
// node: '14.21.3',
|
|
21
|
-
// builder_package: '@journeyapps/cloudcode-build-legacy@1.12.0'
|
|
22
|
-
// DEV HACK:
|
|
23
|
-
node: '16.19.1', // because local dev on darwin/arm64 and there's no darwin-arm64 builds for node14 available.
|
|
24
|
-
builder_package: '~/src/journey-cloudcode/packages/cloudcode-build-legacy',
|
|
25
|
-
builder_script: 'cloudcode-build-legacy'
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
version: '1.11.1',
|
|
29
|
-
// node: '14.21.3',
|
|
30
|
-
// builder_package: '@journeyapps/cloudcode-build-legacy@1.12.0'
|
|
31
|
-
// DEV HACK:
|
|
32
|
-
node: '16.19.1', // because local dev on darwin/arm64 and there's no darwin-arm64 builds for node14 available.
|
|
33
|
-
builder_package: '~/src/journey-cloudcode/packages/cloudcode-build-legacy',
|
|
34
|
-
builder_script: 'cloudcode-build-legacy'
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
version: '1.11.0',
|
|
38
|
-
// node: '14.21.3',
|
|
39
|
-
// builder_package: '@journeyapps/cloudcode-build-legacy@1.12.0'
|
|
40
|
-
// DEV HACK:
|
|
41
|
-
node: '16.19.1', // because local dev on darwin/arm64 and there's no darwin-arm64 builds for node14 available.
|
|
42
|
-
builder_package: '~/src/journey-cloudcode/packages/cloudcode-build-legacy',
|
|
43
|
-
builder_script: 'cloudcode-build-legacy'
|
|
44
|
-
}
|
|
45
|
-
];
|
package/src/detect_tasks.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import * as fs from 'node:fs';
|
|
2
|
-
import * as path from 'node:path';
|
|
3
|
-
import * as jetpack from 'fs-jetpack';
|
|
4
|
-
import * as semver from 'semver';
|
|
5
|
-
import * as defs from './defs';
|
|
6
|
-
|
|
7
|
-
// TODO: validations for cloudcode specific keys and structure?
|
|
8
|
-
async function readPackage(path: string) {
|
|
9
|
-
try {
|
|
10
|
-
const content = await fs.promises.readFile(path, { encoding: 'utf-8' });
|
|
11
|
-
return JSON.parse(content);
|
|
12
|
-
} catch (err) {
|
|
13
|
-
console.error(`ERROR: ${err}`);
|
|
14
|
-
throw err;
|
|
15
|
-
// todo: check for enoent and skip?
|
|
16
|
-
// todo: if json error, throw a CC build error?
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export async function detectTasks(project_path: string, only?: string) {
|
|
21
|
-
const package_files = await jetpack.findAsync(path.join(project_path, 'cloudcode'), { matching: '**/package.json' });
|
|
22
|
-
const filtered_package_files = package_files.filter((pkg_path) => {
|
|
23
|
-
// FIXME: this is kinda clunky.
|
|
24
|
-
const pm = /^\/?cloudcode\/([^\/]+)\/package\.json$/.exec(pkg_path);
|
|
25
|
-
if (!pm) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
const taskName = pm[1];
|
|
29
|
-
|
|
30
|
-
if (only != null && only != taskName) {
|
|
31
|
-
// !(only.indexOf(taskName) >= 0) // TODO: support a specific list of tasks to build?
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
return true;
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
return Promise.all(
|
|
38
|
-
filtered_package_files.map(async (pkg_path) => {
|
|
39
|
-
const task_package = await readPackage(pkg_path);
|
|
40
|
-
|
|
41
|
-
const task_name = task_package.name; // CAVEAT: the pkg name _must_ match the dir.
|
|
42
|
-
const task_version = task_package?.cloudcode?.runtime;
|
|
43
|
-
// FIXME: Do we want to filter out disabled tasks from the build process?
|
|
44
|
-
|
|
45
|
-
console.debug(`Detected task version ${task_version}`);
|
|
46
|
-
|
|
47
|
-
const matching = defs.SUPPORTED_VERSIONS.find((v) => {
|
|
48
|
-
return semver.satisfies(v.version, task_version);
|
|
49
|
-
});
|
|
50
|
-
if (!matching) {
|
|
51
|
-
throw new Error('FIXME: unsupported version');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
console.debug(`Matching versions: ${JSON.stringify(matching)}`);
|
|
55
|
-
|
|
56
|
-
const running_node_version = process.versions.node;
|
|
57
|
-
let required_node_version;
|
|
58
|
-
// if (matching?.node && semver.major(matching.node) !== semver.major(running_node_version)) {
|
|
59
|
-
if (matching?.node && semver.parse(matching.node) !== semver.parse(running_node_version)) {
|
|
60
|
-
console.debug(`Task requires different node version: v${matching.node}`);
|
|
61
|
-
|
|
62
|
-
required_node_version = matching.node;
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
pkg_path,
|
|
66
|
-
task_name,
|
|
67
|
-
task_version,
|
|
68
|
-
required_node_version,
|
|
69
|
-
builder_package: matching.builder_package,
|
|
70
|
-
builder_script: matching.builder_script
|
|
71
|
-
};
|
|
72
|
-
})
|
|
73
|
-
);
|
|
74
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './builder';
|
package/src/installer.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import fetch from 'node-fetch';
|
|
2
|
-
import * as path from 'node:path';
|
|
3
|
-
import * as fs from 'node:fs';
|
|
4
|
-
import * as os from 'node:os';
|
|
5
|
-
import * as URL from 'node:url';
|
|
6
|
-
import * as tar from 'tar';
|
|
7
|
-
|
|
8
|
-
/* Basically this, but for different dirs.
|
|
9
|
-
curl https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${PLATFORM}64.tar.gz -L | tar -xzC /node-dedicated && \
|
|
10
|
-
mv /node-dedicated/node-v${NODE_VERSION}-linux-${PLATFORM}64/bin/node /node-dedicated/node
|
|
11
|
-
*/
|
|
12
|
-
// TODO: feature to find the latest minor and patch for a given major version?
|
|
13
|
-
export async function downloadAndInstallNode(node_version: string, destination: string) {
|
|
14
|
-
// eg. https://nodejs.org/dist/v18.14.2/node-v18.14.2-linux-x64.tar.xz
|
|
15
|
-
|
|
16
|
-
// const PLATFORM = 'x';
|
|
17
|
-
// const node_download_url = `https://nodejs.org/dist/v${node_version}/node-v${node_version}-linux-${PLATFORM}64.tar.gz`;
|
|
18
|
-
|
|
19
|
-
// TODO: this is just for dev for now. Find a better fix.
|
|
20
|
-
const ARCH = os.arch();
|
|
21
|
-
const PLATFORM = os.platform();
|
|
22
|
-
const node_download_url = `https://nodejs.org/dist/v${node_version}/node-v${node_version}-${PLATFORM}-${ARCH}.tar.gz`;
|
|
23
|
-
|
|
24
|
-
await downloadAndExtractTarball(node_download_url, destination);
|
|
25
|
-
// TODO: move binaries into local bin path?
|
|
26
|
-
return nodePaths(destination);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function nodePaths(destination: string) {
|
|
30
|
-
return {
|
|
31
|
-
bin_path: path.resolve(destination, 'bin'),
|
|
32
|
-
node_bin: path.resolve(destination, 'bin', 'node'),
|
|
33
|
-
npm_bin: path.resolve(destination, 'bin', 'npm')
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export async function downloadAndExtractTarball(url: string, dest: string) {
|
|
38
|
-
const tmpdir = os.tmpdir();
|
|
39
|
-
|
|
40
|
-
const filename = path.basename(URL.parse(url).pathname as string);
|
|
41
|
-
const base = path.basename(filename, '.tar.gz');
|
|
42
|
-
const download = path.join(tmpdir, filename);
|
|
43
|
-
|
|
44
|
-
if (fs.existsSync(download)) {
|
|
45
|
-
console.debug(`deleting old ${download}`);
|
|
46
|
-
fs.unlinkSync(download);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
await new Promise(async (resolve, reject) => {
|
|
50
|
-
console.log(`fetching ${url} into ${download}`);
|
|
51
|
-
|
|
52
|
-
const response = await fetch(url);
|
|
53
|
-
if (!response.ok) {
|
|
54
|
-
const errorBody = await response.statusText;
|
|
55
|
-
throw new Error(`Failed to download: ${errorBody}`);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const file = fs.createWriteStream(download); // Sink the download stream into a file, so it can be extracted.
|
|
59
|
-
response.body.pipe(file);
|
|
60
|
-
|
|
61
|
-
file.on('finish', async () => {
|
|
62
|
-
try {
|
|
63
|
-
console.log('Extracting...', download);
|
|
64
|
-
|
|
65
|
-
// const comp = fs.createReadStream(download);
|
|
66
|
-
|
|
67
|
-
tar.extract({
|
|
68
|
-
cwd: tmpdir,
|
|
69
|
-
file: download,
|
|
70
|
-
sync: true
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const uncomp = path.join(tmpdir, base);
|
|
74
|
-
|
|
75
|
-
const dist = path.resolve(dest);
|
|
76
|
-
// FIXME: dangerous. Add protection or replace.
|
|
77
|
-
// if (fs.existsSync(dist)) {
|
|
78
|
-
// fs.rmSync(dist, { recursive: true });
|
|
79
|
-
// }
|
|
80
|
-
if (fs.existsSync(uncomp)) {
|
|
81
|
-
console.log(`Moving extracted files from ${uncomp} to ${dist}`);
|
|
82
|
-
fs.renameSync(uncomp, dist);
|
|
83
|
-
} else {
|
|
84
|
-
console.log(`Can't find extract dir ${uncomp}`);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// FIXME: this seems to sometimes cause errors
|
|
88
|
-
/*
|
|
89
|
-
----
|
|
90
|
-
node:events:505
|
|
91
|
-
throw er; // Unhandled 'error' event
|
|
92
|
-
^
|
|
93
|
-
|
|
94
|
-
Error: ENOENT: no such file or directory, open '/var/folders/kc/h6m4zpmd23v13s63mygvkslm0000gn/T/node-v16.19.1-darwin-arm64.tar.gz'
|
|
95
|
-
Emitted 'error' event on ReadStream instance at:
|
|
96
|
-
at emitErrorNT (node:internal/streams/destroy:157:8)
|
|
97
|
-
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
|
|
98
|
-
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
|
|
99
|
-
errno: -2,
|
|
100
|
-
code: 'ENOENT',
|
|
101
|
-
syscall: 'open',
|
|
102
|
-
path: '/var/folders/kc/h6m4zpmd23v13s63mygvkslm0000gn/T/node-v16.19.1-darwin-arm64.tar.gz'
|
|
103
|
-
*/
|
|
104
|
-
// fs.unlinkSync(file.path);
|
|
105
|
-
|
|
106
|
-
resolve(null);
|
|
107
|
-
} catch (err) {
|
|
108
|
-
reject(err);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
}
|
package/src/run.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { spawnStream, SpawnStreamEvent } from './spawn-stream';
|
|
2
|
-
import { SpawnOptions } from 'child_process';
|
|
3
|
-
|
|
4
|
-
export async function* runCommand(
|
|
5
|
-
command: string,
|
|
6
|
-
args: string[],
|
|
7
|
-
options?: Partial<SpawnOptions>
|
|
8
|
-
): AsyncIterable<SpawnStreamEvent> {
|
|
9
|
-
const { childProcess, stream } = spawnStream(command, args, { cwd: options?.cwd, splitLines: true, ...options });
|
|
10
|
-
|
|
11
|
-
let exitCode: number | null = null;
|
|
12
|
-
|
|
13
|
-
for await (let event of stream) {
|
|
14
|
-
yield event;
|
|
15
|
-
if (event.exitCode != null) {
|
|
16
|
-
exitCode = event.exitCode;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (exitCode != 0) {
|
|
21
|
-
throw new Error(`Command failed with code ${exitCode}`);
|
|
22
|
-
}
|
|
23
|
-
}
|
package/src/spawn-stream.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { ChildProcess, spawn, SpawnOptions } from 'child_process';
|
|
2
|
-
import { PassThrough, Readable } from 'stream';
|
|
3
|
-
|
|
4
|
-
export interface StreamOptions {
|
|
5
|
-
splitLines?: boolean;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function spawnStream(command: string, args: string[], options: SpawnOptions & StreamOptions) {
|
|
9
|
-
const process = spawn(command, args, {
|
|
10
|
-
...options,
|
|
11
|
-
stdio: 'pipe'
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
childProcess: process,
|
|
16
|
-
stream: processToStream(process, options)
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface SpawnStreamEvent {
|
|
21
|
-
event: 'stdout' | 'stderr' | 'exit';
|
|
22
|
-
stdout?: string;
|
|
23
|
-
stderr?: string;
|
|
24
|
-
exitCode?: number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function processToStream(process: ChildProcess, options: StreamOptions): AsyncIterable<SpawnStreamEvent> {
|
|
28
|
-
const combinedStream = new PassThrough({ objectMode: true });
|
|
29
|
-
|
|
30
|
-
async function* transform(stream: Readable, key: 'stdout' | 'stderr'): AsyncIterable<SpawnStreamEvent> {
|
|
31
|
-
stream.setEncoding('utf-8');
|
|
32
|
-
let iterable: AsyncIterable<string> = stream;
|
|
33
|
-
if (options.splitLines) {
|
|
34
|
-
iterable = splitLines(iterable);
|
|
35
|
-
}
|
|
36
|
-
for await (const chunk of iterable) {
|
|
37
|
-
yield {
|
|
38
|
-
event: key,
|
|
39
|
-
[key]: chunk
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (process.stdout) {
|
|
45
|
-
Readable.from(transform(process.stdout, 'stdout')).pipe(combinedStream, { end: false });
|
|
46
|
-
}
|
|
47
|
-
if (process.stderr) {
|
|
48
|
-
Readable.from(transform(process.stderr, 'stderr')).pipe(combinedStream, { end: false });
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
process.on('exit', (code: number | null) => {
|
|
52
|
-
combinedStream.write({ exitCode: code }, () => {
|
|
53
|
-
combinedStream.end();
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
return combinedStream;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async function* splitLines(stream: AsyncIterable<string>): AsyncIterable<string> {
|
|
61
|
-
let buffer = '';
|
|
62
|
-
for await (const chunk of stream) {
|
|
63
|
-
buffer += chunk;
|
|
64
|
-
const lines = buffer.split('\n');
|
|
65
|
-
buffer = lines.pop()!;
|
|
66
|
-
for (let line of lines) {
|
|
67
|
-
yield `${line}\n`;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (buffer) {
|
|
71
|
-
yield buffer;
|
|
72
|
-
}
|
|
73
|
-
}
|