@abtnode/core 1.6.15 → 1.6.19
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/lib/api/node.js +1 -1
- package/lib/blocklet/hooks.js +16 -63
- package/lib/blocklet/manager/disk.js +429 -151
- package/lib/blocklet/migration.js +16 -52
- package/lib/event.js +1 -1
- package/lib/index.js +3 -1
- package/lib/migrations/1.6.17-blocklet-children.js +48 -0
- package/lib/router/helper.js +18 -12
- package/lib/router/manager.js +45 -41
- package/lib/states/blocklet-extras.js +39 -3
- package/lib/states/blocklet.js +89 -20
- package/lib/states/node.js +17 -2
- package/lib/util/blocklet.js +288 -67
- package/lib/util/default-node-config.js +1 -1
- package/lib/util/get-domain-for-blocklet.js +2 -2
- package/lib/util/upgrade.js +8 -4
- package/lib/validators/node.js +11 -12
- package/package.json +23 -23
package/lib/api/node.js
CHANGED
|
@@ -93,7 +93,7 @@ class NodeAPI {
|
|
|
93
93
|
async updateNodeInfo(entity = {}, context) {
|
|
94
94
|
await validateNodeInfo(entity, context);
|
|
95
95
|
|
|
96
|
-
if (entity.autoUpgrade) {
|
|
96
|
+
if (entity.autoUpgrade && process.env.NODE_ENV !== 'development') {
|
|
97
97
|
try {
|
|
98
98
|
canPackageReadWrite(process.env.ABT_NODE_BINARY_NAME, process.env.ABT_NODE_PACKAGE_NAME);
|
|
99
99
|
} catch (err) {
|
package/lib/blocklet/hooks.js
CHANGED
|
@@ -1,68 +1,23 @@
|
|
|
1
|
-
const childProcess = require('child_process');
|
|
2
1
|
const get = require('lodash/get');
|
|
3
2
|
const camelCase = require('lodash/camelCase');
|
|
3
|
+
const runScript = require('@abtnode/util/lib/run-script');
|
|
4
4
|
|
|
5
5
|
// eslint-disable-next-line global-require
|
|
6
6
|
const logger = require('@abtnode/logger')(`${require('../../package.json').name}:blocklet:hooks`);
|
|
7
7
|
|
|
8
8
|
const { getSafeEnv } = require('../util');
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
cwd: appDir,
|
|
14
|
-
env: safeEnv,
|
|
15
|
-
stdio: 'inherit',
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
if (progress) {
|
|
19
|
-
child.stdout.pipe(process.stdout);
|
|
20
|
-
child.stderr.pipe(process.stderr);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return new Promise((resolve, reject) => {
|
|
24
|
-
const errorMessages = [];
|
|
25
|
-
let hasUnhandledRejection = false;
|
|
26
|
-
|
|
27
|
-
child.stderr.on('data', (err) => {
|
|
28
|
-
// Check if has unhandledRejection in childProcess
|
|
29
|
-
// https://stackoverflow.com/questions/32784649/gracefully-handle-errors-in-child-processes-in-nodejs
|
|
30
|
-
if (err.includes('UnhandledPromiseRejectionWarning')) {
|
|
31
|
-
hasUnhandledRejection = true;
|
|
32
|
-
}
|
|
33
|
-
errorMessages.push(err);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
child.on('exit', (code) => {
|
|
37
|
-
if (errorMessages.length > 0) {
|
|
38
|
-
if (code !== 0 || hasUnhandledRejection) {
|
|
39
|
-
return reject(new Error(errorMessages.join('\r\n')));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (!progress) {
|
|
43
|
-
errorMessages.forEach((message) => process.stderr.write(message));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return resolve();
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @param {*} args.did root blocklet did
|
|
54
|
-
*/
|
|
55
|
-
const runUserHook = async (name, args) => {
|
|
56
|
-
const { appDir, hooks, env, exitOnError = true, progress = false, notification, did } = args;
|
|
57
|
-
const hook = get(hooks, `[${name}]`) || get(hooks, `[${camelCase(name)}]`);
|
|
10
|
+
const runUserHook = async (appId, hookName, args) => {
|
|
11
|
+
const { appDir, hooks, env, exitOnError = true, silent = false, notification, did } = args;
|
|
12
|
+
const hook = get(hooks, `[${hookName}]`) || get(hooks, `[${camelCase(hookName)}]`);
|
|
58
13
|
|
|
59
14
|
try {
|
|
60
15
|
if (!hook) {
|
|
61
16
|
return;
|
|
62
17
|
}
|
|
63
18
|
|
|
64
|
-
logger.info(`run hook:${
|
|
65
|
-
await
|
|
19
|
+
logger.info(`run hook:${hookName}:`, { hook });
|
|
20
|
+
await runScript(hook, [appId, hookName].join(':'), { cwd: appDir, env: getSafeEnv(env), silent });
|
|
66
21
|
} catch (error) {
|
|
67
22
|
logger.error(`run ${hook} error:`, { error });
|
|
68
23
|
|
|
@@ -77,33 +32,31 @@ const runUserHook = async (name, args) => {
|
|
|
77
32
|
}
|
|
78
33
|
|
|
79
34
|
if (exitOnError) {
|
|
80
|
-
throw new Error(`Run [${
|
|
35
|
+
throw new Error(`Run [${hookName}] failed: ${error.message}`);
|
|
81
36
|
}
|
|
82
37
|
}
|
|
83
38
|
};
|
|
84
39
|
|
|
85
|
-
const preDeploy = (...args) => runUserHook('pre-deploy', ...args);
|
|
86
|
-
const preInstall = (...args) => runUserHook('pre-install', ...args);
|
|
87
|
-
const postInstall = (...args) => runUserHook('post-install', ...args);
|
|
88
|
-
|
|
89
|
-
const preStart = async (blocklet,
|
|
40
|
+
const preDeploy = (appId, ...args) => runUserHook(appId, 'pre-deploy', ...args);
|
|
41
|
+
const preInstall = (appId, ...args) => runUserHook(appId, 'pre-install', ...args);
|
|
42
|
+
const postInstall = (appId, ...args) => runUserHook(appId, 'post-install', ...args);
|
|
43
|
+
const preConfig = (appId, ...args) => runUserHook(appId, 'pre-config', ...args);
|
|
44
|
+
const preStart = async (blocklet, options) => {
|
|
90
45
|
// check required environments
|
|
91
46
|
let environments = get(blocklet, 'meta.environments', []);
|
|
92
47
|
if (!Array.isArray(environments)) {
|
|
93
48
|
environments = [environments];
|
|
94
49
|
}
|
|
95
50
|
|
|
96
|
-
const tmp = environments.filter((e) => e.required &&
|
|
51
|
+
const tmp = environments.filter((e) => e.required && options.env[e.name] === undefined).map((e) => e.name);
|
|
97
52
|
if (tmp.length > 0) {
|
|
98
53
|
throw new Error(`Required environments is not set: ${tmp.join(',')}`);
|
|
99
54
|
}
|
|
100
55
|
|
|
101
|
-
return runUserHook('pre-start',
|
|
56
|
+
return runUserHook(blocklet.env.appId, 'pre-start', options);
|
|
102
57
|
};
|
|
103
58
|
|
|
104
|
-
const preUninstall = (...args) => runUserHook('pre-uninstall', ...args);
|
|
105
|
-
const preStop = (...args) => runUserHook('pre-stop', ...args);
|
|
106
|
-
|
|
107
|
-
const preConfig = (...args) => runUserHook('pre-config', ...args);
|
|
59
|
+
const preUninstall = (appId, ...args) => runUserHook(appId, 'pre-uninstall', ...args);
|
|
60
|
+
const preStop = (appId, ...args) => runUserHook(appId, 'pre-stop', ...args);
|
|
108
61
|
|
|
109
62
|
module.exports = { preDeploy, preInstall, postInstall, preStart, preUninstall, preStop, preConfig };
|