@dotcom-tool-kit/node 1.0.2-beta.1
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/.toolkitrc.yml +5 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +6 -0
- package/lib/tasks/node.d.ts +8 -0
- package/lib/tasks/node.d.ts.map +1 -0
- package/lib/tasks/node.js +55 -0
- package/package.json +31 -0
package/.toolkitrc.yml
ADDED
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,cAAc,CAAA;AAE/B,eAAO,MAAM,KAAK,iBAAS,CAAA"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Task } from '@dotcom-tool-kit/types';
|
|
2
|
+
import { NodeOptions, NodeSchema } from '@dotcom-tool-kit/types/lib/schema/node';
|
|
3
|
+
export default class Node extends Task<typeof NodeSchema> {
|
|
4
|
+
static description: string;
|
|
5
|
+
static defaultOptions: NodeOptions;
|
|
6
|
+
run(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/tasks/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAA;AAShF,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,IAAI,CAAC,OAAO,UAAU,CAAC;IACvD,MAAM,CAAC,WAAW,SAAK;IAEvB,MAAM,CAAC,cAAc,EAAE,WAAW,CAEjC;IAEK,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CA4C3B"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const types_1 = require("@dotcom-tool-kit/types");
|
|
5
|
+
const error_1 = require("@dotcom-tool-kit/error");
|
|
6
|
+
const child_process_1 = require("child_process");
|
|
7
|
+
const vault_1 = require("@dotcom-tool-kit/vault");
|
|
8
|
+
const state_1 = require("@dotcom-tool-kit/state");
|
|
9
|
+
const logger_1 = require("@dotcom-tool-kit/logger");
|
|
10
|
+
const get_port_1 = (0, tslib_1.__importDefault)(require("get-port"));
|
|
11
|
+
const wait_port_1 = (0, tslib_1.__importDefault)(require("wait-port"));
|
|
12
|
+
class Node extends types_1.Task {
|
|
13
|
+
async run() {
|
|
14
|
+
const { entry } = this.options;
|
|
15
|
+
const vault = new vault_1.VaultEnvVars(this.logger, {
|
|
16
|
+
environment: 'development'
|
|
17
|
+
});
|
|
18
|
+
const vaultEnv = await vault.get();
|
|
19
|
+
const port = Number(process.env.PORT) ||
|
|
20
|
+
(await (0, get_port_1.default)({
|
|
21
|
+
port: [3001, 3002, 3003]
|
|
22
|
+
}));
|
|
23
|
+
if (!entry) {
|
|
24
|
+
const error = new error_1.ToolKitError(`the ${logger_1.styles.task('Node')} task requires an ${logger_1.styles.option('entry')} option`);
|
|
25
|
+
error.details = `this is the entrypoint for your app, e.g. ${logger_1.styles.filepath('server/app.js')}`;
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
this.logger.verbose('starting the child node process...');
|
|
29
|
+
const child = (0, child_process_1.fork)(entry, {
|
|
30
|
+
env: {
|
|
31
|
+
...vaultEnv,
|
|
32
|
+
PORT: port.toString(),
|
|
33
|
+
...process.env
|
|
34
|
+
},
|
|
35
|
+
silent: true
|
|
36
|
+
});
|
|
37
|
+
(0, logger_1.hookFork)(this.logger, entry, child);
|
|
38
|
+
const unhook = (0, logger_1.hookConsole)(this.logger, 'wait-port');
|
|
39
|
+
try {
|
|
40
|
+
await (0, wait_port_1.default)({
|
|
41
|
+
host: 'localhost',
|
|
42
|
+
port: port
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
unhook();
|
|
47
|
+
}
|
|
48
|
+
(0, state_1.writeState)('local', { port });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.default = Node;
|
|
52
|
+
Node.description = '';
|
|
53
|
+
Node.defaultOptions = {
|
|
54
|
+
entry: './server/app.js'
|
|
55
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dotcom-tool-kit/node",
|
|
3
|
+
"version": "1.0.2-beta.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "lib",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "FT.com Platforms Team <platforms-team.customer-products@ft.com>",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@dotcom-tool-kit/error": "^1.0.2-beta.1",
|
|
14
|
+
"@dotcom-tool-kit/state": "^1.0.2-beta.1",
|
|
15
|
+
"@dotcom-tool-kit/types": "^1.0.2-beta.1",
|
|
16
|
+
"@dotcom-tool-kit/vault": "^1.0.2-beta.1",
|
|
17
|
+
"get-port": "^5.1.1",
|
|
18
|
+
"wait-port": "^0.2.9"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/financial-times/dotcom-tool-kit.git",
|
|
23
|
+
"directory": "plugins/node"
|
|
24
|
+
},
|
|
25
|
+
"bugs": "https://github.com/financial-times/dotcom-tool-kit/issues",
|
|
26
|
+
"homepage": "https://github.com/financial-times/dotcom-tool-kit/tree/main/plugins/node",
|
|
27
|
+
"files": [
|
|
28
|
+
"/lib",
|
|
29
|
+
".toolkitrc.yml"
|
|
30
|
+
]
|
|
31
|
+
}
|