@journeyapps/cloudcode-build-agent 0.0.0-dev.90a9f01 → 0.0.0-dev.9202033
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 +21 -1
- package/dist/builder.js +97 -5
- package/dist/builder.js.map +1 -1
- package/dist/cli.js +22 -22
- package/dist/cli.js.map +1 -1
- package/dist/defs.d.ts +6 -0
- package/dist/defs.js +38 -0
- package/dist/defs.js.map +1 -0
- package/dist/detect_tasks.d.ts +9 -0
- package/dist/detect_tasks.js +89 -0
- package/dist/detect_tasks.js.map +1 -0
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/installer.d.ts +16 -1
- package/dist/installer.js +106 -73
- package/dist/installer.js.map +1 -1
- package/dist/run.d.ts +4 -0
- package/dist/run.js +19 -0
- package/dist/run.js.map +1 -0
- package/dist/spawn-stream.d.ts +15 -0
- package/dist/spawn-stream.js +59 -0
- package/dist/spawn-stream.js.map +1 -0
- package/package.json +14 -4
- package/dist/errors.d.ts +0 -8
- package/dist/errors.js +0 -21
- package/dist/errors.js.map +0 -1
- package/dist/utils.d.ts +0 -2
- package/dist/utils.js +0 -83
- package/dist/utils.js.map +0 -1
- package/src/builder.ts +0 -7
- package/src/cli.ts +0 -60
- package/src/errors.ts +0 -22
- package/src/index.ts +0 -3
- package/src/installer.ts +0 -88
- package/src/utils.ts +0 -63
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
package/dist/run.d.ts
ADDED
package/dist/run.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runCommand = void 0;
|
|
4
|
+
const spawn_stream_1 = require("./spawn-stream");
|
|
5
|
+
async function* runCommand(command, args, options) {
|
|
6
|
+
const { childProcess, stream } = (0, spawn_stream_1.spawnStream)(command, args, { cwd: options?.cwd, splitLines: true, ...options });
|
|
7
|
+
let exitCode = null;
|
|
8
|
+
for await (let event of stream) {
|
|
9
|
+
yield event;
|
|
10
|
+
if (event.exitCode != null) {
|
|
11
|
+
exitCode = event.exitCode;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (exitCode != 0) {
|
|
15
|
+
throw new Error(`Command failed with code ${exitCode}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.runCommand = runCommand;
|
|
19
|
+
//# sourceMappingURL=run.js.map
|
package/dist/run.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":";;;AAAA,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;QAC9B,MAAM,KAAK,CAAC;QACZ,IAAI,KAAK,CAAC,QAAQ,IAAI,IAAI,EAAE;YAC1B,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;SAC3B;KACF;IAED,IAAI,QAAQ,IAAI,CAAC,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,4BAA4B,QAAQ,EAAE,CAAC,CAAC;KACzD;AACH,CAAC;AAnBD,gCAmBC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { SpawnOptions } from 'child_process';
|
|
3
|
+
export interface StreamOptions {
|
|
4
|
+
splitLines?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function spawnStream(command: string, args: string[], options: SpawnOptions & StreamOptions): {
|
|
7
|
+
childProcess: import("child_process").ChildProcessWithoutNullStreams;
|
|
8
|
+
stream: AsyncIterable<SpawnStreamEvent>;
|
|
9
|
+
};
|
|
10
|
+
export interface SpawnStreamEvent {
|
|
11
|
+
event: 'stdout' | 'stderr' | 'exit';
|
|
12
|
+
stdout?: string;
|
|
13
|
+
stderr?: string;
|
|
14
|
+
exitCode?: number;
|
|
15
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.spawnStream = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const stream_1 = require("stream");
|
|
6
|
+
function spawnStream(command, args, options) {
|
|
7
|
+
const process = (0, child_process_1.spawn)(command, args, {
|
|
8
|
+
...options,
|
|
9
|
+
stdio: 'pipe'
|
|
10
|
+
});
|
|
11
|
+
return {
|
|
12
|
+
childProcess: process,
|
|
13
|
+
stream: processToStream(process, options)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
exports.spawnStream = spawnStream;
|
|
17
|
+
function processToStream(process, options) {
|
|
18
|
+
const combinedStream = new stream_1.PassThrough({ objectMode: true });
|
|
19
|
+
async function* transform(stream, key) {
|
|
20
|
+
stream.setEncoding('utf-8');
|
|
21
|
+
let iterable = stream;
|
|
22
|
+
if (options.splitLines) {
|
|
23
|
+
iterable = splitLines(iterable);
|
|
24
|
+
}
|
|
25
|
+
for await (const chunk of iterable) {
|
|
26
|
+
yield {
|
|
27
|
+
event: key,
|
|
28
|
+
[key]: chunk
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (process.stdout) {
|
|
33
|
+
stream_1.Readable.from(transform(process.stdout, 'stdout')).pipe(combinedStream, { end: false });
|
|
34
|
+
}
|
|
35
|
+
if (process.stderr) {
|
|
36
|
+
stream_1.Readable.from(transform(process.stderr, 'stderr')).pipe(combinedStream, { end: false });
|
|
37
|
+
}
|
|
38
|
+
process.on('exit', (code) => {
|
|
39
|
+
combinedStream.write({ exitCode: code }, () => {
|
|
40
|
+
combinedStream.end();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
return combinedStream;
|
|
44
|
+
}
|
|
45
|
+
async function* splitLines(stream) {
|
|
46
|
+
let buffer = '';
|
|
47
|
+
for await (const chunk of stream) {
|
|
48
|
+
buffer += chunk;
|
|
49
|
+
const lines = buffer.split('\n');
|
|
50
|
+
buffer = lines.pop();
|
|
51
|
+
for (let line of lines) {
|
|
52
|
+
yield `${line}\n`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (buffer) {
|
|
56
|
+
yield buffer;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=spawn-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn-stream.js","sourceRoot":"","sources":["../src/spawn-stream.ts"],"names":[],"mappings":";;;AAAA,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;AAVD,kCAUC;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,C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AAG,CAAC;QACtB,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE;YACtB,MAAM,GAAG,IAAI,IAAI,CAAC;SACnB;KACF;IACD,IAAI,MAAM,EAAE;QACV,MAAM,MAAM,CAAC;KACd;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@journeyapps/cloudcode-build-agent",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "0.0.0-dev.9202033",
|
|
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": {
|
|
18
|
+
"child-process-promise": "^2.2.1",
|
|
12
19
|
"fs-jetpack": "5.1.0",
|
|
20
|
+
"lodash": "4.17.21",
|
|
13
21
|
"node-fetch": "<3",
|
|
14
22
|
"semver": "7.3.8",
|
|
15
23
|
"tar": "6.1.13",
|
|
16
24
|
"yargs": "17.6.2"
|
|
17
25
|
},
|
|
18
26
|
"devDependencies": {
|
|
19
|
-
"@types/
|
|
27
|
+
"@types/child-process-promise": "2.2.2",
|
|
28
|
+
"@types/lodash": "4.14.191",
|
|
29
|
+
"@types/node": "14.18.36",
|
|
20
30
|
"@types/node-fetch": "2.6.2",
|
|
21
31
|
"@types/semver": "7.3.13",
|
|
22
32
|
"@types/tar": "6.1.4",
|
package/dist/errors.d.ts
DELETED
package/dist/errors.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
package/dist/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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/utils.d.ts
DELETED
package/dist/utils.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
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.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
|
-
async function downloadAndInstallNode(node_version, destination) {
|
|
41
|
-
// eg. https://nodejs.org/dist/v18.14.2/node-v18.14.2-linux-x64.tar.xz
|
|
42
|
-
const PLATFORM = 'x';
|
|
43
|
-
const node_download_url = `https://nodejs.org/dist/v${node_version}/node-v${node_version}-linux-${PLATFORM}64.tar.gz`;
|
|
44
|
-
await downloadAndExtractTarball(node_download_url, destination);
|
|
45
|
-
// TODO: move binaries into local bin path?
|
|
46
|
-
}
|
|
47
|
-
exports.downloadAndInstallNode = downloadAndInstallNode;
|
|
48
|
-
async function downloadAndExtractTarball(url, dest) {
|
|
49
|
-
const tmpdir = os.tmpdir();
|
|
50
|
-
const filename = path.basename(URL.parse(url).pathname);
|
|
51
|
-
const base = path.basename(filename, '.tar.gz');
|
|
52
|
-
const download = path.join(tmpdir, filename);
|
|
53
|
-
const file = fs.createWriteStream(download);
|
|
54
|
-
const response = await (0, node_fetch_1.default)(url);
|
|
55
|
-
if (!response.ok) {
|
|
56
|
-
const errorBody = await response.text();
|
|
57
|
-
throw new Error(`Failed to download: ${errorBody}`);
|
|
58
|
-
}
|
|
59
|
-
// FIXME: replace with webstreams?
|
|
60
|
-
response.body.pipe(file);
|
|
61
|
-
file.on('finish', async () => {
|
|
62
|
-
console.log('Extracting...', download);
|
|
63
|
-
const comp = fs.createReadStream(download);
|
|
64
|
-
tar.extract({
|
|
65
|
-
cwd: tmpdir,
|
|
66
|
-
file: comp.path,
|
|
67
|
-
sync: true
|
|
68
|
-
});
|
|
69
|
-
const uncomp = path.join(tmpdir, base);
|
|
70
|
-
const dist = path.resolve(dest);
|
|
71
|
-
// FIXME: dangerous. Add protection or replace.
|
|
72
|
-
// if (fs.existsSync(dist)) {
|
|
73
|
-
// fs.rmSync(dist, { recursive: true });
|
|
74
|
-
// }
|
|
75
|
-
if (fs.existsSync(uncomp)) {
|
|
76
|
-
console.log(`Moving extracted files from ${uncomp} to ${dist}`);
|
|
77
|
-
fs.renameSync(uncomp, dist);
|
|
78
|
-
}
|
|
79
|
-
fs.unlinkSync(file.path);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
exports.downloadAndExtractTarball = downloadAndExtractTarball;
|
|
83
|
-
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;AACK,KAAK,UAAU,sBAAsB,CAAC,YAAoB,EAAE,WAAmB;IACpF,sEAAsE;IACtE,MAAM,QAAQ,GAAG,GAAG,CAAC;IACrB,MAAM,iBAAiB,GAAG,4BAA4B,YAAY,UAAU,YAAY,UAAU,QAAQ,WAAW,CAAC;IAEtH,MAAM,yBAAyB,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC;IAChE,2CAA2C;AAC7C,CAAC;AAPD,wDAOC;AAEM,KAAK,UAAU,yBAAyB,CAAC,GAAW,EAAE,IAAY;IACvE,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC;IAE3B,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAkB,CAAC,CAAC;IAClE,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAChD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,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1CD,8DA0CC"}
|
package/src/builder.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from 'child_process';
|
|
2
|
-
|
|
3
|
-
// Detect tasks in given path and build them.
|
|
4
|
-
export async function buildTasks(src: string, dest: string, only?: string) {}
|
|
5
|
-
|
|
6
|
-
// Build a single task in the specified subdirectory.
|
|
7
|
-
async function buildTask(src: string, dest: string, config: any) {}
|
package/src/cli.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
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/errors.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
DELETED
package/src/installer.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from 'child_process';
|
|
2
|
-
import * as fs from 'node:fs';
|
|
3
|
-
import * as path from 'node:path';
|
|
4
|
-
import * as jetpack from 'fs-jetpack';
|
|
5
|
-
import * as semver from 'semver';
|
|
6
|
-
import * as utils from './utils';
|
|
7
|
-
|
|
8
|
-
const SUPPORTED_VERSIONS = [
|
|
9
|
-
{
|
|
10
|
-
version: '1.12.0',
|
|
11
|
-
node: '16.19.1' // FIXME: this is maybe brittle?
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
version: '1.11.2',
|
|
15
|
-
node: '14.21.3'
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
version: '1.11.1',
|
|
19
|
-
node: '14.21.3'
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
version: '1.11.0',
|
|
23
|
-
node: '14.21.3'
|
|
24
|
-
}
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
export async function prepareBuildEnvForTasks(project_path: string, only?: string) {
|
|
28
|
-
const package_files = await jetpack.findAsync(path.join(project_path, 'cloudcode'), { matching: '**/package.json' });
|
|
29
|
-
const filtered_package_files = package_files.filter((pkg_path) => {
|
|
30
|
-
// FIXME: this is kinda clunky.
|
|
31
|
-
const pm = /^\/?cloudcode\/([^\/]+)\/package\.json$/.exec(pkg_path);
|
|
32
|
-
if (!pm) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
const taskName = pm[1];
|
|
36
|
-
|
|
37
|
-
if (only != null && only != taskName) {
|
|
38
|
-
// !(only.indexOf(taskName) >= 0)
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
return true;
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// FIXME: Would it be better to map out required node_versions and subsequently install them, or is this in-line approach okay?
|
|
45
|
-
/* TODO:
|
|
46
|
-
How to install and execute custom node version in a portable way?
|
|
47
|
-
- install to predictable path inside project dir, which is writeable in the container.
|
|
48
|
-
But how to run it from inside task dirs? local bin? ENV?
|
|
49
|
-
What about yarn for each node version?
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
for (const pkg_path of filtered_package_files) {
|
|
53
|
-
try {
|
|
54
|
-
const content = await fs.promises.readFile(pkg_path, { encoding: 'utf-8' });
|
|
55
|
-
const task_package = JSON.parse(content);
|
|
56
|
-
const task_version = task_package?.cloudcode?.runtime;
|
|
57
|
-
|
|
58
|
-
// check task version against supported versions, install relevant node version and yarn
|
|
59
|
-
console.log(`Detected task version ${task_version}`);
|
|
60
|
-
|
|
61
|
-
const matching = SUPPORTED_VERSIONS.find((v) => {
|
|
62
|
-
return semver.satisfies(v.version, task_version);
|
|
63
|
-
});
|
|
64
|
-
if (!matching) {
|
|
65
|
-
console.error('FIXME: unsupported version');
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
console.log(`Matching versions: ${JSON.stringify(matching)}`);
|
|
69
|
-
const running_node_version = process.versions.node;
|
|
70
|
-
if (matching?.node && semver.major(matching.node) !== semver.major(running_node_version)) {
|
|
71
|
-
console.log(`Task requires different node version: v${matching.node}`);
|
|
72
|
-
|
|
73
|
-
const NODE_VERSION = matching.node;
|
|
74
|
-
|
|
75
|
-
const custom_node_path = path.resolve(`node-${semver.major(NODE_VERSION)}`);
|
|
76
|
-
|
|
77
|
-
if (!jetpack.exists(custom_node_path)) {
|
|
78
|
-
await jetpack.dirAsync(custom_node_path);
|
|
79
|
-
await utils.downloadAndInstallNode(NODE_VERSION, custom_node_path);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
} catch (err) {
|
|
83
|
-
console.error(`ERROR: ${err}`);
|
|
84
|
-
// todo: check for enoent and skip?
|
|
85
|
-
// todo: if json error, throw a CC build error?
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,63 +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
|
-
export async function downloadAndInstallNode(node_version: string, destination: string) {
|
|
13
|
-
// eg. https://nodejs.org/dist/v18.14.2/node-v18.14.2-linux-x64.tar.xz
|
|
14
|
-
const PLATFORM = 'x';
|
|
15
|
-
const node_download_url = `https://nodejs.org/dist/v${node_version}/node-v${node_version}-linux-${PLATFORM}64.tar.gz`;
|
|
16
|
-
|
|
17
|
-
await downloadAndExtractTarball(node_download_url, destination);
|
|
18
|
-
// TODO: move binaries into local bin path?
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export async function downloadAndExtractTarball(url: string, dest: string) {
|
|
22
|
-
const tmpdir = os.tmpdir();
|
|
23
|
-
|
|
24
|
-
const filename = path.basename(URL.parse(url).pathname as string);
|
|
25
|
-
const base = path.basename(filename, '.tar.gz');
|
|
26
|
-
const download = path.join(tmpdir, filename);
|
|
27
|
-
|
|
28
|
-
const file = fs.createWriteStream(download);
|
|
29
|
-
const response = await fetch(url);
|
|
30
|
-
if (!response.ok) {
|
|
31
|
-
const errorBody = await response.text();
|
|
32
|
-
throw new Error(`Failed to download: ${errorBody}`);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// FIXME: replace with webstreams?
|
|
36
|
-
response.body.pipe(file);
|
|
37
|
-
|
|
38
|
-
file.on('finish', async () => {
|
|
39
|
-
console.log('Extracting...', download);
|
|
40
|
-
|
|
41
|
-
const comp = fs.createReadStream(download);
|
|
42
|
-
|
|
43
|
-
tar.extract({
|
|
44
|
-
cwd: tmpdir,
|
|
45
|
-
file: comp.path as string,
|
|
46
|
-
sync: true
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const uncomp = path.join(tmpdir, base);
|
|
50
|
-
|
|
51
|
-
const dist = path.resolve(dest);
|
|
52
|
-
// FIXME: dangerous. Add protection or replace.
|
|
53
|
-
// if (fs.existsSync(dist)) {
|
|
54
|
-
// fs.rmSync(dist, { recursive: true });
|
|
55
|
-
// }
|
|
56
|
-
if (fs.existsSync(uncomp)) {
|
|
57
|
-
console.log(`Moving extracted files from ${uncomp} to ${dist}`);
|
|
58
|
-
fs.renameSync(uncomp, dist);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
fs.unlinkSync(file.path);
|
|
62
|
-
});
|
|
63
|
-
}
|