@journeyapps/cloudcode-build-agent 0.0.0-dev.8ebefb0 → 0.0.0-dev.9188dcc
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 +1 -7
- package/dist/builder.js +4 -106
- package/dist/builder.js.map +1 -1
- package/dist/cli.js +22 -17
- package/dist/cli.js.map +1 -1
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +21 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/installer.d.ts +1 -11
- package/dist/installer.js +58 -99
- package/dist/installer.js.map +1 -1
- package/package.json +2 -12
- package/src/builder.ts +5 -103
- package/src/cli.ts +31 -22
- package/src/errors.ts +22 -0
- package/src/index.ts +2 -0
- package/src/installer.ts +62 -106
- package/tsconfig.json +2 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/defs.d.ts +0 -6
- package/dist/defs.js +0 -49
- package/dist/defs.js.map +0 -1
- package/dist/detect_tasks.d.ts +0 -8
- package/dist/detect_tasks.js +0 -91
- package/dist/detect_tasks.js.map +0 -1
- package/dist/run.d.ts +0 -4
- package/dist/run.js +0 -19
- package/dist/run.js.map +0 -1
- package/dist/spawn-stream.d.ts +0 -15
- package/dist/spawn-stream.js +0 -59
- package/dist/spawn-stream.js.map +0 -1
- package/src/defs.ts +0 -45
- package/src/detect_tasks.ts +0 -74
- package/src/run.ts +0 -23
- package/src/spawn-stream.ts +0 -73
package/dist/builder.d.ts
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
app_id: string;
|
|
3
|
-
env: string;
|
|
4
|
-
backend_id: string;
|
|
5
|
-
backend_url: string;
|
|
6
|
-
};
|
|
7
|
-
export declare function buildTasks(project_path: string, dest: string, config: GeneralTaskConfig, only?: string): Promise<void>;
|
|
1
|
+
export declare function buildTasks(src: string, dest: string, only?: string): Promise<void>;
|
package/dist/builder.js
CHANGED
|
@@ -1,111 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.buildTasks = void 0;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const semver = __importStar(require("semver"));
|
|
30
|
-
const utils = __importStar(require("./installer"));
|
|
31
|
-
const detect_tasks_1 = require("./detect_tasks");
|
|
32
|
-
const run_1 = require("./run");
|
|
33
|
-
const _ = __importStar(require("lodash"));
|
|
34
|
-
async function buildTasks(project_path, dest, config, only) {
|
|
35
|
-
const tasks = await (0, detect_tasks_1.detectTasks)(project_path, only);
|
|
36
|
-
const required_node_versions = _.compact(tasks.map((t) => t.required_node_version));
|
|
37
|
-
const install_node_versions = _.uniq(required_node_versions);
|
|
38
|
-
// FIXME: Maybe refactor this section into an ensureNodeVersion (or something) that returns the relevant toolpaths?
|
|
39
|
-
const tool_paths = {};
|
|
40
|
-
// Use the version of nodejs that's running this script as the default.
|
|
41
|
-
const default_tool_paths = {
|
|
42
|
-
bin_path: path.dirname(process.execPath),
|
|
43
|
-
node_bin: process.execPath,
|
|
44
|
-
npm_bin: path.join(path.dirname(process.execPath), 'npm')
|
|
45
|
-
};
|
|
46
|
-
tool_paths[process.version] = default_tool_paths;
|
|
47
|
-
for (const required_node_version of install_node_versions) {
|
|
48
|
-
// FIXME: put this in another directory to avoid leaking into the builder
|
|
49
|
-
const custom_node_path = path.resolve(`node-${semver.major(required_node_version)}`);
|
|
50
|
-
if (!jetpack.exists(path.join(custom_node_path, 'bin/node'))) {
|
|
51
|
-
console.debug(`installing to ${custom_node_path}`);
|
|
52
|
-
await jetpack.dirAsync(custom_node_path);
|
|
53
|
-
await utils.downloadAndInstallNode(required_node_version, custom_node_path);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
console.debug(`already installed in ${custom_node_path}`);
|
|
57
|
-
}
|
|
58
|
-
tool_paths[required_node_version] = utils.nodePaths(custom_node_path);
|
|
59
|
-
}
|
|
60
|
-
// console.debug('----');
|
|
61
|
-
for (const task of tasks) {
|
|
62
|
-
const node_version = task.required_node_version ?? process.version;
|
|
63
|
-
const builder_package = task.builder_package;
|
|
64
|
-
const builder_script = task.builder_script;
|
|
65
|
-
const { bin_path, node_bin, npm_bin } = tool_paths[node_version];
|
|
66
|
-
const builder_bin = path.resolve(bin_path, builder_script);
|
|
67
|
-
if (!jetpack.exists(node_bin)) {
|
|
68
|
-
throw new Error(`Node binary not found: ${node_bin}`);
|
|
69
|
-
}
|
|
70
|
-
console.debug(`[${task.task_name}] Installing builder script "${builder_package}" for node ${node_version}`);
|
|
71
|
-
// debug(`Installing builder script "${builder_package}" for node ${node_version}`);
|
|
72
|
-
const stream1 = (0, run_1.runCommand)(node_bin, [npm_bin, '--global', 'install', builder_package], {
|
|
73
|
-
cwd: project_path,
|
|
74
|
-
env: process.env
|
|
75
|
-
});
|
|
76
|
-
for await (let event of stream1) {
|
|
77
|
-
const log = event.stdout ?? event.stderr;
|
|
78
|
-
if (log) {
|
|
79
|
-
console.log(`[${task.task_name} - install]`, log.trimRight());
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
if (!jetpack.exists(builder_bin)) {
|
|
83
|
-
console.error(`[${task.task_name}] ${builder_bin} not found`);
|
|
84
|
-
throw new Error(`Builder script not found for task ${task.task_name}`);
|
|
85
|
-
}
|
|
86
|
-
const builder_args = [];
|
|
87
|
-
// --src ./ --out ./dist/echo --task echo --appId 'appid' --env 'testing' --backendId 'backendid' --backendUrl 'http://run.journeyapps.test'
|
|
88
|
-
builder_args.push(builder_bin);
|
|
89
|
-
builder_args.push('--src', project_path);
|
|
90
|
-
builder_args.push(`--out`, path.join(dest, task.task_name));
|
|
91
|
-
builder_args.push(`--zip`, path.join(dest, `${task.task_name}.zip`));
|
|
92
|
-
builder_args.push(`--task`, `${task.task_name}`);
|
|
93
|
-
builder_args.push(`--appId`, config.app_id);
|
|
94
|
-
builder_args.push(`--env`, config.env);
|
|
95
|
-
builder_args.push(`--backendId`, config.backend_id);
|
|
96
|
-
builder_args.push(`--backendUrl`, config.backend_url);
|
|
97
|
-
// builder_args.push(`--runInstallScripts`, 'true'); // TODO: handle this from feature flags somehow
|
|
98
|
-
console.debug(`[${task.task_name}] Trying: ${node_bin} ${builder_args.join(' ')}`);
|
|
99
|
-
// debug(`Trying: ${node_bin} ${builder_args.join(' ')}`);
|
|
100
|
-
const stream2 = (0, run_1.runCommand)(node_bin, builder_args, { cwd: project_path, env: process.env });
|
|
101
|
-
for await (let event of stream2) {
|
|
102
|
-
const log = event.stdout ?? event.stderr;
|
|
103
|
-
if (log) {
|
|
104
|
-
console.log(`[${task.task_name} - build]`, log.trimRight());
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
// console.debug('----');
|
|
108
|
-
}
|
|
109
|
-
}
|
|
4
|
+
// Detect tasks in given path and build them.
|
|
5
|
+
async function buildTasks(src, dest, only) { }
|
|
110
6
|
exports.buildTasks = buildTasks;
|
|
7
|
+
// Build a single task in the specified subdirectory.
|
|
8
|
+
async function buildTask(src, dest, config) { }
|
|
111
9
|
//# sourceMappingURL=builder.js.map
|
package/dist/builder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":";;;AAEA,6CAA6C;AACtC,KAAK,UAAU,UAAU,CAAC,GAAW,EAAE,IAAY,EAAE,IAAa,IAAG,CAAC;AAA7E,gCAA6E;AAE7E,qDAAqD;AACrD,KAAK,UAAU,SAAS,CAAC,GAAW,EAAE,IAAY,EAAE,MAAW,IAAG,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -27,27 +27,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
27
27
|
const yargs = __importStar(require("yargs"));
|
|
28
28
|
const _1 = require("./");
|
|
29
29
|
const DEFAULT_SRC_PATH = './';
|
|
30
|
-
const DEFAULT_OUT_PATH = '
|
|
30
|
+
const DEFAULT_OUT_PATH = '';
|
|
31
31
|
yargs
|
|
32
32
|
.command(['build', '$0'], // $0 means this is the default command
|
|
33
33
|
'build tasks', (yargs) => {
|
|
34
|
-
return
|
|
34
|
+
return yargs
|
|
35
35
|
.option('only', { string: true })
|
|
36
36
|
.option('path', { default: DEFAULT_SRC_PATH })
|
|
37
|
-
.option('out', { default: DEFAULT_OUT_PATH })
|
|
38
|
-
// TODO: investigate yargs.config() for reading task config blob from a file. But how to ensure required args?
|
|
39
|
-
.option('appId', { string: true, demandOption: true, describe: "CloudCode's reference id" })
|
|
40
|
-
.option('env', { string: true, demandOption: true })
|
|
41
|
-
.option('backendId', { string: true, demandOption: true })
|
|
42
|
-
.option('backendUrl', { string: true, demandOption: true }));
|
|
37
|
+
.option('out', { default: DEFAULT_OUT_PATH });
|
|
43
38
|
}, handled(async (argv) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
};
|
|
50
|
-
|
|
39
|
+
// iterate over task directories and run: 'yarn cloudcode-build'.
|
|
40
|
+
// optionally filtered by `argv.only` to build a single task.
|
|
41
|
+
await (0, _1.buildTasks)(argv.path, argv.out, argv.only);
|
|
42
|
+
}))
|
|
43
|
+
.command('prepare-env', 'Install node environments and packages for each task', (yargs) => {
|
|
44
|
+
return yargs.option('only', { string: true }).option('path', { default: DEFAULT_SRC_PATH });
|
|
45
|
+
}, handled(async (argv) => {
|
|
46
|
+
// iterate over task directories:
|
|
47
|
+
// ensure required node version for task CC version is installed - What if too old - error?
|
|
48
|
+
// run yarn install
|
|
49
|
+
await (0, _1.prepareBuildEnvForTasks)(argv.path, argv.only);
|
|
51
50
|
}))
|
|
52
51
|
.option('verbose', {
|
|
53
52
|
alias: 'v',
|
|
@@ -59,8 +58,14 @@ function handled(fn) {
|
|
|
59
58
|
await fn(argv);
|
|
60
59
|
}
|
|
61
60
|
catch (err) {
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
if (err instanceof _1.ProcessError) {
|
|
62
|
+
console.error(err.message);
|
|
63
|
+
process.exit(err.status);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
console.error(err.stack);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
64
69
|
}
|
|
65
70
|
};
|
|
66
71
|
}
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,6C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,CAAC,SAAS,EAAE;IACjB,KAAK,EAAE,GAAG;IACV,OAAO,EAAE,KAAK;CACf,CAAC,CAAC,IAAI,CAAC;AAEV,SAAS,OAAO,CAAI,EAA8B;IAChD,OAAO,KAAK,EAAE,IAAO,EAAE,EAAE;QACvB,IAAI;YACF,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;SAChB;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,GAAG,YAAY,eAAY,EAAE;gBAC/B,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBAC3B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;aAC1B;iBAAM;gBACL,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;SACF;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/errors.d.ts
ADDED
package/dist/errors.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProcessError = void 0;
|
|
4
|
+
class ProcessError extends Error {
|
|
5
|
+
constructor(result) {
|
|
6
|
+
super(constructMessage(result));
|
|
7
|
+
this.result = result;
|
|
8
|
+
if (result.error) {
|
|
9
|
+
this.cause = result.error;
|
|
10
|
+
}
|
|
11
|
+
this.status = result.status || 1;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ProcessError = ProcessError;
|
|
15
|
+
function constructMessage(result) {
|
|
16
|
+
if (result.error) {
|
|
17
|
+
return result.error.message;
|
|
18
|
+
}
|
|
19
|
+
return `${result.stdout}${result.stderr}`.trim();
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAEA,MAAa,YAAa,SAAQ,KAAK;IAIrC,YAAmB,MAAgC;QACjD,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;QADf,WAAM,GAAN,MAAM,CAA0B;QAGjD,IAAI,MAAM,CAAC,KAAK,EAAE;YAChB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;SAC3B;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC;IACnC,CAAC;CACF;AAZD,oCAYC;AAED,SAAS,gBAAgB,CAAC,MAAgC;IACxD,IAAI,MAAM,CAAC,KAAK,EAAE;QAChB,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC;KAC7B;IACD,OAAO,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC;AACnD,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,5 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./errors"), exports);
|
|
17
18
|
__exportStar(require("./builder"), exports);
|
|
19
|
+
__exportStar(require("./installer"), exports);
|
|
18
20
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,4CAA0B;AAC1B,8CAA4B"}
|
package/dist/installer.d.ts
CHANGED
|
@@ -1,11 +1 @@
|
|
|
1
|
-
export declare function
|
|
2
|
-
bin_path: string;
|
|
3
|
-
node_bin: string;
|
|
4
|
-
npm_bin: string;
|
|
5
|
-
}>;
|
|
6
|
-
export declare function nodePaths(destination: string): {
|
|
7
|
-
bin_path: string;
|
|
8
|
-
node_bin: string;
|
|
9
|
-
npm_bin: string;
|
|
10
|
-
};
|
|
11
|
-
export declare function downloadAndExtractTarball(url: string, dest: string): Promise<void>;
|
|
1
|
+
export declare function prepareBuildEnvForTasks(project_path: string, only?: string): Promise<void>;
|
package/dist/installer.js
CHANGED
|
@@ -22,108 +22,67 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
30
|
-
const
|
|
26
|
+
exports.prepareBuildEnvForTasks = void 0;
|
|
27
|
+
const fs = __importStar(require("node:fs/promises"));
|
|
31
28
|
const path = __importStar(require("node:path"));
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
await downloadAndExtractTarball(node_download_url, destination);
|
|
50
|
-
// TODO: move binaries into local bin path?
|
|
51
|
-
return nodePaths(destination);
|
|
52
|
-
}
|
|
53
|
-
exports.downloadAndInstallNode = downloadAndInstallNode;
|
|
54
|
-
function nodePaths(destination) {
|
|
55
|
-
return {
|
|
56
|
-
bin_path: path.resolve(destination, 'bin'),
|
|
57
|
-
node_bin: path.resolve(destination, 'bin', 'node'),
|
|
58
|
-
npm_bin: path.resolve(destination, 'bin', 'npm')
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
exports.nodePaths = nodePaths;
|
|
62
|
-
async function downloadAndExtractTarball(url, dest) {
|
|
63
|
-
const tmpdir = os.tmpdir();
|
|
64
|
-
const filename = path.basename(URL.parse(url).pathname);
|
|
65
|
-
const base = path.basename(filename, '.tar.gz');
|
|
66
|
-
const download = path.join(tmpdir, filename);
|
|
67
|
-
if (fs.existsSync(download)) {
|
|
68
|
-
console.debug(`deleting old ${download}`);
|
|
69
|
-
fs.unlinkSync(download);
|
|
29
|
+
const jetpack = __importStar(require("fs-jetpack"));
|
|
30
|
+
const SUPPORTED_VERSIONS = [
|
|
31
|
+
{
|
|
32
|
+
version: '1.12.0',
|
|
33
|
+
node: '16'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
version: '1.11.2',
|
|
37
|
+
node: '14'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
version: '1.11.1',
|
|
41
|
+
node: '14'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
version: '1.11.0',
|
|
45
|
+
node: '14'
|
|
70
46
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
47
|
+
];
|
|
48
|
+
async function prepareBuildEnvForTasks(project_path, only) {
|
|
49
|
+
// const subdirs = (await fs.readdir(project_path, { withFileTypes: true }))
|
|
50
|
+
// .filter((dirent) => dirent.isDirectory())
|
|
51
|
+
// .map((d) => d.name);
|
|
52
|
+
// for (const dir of subdirs) {
|
|
53
|
+
// try {
|
|
54
|
+
// } catch (err) {
|
|
55
|
+
// console.error(`ERROR: ${err}`)
|
|
56
|
+
// // todo: check for enoent and skip
|
|
57
|
+
// // todo: if json error, throw a CC build error
|
|
58
|
+
// }
|
|
59
|
+
// }
|
|
60
|
+
const package_files = await jetpack.findAsync(path.join(project_path, 'cloudcode'), { matching: '**/package.json' });
|
|
61
|
+
for (const pkg_path of package_files) {
|
|
62
|
+
console.log(pkg_path);
|
|
63
|
+
const pm = /^\/?cloudcode\/([^\/]+)\/package\.json$/.exec(pkg_path);
|
|
64
|
+
if (!pm) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const taskName = pm[1];
|
|
68
|
+
if (only != null && only != taskName) {
|
|
69
|
+
// !(only.indexOf(taskName) >= 0)
|
|
70
|
+
continue;
|
|
77
71
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// if (fs.existsSync(dist)) {
|
|
93
|
-
// fs.rmSync(dist, { recursive: true });
|
|
94
|
-
// }
|
|
95
|
-
if (fs.existsSync(uncomp)) {
|
|
96
|
-
console.log(`Moving extracted files from ${uncomp} to ${dist}`);
|
|
97
|
-
fs.renameSync(uncomp, dist);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
console.log(`Can't find extract dir ${uncomp}`);
|
|
101
|
-
}
|
|
102
|
-
// FIXME: this seems to sometimes cause errors
|
|
103
|
-
/*
|
|
104
|
-
----
|
|
105
|
-
node:events:505
|
|
106
|
-
throw er; // Unhandled 'error' event
|
|
107
|
-
^
|
|
108
|
-
|
|
109
|
-
Error: ENOENT: no such file or directory, open '/var/folders/kc/h6m4zpmd23v13s63mygvkslm0000gn/T/node-v16.19.1-darwin-arm64.tar.gz'
|
|
110
|
-
Emitted 'error' event on ReadStream instance at:
|
|
111
|
-
at emitErrorNT (node:internal/streams/destroy:157:8)
|
|
112
|
-
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
|
|
113
|
-
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
|
|
114
|
-
errno: -2,
|
|
115
|
-
code: 'ENOENT',
|
|
116
|
-
syscall: 'open',
|
|
117
|
-
path: '/var/folders/kc/h6m4zpmd23v13s63mygvkslm0000gn/T/node-v16.19.1-darwin-arm64.tar.gz'
|
|
118
|
-
*/
|
|
119
|
-
// fs.unlinkSync(file.path);
|
|
120
|
-
resolve(null);
|
|
121
|
-
}
|
|
122
|
-
catch (err) {
|
|
123
|
-
reject(err);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
});
|
|
72
|
+
try {
|
|
73
|
+
const content = await fs.readFile(pkg_path, { encoding: 'utf-8' });
|
|
74
|
+
const task_package = JSON.parse(content);
|
|
75
|
+
const task_version = task_package?.cloudcode?.runtime;
|
|
76
|
+
// check task version against supported versions, install relevant node version and yarn
|
|
77
|
+
// cwd into directory and run the correct node's yarn.
|
|
78
|
+
console.log(`Detected task version ${task_version}`);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
console.error(`ERROR: ${err}`);
|
|
82
|
+
// todo: check for enoent and skip
|
|
83
|
+
// todo: if json error, throw a CC build error
|
|
84
|
+
}
|
|
85
|
+
}
|
|
127
86
|
}
|
|
128
|
-
exports.
|
|
87
|
+
exports.prepareBuildEnvForTasks = prepareBuildEnvForTasks;
|
|
129
88
|
//# sourceMappingURL=installer.js.map
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qDAAuC;AACvC,gDAAkC;AAClC,oDAAsC;AAEtC,MAAM,kBAAkB,GAAG;IACzB;QACE,OAAO,EAAE,QAAQ;QACjB,IAAI,EAAE,IAAI;KACX;IACD;QACE,OAAO,EAAE,QAAQ;QACjB,IAAI,EAAE,IAAI;KACX;IACD;QACE,OAAO,EAAE,QAAQ;QACjB,IAAI,EAA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YAC/B,kCAAkC;YAClC,8CAA8C;SAC/C;KACF;AACH,CAAC;AA3CD,0DA2CC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@journeyapps/cloudcode-build-agent",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.9188dcc",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index",
|
|
6
6
|
"types": "./dist/index",
|
|
@@ -9,21 +9,11 @@
|
|
|
9
9
|
"cloudcode-build-agent": "./bin.js"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"child-process-promise": "^2.2.1",
|
|
13
12
|
"fs-jetpack": "5.1.0",
|
|
14
|
-
"lodash": "4.17.21",
|
|
15
|
-
"node-fetch": "<3",
|
|
16
|
-
"semver": "7.3.8",
|
|
17
|
-
"tar": "6.1.13",
|
|
18
13
|
"yargs": "17.6.2"
|
|
19
14
|
},
|
|
20
15
|
"devDependencies": {
|
|
21
|
-
"@types/
|
|
22
|
-
"@types/lodash": "4.14.191",
|
|
23
|
-
"@types/node": "14.18.36",
|
|
24
|
-
"@types/node-fetch": "2.6.2",
|
|
25
|
-
"@types/semver": "7.3.13",
|
|
26
|
-
"@types/tar": "6.1.4",
|
|
16
|
+
"@types/node": "^18.6.3",
|
|
27
17
|
"@types/yargs": "17.0.22",
|
|
28
18
|
"typescript": "4.9.5"
|
|
29
19
|
},
|
package/src/builder.ts
CHANGED
|
@@ -1,105 +1,7 @@
|
|
|
1
|
-
import
|
|
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';
|
|
1
|
+
import { spawnSync } from 'child_process';
|
|
7
2
|
|
|
8
|
-
|
|
3
|
+
// Detect tasks in given path and build them.
|
|
4
|
+
export async function buildTasks(src: string, dest: string, only?: string) {}
|
|
9
5
|
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
}
|
|
6
|
+
// Build a single task in the specified subdirectory.
|
|
7
|
+
async function buildTask(src: string, dest: string, config: any) {}
|