@journeyapps/cloudcode-build-agent 0.0.0-dev.2b3e822 → 0.0.0-dev.55699c3
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 +3 -88
- package/dist/builder.js.map +1 -1
- package/dist/cli.js +22 -17
- package/dist/cli.js.map +1 -1
- package/dist/detect_tasks.js +0 -1
- package/dist/detect_tasks.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 +61 -99
- package/dist/installer.js.map +1 -1
- package/dist/utils.d.ts +11 -0
- package/dist/utils.js +99 -0
- package/dist/utils.js.map +1 -0
- package/package.json +2 -5
- package/src/builder.ts +5 -88
- package/src/cli.ts +31 -22
- package/src/detect_tasks.ts +0 -1
- package/src/errors.ts +22 -0
- package/src/index.ts +2 -0
- package/src/installer.ts +78 -109
- package/src/utils.ts +82 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/run.d.ts +0 -10
- package/dist/run.js +0 -90
- package/dist/run.js.map +0 -1
- package/src/run.ts +0 -112
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(project_path: string, dest: string, config: any, only?: string): Promise<void>;
|
package/dist/builder.js
CHANGED
|
@@ -1,97 +1,12 @@
|
|
|
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
|
-
const path = __importStar(require("node:path"));
|
|
28
|
-
const jetpack = __importStar(require("fs-jetpack"));
|
|
29
|
-
const semver = __importStar(require("semver"));
|
|
30
|
-
const utils = __importStar(require("./installer"));
|
|
31
4
|
const detect_tasks_1 = require("./detect_tasks");
|
|
32
|
-
|
|
33
|
-
const _ = __importStar(require("lodash"));
|
|
5
|
+
// Detect tasks in given path and build them.
|
|
34
6
|
async function buildTasks(project_path, dest, config, only) {
|
|
35
7
|
const tasks = await (0, detect_tasks_1.detectTasks)(project_path, only);
|
|
36
|
-
const
|
|
37
|
-
|
|
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 debug = require('debug')(`${task.task_name}`);
|
|
63
|
-
const node_version = task.required_node_version ?? process.version;
|
|
64
|
-
const builder_package = task.builder_package;
|
|
65
|
-
const builder_script = task.builder_script;
|
|
66
|
-
const { bin_path, node_bin, npm_bin } = tool_paths[node_version];
|
|
67
|
-
const builder_bin = path.resolve(bin_path, builder_script);
|
|
68
|
-
if (!jetpack.exists(node_bin)) {
|
|
69
|
-
throw new Error(`Node binary not found: ${node_bin}`);
|
|
70
|
-
}
|
|
71
|
-
// console.debug(`[${task.task_name}] Installing builder script "${builder_package}" for node ${node_version}`);
|
|
72
|
-
debug(`Installing builder script "${builder_package}" for node ${node_version}`);
|
|
73
|
-
// TODO: This may need to be replaced with the something like the spawn-stream stuff in build-agent? OR what to do with the stdout/stderr and errorhandling?
|
|
74
|
-
await (0, run_1.runCommand)(node_bin, [npm_bin, '--global', 'install', builder_package], { cwd: project_path }, { task_name: task.task_name });
|
|
75
|
-
if (!jetpack.exists(builder_bin)) {
|
|
76
|
-
console.error(`[${task.task_name}] ${builder_bin} not found`);
|
|
77
|
-
throw new Error(`Builder script not found for task ${task.task_name}`);
|
|
78
|
-
}
|
|
79
|
-
const builder_args = [];
|
|
80
|
-
// --src ./ --out ./dist/echo --task echo --appId 'appid' --env 'testing' --backendId 'backendid' --backendUrl 'http://run.journeyapps.test'
|
|
81
|
-
builder_args.push(builder_bin);
|
|
82
|
-
builder_args.push('--src', project_path);
|
|
83
|
-
builder_args.push(`--out`, path.join(dest, task.task_name));
|
|
84
|
-
builder_args.push(`--zip`, path.join(dest, `${task.task_name}.zip`));
|
|
85
|
-
builder_args.push(`--task`, `${task.task_name}`);
|
|
86
|
-
builder_args.push(`--appId`, config.app_id);
|
|
87
|
-
builder_args.push(`--env`, config.env);
|
|
88
|
-
builder_args.push(`--backendId`, config.backend_id);
|
|
89
|
-
builder_args.push(`--backendUrl`, config.backend_url);
|
|
90
|
-
// builder_args.push(`--runInstallScripts`, 'true'); // TODO: handle this from feature flags somehow
|
|
91
|
-
// console.debug(`[${task.task_name}] Trying: ${node_bin} ${builder_args.join(' ')}`);
|
|
92
|
-
debug(`Trying: ${node_bin} ${builder_args.join(' ')}`);
|
|
93
|
-
await (0, run_1.runCommand)(node_bin, builder_args, { cwd: project_path }, { task_name: task.task_name });
|
|
94
|
-
console.debug('----');
|
|
8
|
+
for (const t of tasks) {
|
|
9
|
+
// await t.drink()
|
|
95
10
|
}
|
|
96
11
|
}
|
|
97
12
|
exports.buildTasks = buildTasks;
|
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":";;;AACA,iDAA6C;AAE7C,6CAA6C;AACtC,KAAK,UAAU,UAAU,CAAC,YAAoB,EAAE,IAAY,EAAE,MAAW,EAAE,IAAa;IAC7F,MAAM,KAAK,GAAG,MAAM,IAAA,0BAAW,EAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAEpD,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE;QACrB,kBAAkB;KACnB;AACH,CAAC;AAND,gCAMC"}
|
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,6CAA+B;AAE/B,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,6CAA+B;AAE/B,yBAAuE;AAEvE,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAC9B,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B,KAAK;KACF,OAAO,CACN,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,uCAAuC;AACxD,aAAa,EACb,CAAC,KAAK,EAAE,EAAE;IACR,OAAO,KAAK;SACT,MAAM,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,IAA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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/detect_tasks.js
CHANGED
|
@@ -61,7 +61,6 @@ async function detectTasks(project_path, only) {
|
|
|
61
61
|
const task_package = await readPackage(pkg_path);
|
|
62
62
|
const task_name = task_package.name; // CAVEAT: the pkg name _must_ match the dir.
|
|
63
63
|
const task_version = task_package?.cloudcode?.runtime;
|
|
64
|
-
// FIXME: Do we want to filter out disabled tasks from the build process?
|
|
65
64
|
console.debug(`Detected task version ${task_version}`);
|
|
66
65
|
const matching = defs.SUPPORTED_VERSIONS.find((v) => {
|
|
67
66
|
return semver.satisfies(v.version, task_version);
|
package/dist/detect_tasks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect_tasks.js","sourceRoot":"","sources":["../src/detect_tasks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAClC,oDAAsC;AACtC,+CAAiC;AACjC,6CAA+B;AAE/B,+DAA+D;AAC/D,KAAK,UAAU,WAAW,CAAC,IAAY;IACrC,IAAI;QACF,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QACxE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;KAC5B;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,CAAC,KAAK,CAAC,UAAU,GAAG,EAAE,CAAC,CAAC;QAC/B,MAAM,GAAG,CAAC;QACV,mCAAmC;QACnC,+CAA+C;KAChD;AACH,CAAC;AAEM,KAAK,UAAU,WAAW,CAAC,YAAoB,EAAE,IAAa;IACnE,MAAM,aAAa,GA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C,CAAC,CAAC,EAAE,EAAE;YAClD,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,EAAE;YACb,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;SAC/C;QAED,OAAO,CAAC,KAAK,CAAC,sBAAsB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAEhE,MAAM,oBAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;QACnD,IAAI,qBAAqB,CAAC;QAC1B,8FAA8F;QAC9F,IAAI,QAAQ,EAAE,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,EAAE;YACxF,OAAO,CAAC,KAAK,CAAC,0CAA0C,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;YAEzE,qBAAqB,GAAG,QAAQ,CAAC,IAAI,CAAC;SACvC;QACD,OAAO;YACL,QAAQ;YACR,SAAS;YACT,YAAY;YACZ,qBAAqB;YACrB,eAAe,EAAE,QAAQ,CAAC,eAAe;YACzC,cAAc,EAAE,QAAQ,CAAC,cAAc;SACxC,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AArDD,kCAqDC"}
|
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,109 +22,71 @@ 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 node_fetch_1 = __importDefault(require("node-fetch"));
|
|
26
|
+
exports.prepareBuildEnvForTasks = void 0;
|
|
31
27
|
const path = __importStar(require("node:path"));
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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);
|
|
70
|
-
}
|
|
71
|
-
await new Promise(async (resolve, reject) => {
|
|
72
|
-
console.log(`fetching ${url} into ${download}`);
|
|
73
|
-
const response = await (0, node_fetch_1.default)(url);
|
|
74
|
-
if (!response.ok) {
|
|
75
|
-
const errorBody = await response.statusText;
|
|
76
|
-
throw new Error(`Failed to download: ${errorBody}`);
|
|
28
|
+
const jetpack = __importStar(require("fs-jetpack"));
|
|
29
|
+
const semver = __importStar(require("semver"));
|
|
30
|
+
const utils = __importStar(require("./utils"));
|
|
31
|
+
const child_process_1 = require("child_process");
|
|
32
|
+
const detect_tasks_1 = require("./detect_tasks");
|
|
33
|
+
const _ = __importStar(require("lodash"));
|
|
34
|
+
async function prepareBuildEnvForTasks(project_path, 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
|
+
const tool_paths = {};
|
|
39
|
+
for (const required_node_version of install_node_versions) {
|
|
40
|
+
// FIXME: maybe a path prefix.
|
|
41
|
+
const custom_node_path = path.resolve(`node-${semver.major(required_node_version)}`);
|
|
42
|
+
if (!jetpack.exists(custom_node_path)) {
|
|
43
|
+
console.log(`installing to ${custom_node_path}`);
|
|
44
|
+
await jetpack.dirAsync(custom_node_path);
|
|
45
|
+
await utils.downloadAndInstallNode(required_node_version, custom_node_path);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
console.log(`already installed in ${custom_node_path}`);
|
|
77
49
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
node:events:505
|
|
107
|
-
throw er; // Unhandled 'error' event
|
|
108
|
-
^
|
|
109
|
-
|
|
110
|
-
Error: ENOENT: no such file or directory, open '/var/folders/kc/h6m4zpmd23v13s63mygvkslm0000gn/T/node-v16.19.1-darwin-arm64.tar.gz'
|
|
111
|
-
Emitted 'error' event on ReadStream instance at:
|
|
112
|
-
at emitErrorNT (node:internal/streams/destroy:157:8)
|
|
113
|
-
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
|
|
114
|
-
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
|
|
115
|
-
errno: -2,
|
|
116
|
-
code: 'ENOENT',
|
|
117
|
-
syscall: 'open',
|
|
118
|
-
path: '/var/folders/kc/h6m4zpmd23v13s63mygvkslm0000gn/T/node-v16.19.1-darwin-arm64.tar.gz'
|
|
119
|
-
*/
|
|
120
|
-
// fs.unlinkSync(file.path);
|
|
121
|
-
resolve(null);
|
|
50
|
+
tool_paths[required_node_version] = utils.nodePaths(custom_node_path);
|
|
51
|
+
}
|
|
52
|
+
console.log('----');
|
|
53
|
+
for (const task of tasks) {
|
|
54
|
+
const node_version = task.required_node_version ?? process.version;
|
|
55
|
+
const builder_package = task.builder_package;
|
|
56
|
+
const builder_script = task.builder_script;
|
|
57
|
+
console.log(`[${task.task_name}] Installing builder script "${builder_package}" for node ${node_version}`);
|
|
58
|
+
const { bin_path, node_bin, npm_bin } = tool_paths[node_version];
|
|
59
|
+
const builder_bin = path.resolve(bin_path, builder_script);
|
|
60
|
+
// TODO: This may need to be replaced with the something like the spawn-stream stuff in build-agent? OR what to do with the stdout/stderr and errorhandling?
|
|
61
|
+
const spawnResult = (0, child_process_1.spawnSync)(node_bin, [npm_bin, '--global', 'install', builder_package], { cwd: project_path });
|
|
62
|
+
if (spawnResult.status == 0 && jetpack.exists(builder_bin)) {
|
|
63
|
+
// DEV HACK: this needs to move to the build thingie.
|
|
64
|
+
const builder_args = [];
|
|
65
|
+
// --src ~/src/cool-app-bro-master --out ~/src/dist --task echo --appId 'appid' --env 'testing' --backendId 'backendid' --backendUrl 'http://run.journeyapps.test'
|
|
66
|
+
builder_args.push(builder_bin);
|
|
67
|
+
// // builder_args.push('--version')
|
|
68
|
+
builder_args.push('--src', './');
|
|
69
|
+
builder_args.push(`--out`, `./dist/${task.task_name}`);
|
|
70
|
+
builder_args.push(`--task`, `${task.task_name}`);
|
|
71
|
+
builder_args.push(`--appId`, 'appid', `--env`, 'testing', `--backendId`, 'backendid', `--backendUrl`, 'http://run.journeyapps.test');
|
|
72
|
+
console.log(`[${task.task_name}] Trying: ${node_bin} ${builder_args.join(' ')}`);
|
|
73
|
+
const builderSpawnResult = (0, child_process_1.spawnSync)(node_bin, builder_args, { cwd: project_path });
|
|
74
|
+
if (builderSpawnResult.status !== 0) {
|
|
75
|
+
console.log(`[${task.task_name}] FAILED TO RUN BUILDER SCRIPT`);
|
|
76
|
+
console.log(`[${task.task_name}] OUTPUT: ${builderSpawnResult.stdout}`);
|
|
77
|
+
console.log(`[${task.task_name}] ERROR: ${builderSpawnResult.stderr}`);
|
|
122
78
|
}
|
|
123
|
-
|
|
124
|
-
|
|
79
|
+
else {
|
|
80
|
+
console.log(`[${task.task_name}] SCRIPT SUCCESS?`);
|
|
81
|
+
console.log(`[${task.task_name}] OUTPUT: ${builderSpawnResult.stdout}`);
|
|
82
|
+
console.log(`[${task.task_name}] ERROR: ${builderSpawnResult.stderr}`);
|
|
125
83
|
}
|
|
126
|
-
|
|
127
|
-
|
|
84
|
+
console.log('----');
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
console.log(`[${task.task_name}] failed to install ${builder_package}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
128
90
|
}
|
|
129
|
-
exports.
|
|
91
|
+
exports.prepareBuildEnvForTasks = prepareBuildEnvForTasks;
|
|
130
92
|
//# 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,gDAAkC;AAClC,oDAAsC;AACtC,+CAAiC;AACjC,+CAAiC;AACjC,iDAA0C;AAC1C,iDAA6C;AAE7C,0CAA4B;AAErB,KAAK,UAAU,uBAAuB,CAAC,YAAoB,EAAE,IAAa;IAC/E,MAAM,KAAK,GAAG,MAAM,IAAA,0BAAW,EAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAEpD,MAAM,sBAAsB,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,C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E,CAAC,CAAC;gBACxE,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,SAAS,YAAY,kBAAkB,CAAC,MAAM,EAAE,CAAC,CAAC;aACxE;iBAAM;gBACL,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,SAAS,mBAAmB,CAAC,CAAC;gBACnD,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,SAAS,aAAa,kBAAkB,CAAC,MAAM,EAAE,CAAC,CAAC;gBACxE,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,SAAS,YAAY,kBAAkB,CAAC,MAAM,EAAE,CAAC,CAAC;aACxE;YACD,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;SACrB;aAAM;YACL,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,SAAS,uBAAuB,eAAe,EAAE,CAAC,CAAC;SACzE;KACF;AACH,CAAC;AAvED,0DAuEC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function downloadAndInstallNode(node_version: string, destination: string): Promise<{
|
|
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>;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.downloadAndExtractTarball = exports.nodePaths = exports.downloadAndInstallNode = void 0;
|
|
30
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
31
|
+
const path = __importStar(require("node:path"));
|
|
32
|
+
const fs = __importStar(require("node:fs"));
|
|
33
|
+
const os = __importStar(require("node:os"));
|
|
34
|
+
const URL = __importStar(require("node:url"));
|
|
35
|
+
const tar = __importStar(require("tar"));
|
|
36
|
+
/* Basically this, but for different dirs.
|
|
37
|
+
curl https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${PLATFORM}64.tar.gz -L | tar -xzC /node-dedicated && \
|
|
38
|
+
mv /node-dedicated/node-v${NODE_VERSION}-linux-${PLATFORM}64/bin/node /node-dedicated/node
|
|
39
|
+
*/
|
|
40
|
+
// TODO: feature to find the latest minor and patch for a given major version?
|
|
41
|
+
async function downloadAndInstallNode(node_version, destination) {
|
|
42
|
+
// eg. https://nodejs.org/dist/v18.14.2/node-v18.14.2-linux-x64.tar.xz
|
|
43
|
+
// const PLATFORM = 'x';
|
|
44
|
+
// const node_download_url = `https://nodejs.org/dist/v${node_version}/node-v${node_version}-linux-${PLATFORM}64.tar.gz`;
|
|
45
|
+
// TODO: this is just for dev for now. Find a better fix.
|
|
46
|
+
const ARCH = os.arch();
|
|
47
|
+
const PLATFORM = os.platform();
|
|
48
|
+
const node_download_url = `https://nodejs.org/dist/v${node_version}/node-v${node_version}-${PLATFORM}-${ARCH}.tar.gz`;
|
|
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
|
+
console.log(`fetching ${url}`);
|
|
68
|
+
const file = fs.createWriteStream(download);
|
|
69
|
+
const response = await (0, node_fetch_1.default)(url);
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
const errorBody = await response.statusText;
|
|
72
|
+
throw new Error(`Failed to download: ${errorBody}`);
|
|
73
|
+
}
|
|
74
|
+
// FIXME: replace with webstreams?
|
|
75
|
+
response.body.pipe(file);
|
|
76
|
+
file.on('finish', async () => {
|
|
77
|
+
console.log('Extracting...', download);
|
|
78
|
+
const comp = fs.createReadStream(download);
|
|
79
|
+
tar.extract({
|
|
80
|
+
cwd: tmpdir,
|
|
81
|
+
file: comp.path,
|
|
82
|
+
sync: true
|
|
83
|
+
});
|
|
84
|
+
const uncomp = path.join(tmpdir, base);
|
|
85
|
+
const dist = path.resolve(dest);
|
|
86
|
+
// FIXME: dangerous. Add protection or replace.
|
|
87
|
+
// if (fs.existsSync(dist)) {
|
|
88
|
+
// fs.rmSync(dist, { recursive: true });
|
|
89
|
+
// }
|
|
90
|
+
if (fs.existsSync(uncomp)) {
|
|
91
|
+
console.log(`Moving extracted files from ${uncomp} to ${dist}`);
|
|
92
|
+
fs.renameSync(uncomp, dist);
|
|
93
|
+
}
|
|
94
|
+
// FIXME: this seems to sometimes cause errors
|
|
95
|
+
// fs.unlinkSync(file.path);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
exports.downloadAndExtractTarball = downloadAndExtractTarball;
|
|
99
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA+B;AAC/B,gDAAkC;AAClC,4CAA8B;AAC9B,4CAA8B;AAC9B,8CAAgC;AAChC,yCAA2B;AAE3B;;;EAGE;AACF,8EAA8E;AACvE,KAAK,UAAU,sBAAsB,CAAC,YAAoB,EAAE,WAAmB;IACpF,sEAAsE;IAEtE,wBAAwB;IACxB,yHAAyH;IAEzH,yDAAyD;IACzD,MAAM,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;IACvB,MAAM,QAAQ,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC/B,MAAM,iBAAiB,GAAG,4BAA4B,YAAY,UAAU,YAAY,IAAI,QAAQ,IAAI,IAAI,SAAS,CAAC;IAEtH,MA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