@journeyapps/cloudcode-build-agent 0.0.0-dev.3868b04 → 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 -21
- package/dist/builder.js +6 -94
- package/dist/builder.js.map +1 -1
- package/dist/cli.js +22 -22
- package/dist/cli.js.map +1 -1
- package/dist/defs.js +25 -14
- package/dist/defs.js.map +1 -1
- package/dist/detect_tasks.d.ts +5 -6
- package/dist/detect_tasks.js +4 -3
- 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 -16
- package/dist/installer.js +61 -107
- 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 -8
- package/src/builder.ts +11 -0
- package/src/cli.ts +60 -0
- package/src/defs.ts +45 -0
- package/src/detect_tasks.ts +73 -0
- package/src/errors.ts +22 -0
- package/src/index.ts +3 -0
- package/src/installer.ts +82 -0
- package/src/utils.ts +82 -0
- package/tsconfig.json +9 -0
- package/tsconfig.tsbuildinfo +1 -0
- 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/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;AAC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C;YAEjF,MAAM,kBAAkB,GAAG,IAAA,yBAAS,EAAC,QAAQ,EAAE,YAAY,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,CAAC;YAEpF,IAAI,kBAAkB,CAAC,MAAM,KAAK,CAAC,EAAE;gBACnC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,SAAS,gCAAgC,CAAC,CAAC;gBAChE,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;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,8EA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
2
|
"name": "@journeyapps/cloudcode-build-agent",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.55699c3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index",
|
|
6
6
|
"types": "./dist/index",
|
|
@@ -8,12 +8,7 @@
|
|
|
8
8
|
"bin": {
|
|
9
9
|
"cloudcode-build-agent": "./bin.js"
|
|
10
10
|
},
|
|
11
|
-
"files": [
|
|
12
|
-
"bin.js",
|
|
13
|
-
"dist"
|
|
14
|
-
],
|
|
15
11
|
"dependencies": {
|
|
16
|
-
"child-process-promise": "^2.2.1",
|
|
17
12
|
"fs-jetpack": "5.1.0",
|
|
18
13
|
"lodash": "4.17.21",
|
|
19
14
|
"node-fetch": "<3",
|
|
@@ -22,9 +17,8 @@
|
|
|
22
17
|
"yargs": "17.6.2"
|
|
23
18
|
},
|
|
24
19
|
"devDependencies": {
|
|
25
|
-
"@types/child-process-promise": "2.2.2",
|
|
26
20
|
"@types/lodash": "4.14.191",
|
|
27
|
-
"@types/node": "
|
|
21
|
+
"@types/node": "16.11.7",
|
|
28
22
|
"@types/node-fetch": "2.6.2",
|
|
29
23
|
"@types/semver": "7.3.13",
|
|
30
24
|
"@types/tar": "6.1.4",
|
package/src/builder.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { spawnSync } from 'child_process';
|
|
2
|
+
import { detectTasks } from './detect_tasks';
|
|
3
|
+
|
|
4
|
+
// Detect tasks in given path and build them.
|
|
5
|
+
export async function buildTasks(project_path: string, dest: string, config: any, only?: string) {
|
|
6
|
+
const tasks = await detectTasks(project_path, only);
|
|
7
|
+
|
|
8
|
+
for (const t of tasks) {
|
|
9
|
+
// await t.drink()
|
|
10
|
+
}
|
|
11
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import * as yargs from 'yargs';
|
|
4
|
+
|
|
5
|
+
import { ProcessError, buildTasks, prepareBuildEnvForTasks } from './';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_SRC_PATH = './';
|
|
8
|
+
const DEFAULT_OUT_PATH = '';
|
|
9
|
+
|
|
10
|
+
yargs
|
|
11
|
+
.command(
|
|
12
|
+
['build', '$0'], // $0 means this is the default command
|
|
13
|
+
'build tasks',
|
|
14
|
+
(yargs) => {
|
|
15
|
+
return yargs
|
|
16
|
+
.option('only', { string: true })
|
|
17
|
+
.option('path', { default: DEFAULT_SRC_PATH })
|
|
18
|
+
.option('out', { default: DEFAULT_OUT_PATH });
|
|
19
|
+
},
|
|
20
|
+
handled(async (argv) => {
|
|
21
|
+
// iterate over task directories and run: 'yarn cloudcode-build'.
|
|
22
|
+
// optionally filtered by `argv.only` to build a single task.
|
|
23
|
+
|
|
24
|
+
await buildTasks(argv.path, argv.out, argv.only);
|
|
25
|
+
})
|
|
26
|
+
)
|
|
27
|
+
.command(
|
|
28
|
+
'prepare-env',
|
|
29
|
+
'Install node environments and packages for each task',
|
|
30
|
+
(yargs) => {
|
|
31
|
+
return yargs.option('only', { string: true }).option('path', { default: DEFAULT_SRC_PATH });
|
|
32
|
+
},
|
|
33
|
+
handled(async (argv) => {
|
|
34
|
+
// iterate over task directories:
|
|
35
|
+
// ensure required node version for task CC version is installed - What if too old - error?
|
|
36
|
+
// run yarn install
|
|
37
|
+
|
|
38
|
+
await prepareBuildEnvForTasks(argv.path, argv.only);
|
|
39
|
+
})
|
|
40
|
+
)
|
|
41
|
+
.option('verbose', {
|
|
42
|
+
alias: 'v',
|
|
43
|
+
default: false
|
|
44
|
+
}).argv;
|
|
45
|
+
|
|
46
|
+
function handled<T>(fn: (argv: T) => Promise<void>): (argv: T) => Promise<void> {
|
|
47
|
+
return async (argv: T) => {
|
|
48
|
+
try {
|
|
49
|
+
await fn(argv);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
if (err instanceof ProcessError) {
|
|
52
|
+
console.error(err.message);
|
|
53
|
+
process.exit(err.status);
|
|
54
|
+
} else {
|
|
55
|
+
console.error(err.stack);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
package/src/defs.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
];
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
|
|
44
|
+
console.debug(`Detected task version ${task_version}`);
|
|
45
|
+
|
|
46
|
+
const matching = defs.SUPPORTED_VERSIONS.find((v) => {
|
|
47
|
+
return semver.satisfies(v.version, task_version);
|
|
48
|
+
});
|
|
49
|
+
if (!matching) {
|
|
50
|
+
throw new Error('FIXME: unsupported version');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
console.debug(`Matching versions: ${JSON.stringify(matching)}`);
|
|
54
|
+
|
|
55
|
+
const running_node_version = process.versions.node;
|
|
56
|
+
let required_node_version;
|
|
57
|
+
// if (matching?.node && semver.major(matching.node) !== semver.major(running_node_version)) {
|
|
58
|
+
if (matching?.node && semver.parse(matching.node) !== semver.parse(running_node_version)) {
|
|
59
|
+
console.debug(`Task requires different node version: v${matching.node}`);
|
|
60
|
+
|
|
61
|
+
required_node_version = matching.node;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
pkg_path,
|
|
65
|
+
task_name,
|
|
66
|
+
task_version,
|
|
67
|
+
required_node_version,
|
|
68
|
+
builder_package: matching.builder_package,
|
|
69
|
+
builder_script: matching.builder_script
|
|
70
|
+
};
|
|
71
|
+
})
|
|
72
|
+
);
|
|
73
|
+
}
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SpawnSyncReturns } from 'child_process';
|
|
2
|
+
|
|
3
|
+
export class ProcessError extends Error {
|
|
4
|
+
cause?: Error;
|
|
5
|
+
status: number;
|
|
6
|
+
|
|
7
|
+
constructor(public result: SpawnSyncReturns<string>) {
|
|
8
|
+
super(constructMessage(result));
|
|
9
|
+
|
|
10
|
+
if (result.error) {
|
|
11
|
+
this.cause = result.error;
|
|
12
|
+
}
|
|
13
|
+
this.status = result.status || 1;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function constructMessage(result: SpawnSyncReturns<string>): string {
|
|
18
|
+
if (result.error) {
|
|
19
|
+
return result.error.message;
|
|
20
|
+
}
|
|
21
|
+
return `${result.stdout}${result.stderr}`.trim();
|
|
22
|
+
}
|
package/src/index.ts
ADDED
package/src/installer.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
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 utils from './utils';
|
|
6
|
+
import { spawnSync } from 'child_process';
|
|
7
|
+
import { detectTasks } from './detect_tasks';
|
|
8
|
+
|
|
9
|
+
import * as _ from 'lodash';
|
|
10
|
+
|
|
11
|
+
export async function prepareBuildEnvForTasks(project_path: string, only?: string) {
|
|
12
|
+
const tasks = await detectTasks(project_path, only);
|
|
13
|
+
|
|
14
|
+
const required_node_versions = _.compact(tasks.map((t) => t.required_node_version));
|
|
15
|
+
const install_node_versions = _.uniq(required_node_versions);
|
|
16
|
+
|
|
17
|
+
const tool_paths: Record<string, { bin_path: string; node_bin: string; npm_bin: string }> = {};
|
|
18
|
+
for (const required_node_version of install_node_versions) {
|
|
19
|
+
// FIXME: maybe a path prefix.
|
|
20
|
+
const custom_node_path = path.resolve(`node-${semver.major(required_node_version)}`);
|
|
21
|
+
|
|
22
|
+
if (!jetpack.exists(custom_node_path)) {
|
|
23
|
+
console.log(`installing to ${custom_node_path}`);
|
|
24
|
+
await jetpack.dirAsync(custom_node_path);
|
|
25
|
+
await utils.downloadAndInstallNode(required_node_version, custom_node_path);
|
|
26
|
+
} else {
|
|
27
|
+
console.log(`already installed in ${custom_node_path}`);
|
|
28
|
+
}
|
|
29
|
+
tool_paths[required_node_version] = utils.nodePaths(custom_node_path);
|
|
30
|
+
}
|
|
31
|
+
console.log('----');
|
|
32
|
+
|
|
33
|
+
for (const task of tasks) {
|
|
34
|
+
const node_version = task.required_node_version ?? process.version;
|
|
35
|
+
const builder_package = task.builder_package;
|
|
36
|
+
const builder_script = task.builder_script;
|
|
37
|
+
console.log(`[${task.task_name}] Installing builder script "${builder_package}" for node ${node_version}`);
|
|
38
|
+
const { bin_path, node_bin, npm_bin } = tool_paths[node_version];
|
|
39
|
+
const builder_bin = path.resolve(bin_path, builder_script);
|
|
40
|
+
|
|
41
|
+
// 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?
|
|
42
|
+
const spawnResult = spawnSync(node_bin, [npm_bin, '--global', 'install', builder_package], { cwd: project_path });
|
|
43
|
+
if (spawnResult.status == 0 && jetpack.exists(builder_bin)) {
|
|
44
|
+
// DEV HACK: this needs to move to the build thingie.
|
|
45
|
+
|
|
46
|
+
const builder_args: string[] = [];
|
|
47
|
+
// --src ~/src/cool-app-bro-master --out ~/src/dist --task echo --appId 'appid' --env 'testing' --backendId 'backendid' --backendUrl 'http://run.journeyapps.test'
|
|
48
|
+
builder_args.push(builder_bin);
|
|
49
|
+
// // builder_args.push('--version')
|
|
50
|
+
builder_args.push('--src', './');
|
|
51
|
+
builder_args.push(`--out`, `./dist/${task.task_name}`);
|
|
52
|
+
builder_args.push(`--task`, `${task.task_name}`);
|
|
53
|
+
builder_args.push(
|
|
54
|
+
`--appId`,
|
|
55
|
+
'appid',
|
|
56
|
+
`--env`,
|
|
57
|
+
'testing',
|
|
58
|
+
`--backendId`,
|
|
59
|
+
'backendid',
|
|
60
|
+
`--backendUrl`,
|
|
61
|
+
'http://run.journeyapps.test'
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
console.log(`[${task.task_name}] Trying: ${node_bin} ${builder_args.join(' ')}`);
|
|
65
|
+
|
|
66
|
+
const builderSpawnResult = spawnSync(node_bin, builder_args, { cwd: project_path });
|
|
67
|
+
|
|
68
|
+
if (builderSpawnResult.status !== 0) {
|
|
69
|
+
console.log(`[${task.task_name}] FAILED TO RUN BUILDER SCRIPT`);
|
|
70
|
+
console.log(`[${task.task_name}] OUTPUT: ${builderSpawnResult.stdout}`);
|
|
71
|
+
console.log(`[${task.task_name}] ERROR: ${builderSpawnResult.stderr}`);
|
|
72
|
+
} else {
|
|
73
|
+
console.log(`[${task.task_name}] SCRIPT SUCCESS?`);
|
|
74
|
+
console.log(`[${task.task_name}] OUTPUT: ${builderSpawnResult.stdout}`);
|
|
75
|
+
console.log(`[${task.task_name}] ERROR: ${builderSpawnResult.stderr}`);
|
|
76
|
+
}
|
|
77
|
+
console.log('----');
|
|
78
|
+
} else {
|
|
79
|
+
console.log(`[${task.task_name}] failed to install ${builder_package}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
console.log(`fetching ${url}`);
|
|
45
|
+
|
|
46
|
+
const file = fs.createWriteStream(download);
|
|
47
|
+
const response = await fetch(url);
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
const errorBody = await response.statusText;
|
|
50
|
+
throw new Error(`Failed to download: ${errorBody}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// FIXME: replace with webstreams?
|
|
54
|
+
response.body.pipe(file);
|
|
55
|
+
|
|
56
|
+
file.on('finish', async () => {
|
|
57
|
+
console.log('Extracting...', download);
|
|
58
|
+
|
|
59
|
+
const comp = fs.createReadStream(download);
|
|
60
|
+
|
|
61
|
+
tar.extract({
|
|
62
|
+
cwd: tmpdir,
|
|
63
|
+
file: comp.path as string,
|
|
64
|
+
sync: true
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const uncomp = path.join(tmpdir, base);
|
|
68
|
+
|
|
69
|
+
const dist = path.resolve(dest);
|
|
70
|
+
// FIXME: dangerous. Add protection or replace.
|
|
71
|
+
// if (fs.existsSync(dist)) {
|
|
72
|
+
// fs.rmSync(dist, { recursive: true });
|
|
73
|
+
// }
|
|
74
|
+
if (fs.existsSync(uncomp)) {
|
|
75
|
+
console.log(`Moving extracted files from ${uncomp} to ${dist}`);
|
|
76
|
+
fs.renameSync(uncomp, dist);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// FIXME: this seems to sometimes cause errors
|
|
80
|
+
// fs.unlinkSync(file.path);
|
|
81
|
+
});
|
|
82
|
+
}
|