@next-core/build-next-bricks 1.4.2 → 1.5.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/bin/build-next-bricks.js +5 -0
- package/package.json +4 -3
- package/src/generateMetadata.js +92 -0
- package/template/.pkgbuild/PKGBUILD +3 -0
- package/template/deploy/install_postscript.sh +77 -0
- package/template/deploy/update_postscript.sh +4 -0
- package/template/deploy/update_prescript.sh +4 -0
package/bin/build-next-bricks.js
CHANGED
|
@@ -3,6 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import build from "../src/build.js";
|
|
5
5
|
import scanBricks from "../src/scanBricks.js";
|
|
6
|
+
import generateMetadata from "../src/generateMetadata.js";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @typedef {T | Array<T>} MaybeArray<T>
|
|
@@ -66,6 +67,10 @@ try {
|
|
|
66
67
|
});
|
|
67
68
|
});
|
|
68
69
|
|
|
70
|
+
if (configList.some((config) => !config.type || config.type === "bricks")) {
|
|
71
|
+
await generateMetadata(packageDir);
|
|
72
|
+
}
|
|
73
|
+
|
|
69
74
|
console.log(
|
|
70
75
|
`Build bricks done in ${((Date.now() - startTime) / 1000).toFixed(2)}s`
|
|
71
76
|
);
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-core/build-next-bricks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Build next bricks",
|
|
5
|
-
"homepage": "https://github.com/easyops-cn/next-core/tree/
|
|
5
|
+
"homepage": "https://github.com/easyops-cn/next-core/tree/v3/packages/build-next-bricks",
|
|
6
6
|
"license": "GPL-3.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"typings": "./index.d.ts",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"files": [
|
|
13
13
|
"bin",
|
|
14
14
|
"src",
|
|
15
|
+
"template",
|
|
15
16
|
"index.d.ts"
|
|
16
17
|
],
|
|
17
18
|
"exports": {
|
|
@@ -46,5 +47,5 @@
|
|
|
46
47
|
"typescript": "^5.0.3",
|
|
47
48
|
"webpack": "^5.78.0"
|
|
48
49
|
},
|
|
49
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "03c671149d81db0c34758f9c662e932791cf0c7b"
|
|
50
51
|
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { copyFile, readFile, writeFile } from "node:fs/promises";
|
|
6
|
+
|
|
7
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} packageDir
|
|
11
|
+
*/
|
|
12
|
+
export default async function generateMetadata(packageDir) {
|
|
13
|
+
const targetPkgBuildDir = path.join(packageDir, ".pkgbuild");
|
|
14
|
+
if (!existsSync(targetPkgBuildDir)) {
|
|
15
|
+
mkdirSync(targetPkgBuildDir);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const targetDeployDir = path.join(packageDir, "deploy");
|
|
19
|
+
if (!existsSync(targetDeployDir)) {
|
|
20
|
+
mkdirSync(targetDeployDir);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
await Promise.all([
|
|
24
|
+
copyFile(
|
|
25
|
+
path.join(__dirname, "../template/.pkgbuild/PKGBUILD"),
|
|
26
|
+
path.join(targetPkgBuildDir, "PKGBUILD")
|
|
27
|
+
),
|
|
28
|
+
[
|
|
29
|
+
"install_postscript.sh",
|
|
30
|
+
"update_postscript.sh",
|
|
31
|
+
"update_prescript.sh",
|
|
32
|
+
].map((filename) =>
|
|
33
|
+
copyFile(
|
|
34
|
+
path.join(__dirname, "../template/deploy", filename),
|
|
35
|
+
path.join(targetDeployDir, filename)
|
|
36
|
+
)
|
|
37
|
+
),
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
const pkgName = path.basename(packageDir);
|
|
41
|
+
/**
|
|
42
|
+
* @type {[string, string][]}
|
|
43
|
+
*/
|
|
44
|
+
const patterns = Object.entries({
|
|
45
|
+
"$install-path-dir$": "bricks",
|
|
46
|
+
"$scope-name$": "bricks",
|
|
47
|
+
"$package-name$": pkgName,
|
|
48
|
+
"$suffix-name$": "NB",
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
await Promise.all(
|
|
52
|
+
[
|
|
53
|
+
path.join(targetPkgBuildDir, "PKGBUILD"),
|
|
54
|
+
path.join(targetDeployDir, "install_postscript.sh"),
|
|
55
|
+
].map((filePath) => replacePatterns(filePath, patterns))
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const defaultConfPath = path.join(
|
|
59
|
+
packageDir,
|
|
60
|
+
"deploy-default/package.conf.yaml"
|
|
61
|
+
);
|
|
62
|
+
const targetConfPath = path.join(packageDir, "deploy/package.conf.yaml");
|
|
63
|
+
|
|
64
|
+
if (existsSync(defaultConfPath)) {
|
|
65
|
+
// Todo: merge default conf with dependencies in package json.
|
|
66
|
+
await copyFile(defaultConfPath, targetConfPath);
|
|
67
|
+
} else {
|
|
68
|
+
await writeFile(
|
|
69
|
+
targetConfPath,
|
|
70
|
+
`install_path: /usr/local/easyops/bricks/${pkgName}-NB
|
|
71
|
+
user: "easyops:easyops"
|
|
72
|
+
dependencies:
|
|
73
|
+
- name: brick_next
|
|
74
|
+
version: ^2.86.3 || ^3.0.0
|
|
75
|
+
local_deploy: true
|
|
76
|
+
`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @param {string} filePath
|
|
83
|
+
* @param {[string, string][]} replacements
|
|
84
|
+
*/
|
|
85
|
+
async function replacePatterns(filePath, replacements) {
|
|
86
|
+
const content = await readFile(filePath, "utf-8");
|
|
87
|
+
const newContent = replacements.reduce(
|
|
88
|
+
(str, [s, r]) => str.replace(s, r),
|
|
89
|
+
content
|
|
90
|
+
);
|
|
91
|
+
await writeFile(filePath, newContent);
|
|
92
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# easyops 安装根目录
|
|
4
|
+
install_base="/usr/local/easyops"
|
|
5
|
+
|
|
6
|
+
install_path_dir='$install-path-dir$'
|
|
7
|
+
scope_name='$scope-name$'
|
|
8
|
+
plugin_name='$package-name$'
|
|
9
|
+
suffix='$suffix-name$'
|
|
10
|
+
|
|
11
|
+
install_path="${install_base}/${install_path_dir}/${plugin_name}-${suffix}"
|
|
12
|
+
|
|
13
|
+
function report_micro_app() {
|
|
14
|
+
install_base=$1
|
|
15
|
+
org=$2
|
|
16
|
+
install_path=$3
|
|
17
|
+
${install_base}/python/bin/python ${install_base}/brick_next/packages/brick-container/tools/report_installed_micro_app.py ${org} ${install_path}
|
|
18
|
+
if [[ $? -ne 0 ]]; then
|
|
19
|
+
echo "report installed micro app error"
|
|
20
|
+
exit 1
|
|
21
|
+
fi
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function report_package() {
|
|
25
|
+
install_base=$1
|
|
26
|
+
install_path=$2
|
|
27
|
+
if [[ -f ${install_base}/brick_next/packages/brick-container/tools/report_installed_brick_next_package.py ]];then
|
|
28
|
+
${install_base}/python/bin/python ${install_base}/brick_next/packages/brick-container/tools/report_installed_brick_next_package.py ${org} ${install_path}
|
|
29
|
+
if [[ $? -ne 0 ]]; then
|
|
30
|
+
echo "report installed micro app error"
|
|
31
|
+
exit 1
|
|
32
|
+
fi
|
|
33
|
+
fi
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
# 优先取环境变量里面的org
|
|
37
|
+
if [[ ${org}X == X ]]; then
|
|
38
|
+
org=$(/usr/local/easyops/deploy_init/tools/get_env.py common org)
|
|
39
|
+
[[ $? -ne 0 ]] && echo "get org error, exit" && exit 1
|
|
40
|
+
fi
|
|
41
|
+
|
|
42
|
+
# 是否以克隆模式部署(小产品支持多org部署),如果是的话,不用删除上一个版本的组件目录
|
|
43
|
+
if [[ ${cloned_install_path}X != X ]]; then
|
|
44
|
+
# 上报当前安装小产品
|
|
45
|
+
if [[ ${suffix} == "NA" ]]; then
|
|
46
|
+
report_micro_app ${install_base} ${org} ${cloned_install_path}
|
|
47
|
+
fi
|
|
48
|
+
# 上报当前安装小产品
|
|
49
|
+
if [[ ${suffix} == "NB" || ${suffix} == "NT" ]]; then
|
|
50
|
+
report_package ${install_base} ${cloned_install_path}
|
|
51
|
+
fi
|
|
52
|
+
else
|
|
53
|
+
# 构件目录
|
|
54
|
+
plugins_dir="${install_base}/brick_next/${scope_name}"
|
|
55
|
+
|
|
56
|
+
# 删除上一个版本
|
|
57
|
+
rm -rf "${plugins_dir:?}/${plugin_name}"
|
|
58
|
+
|
|
59
|
+
# 确保存在插件目录
|
|
60
|
+
mkdir -p "${plugins_dir}"
|
|
61
|
+
# 这边转换插件的名字,不用 -NB 后缀
|
|
62
|
+
ln -snf "${install_path}" "${plugins_dir}/${plugin_name}"
|
|
63
|
+
|
|
64
|
+
# 上报当前安装小产品
|
|
65
|
+
if [[ ${suffix} == "NA" ]]; then
|
|
66
|
+
report_micro_app ${install_base} ${org} ${install_path}
|
|
67
|
+
fi
|
|
68
|
+
|
|
69
|
+
# 上报当前安装小产品
|
|
70
|
+
if [[ ${suffix} == "NB" || ${suffix} == "NT" ]]; then
|
|
71
|
+
report_package ${install_base} ${install_path}
|
|
72
|
+
fi
|
|
73
|
+
|
|
74
|
+
fi
|
|
75
|
+
|
|
76
|
+
exit 0
|
|
77
|
+
|