@cloudbase/framework-plugin-low-code 1.0.3-alpha.0 → 1.0.3-alpha.3
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/package.json +6 -4
- package/scripts/build-plugin-tar.sh +31 -0
- package/scripts/generateTemplate.js +31 -0
- package/scripts/link-packages.js +11 -0
- package/scripts/link.js +91 -0
- package/scripts/postinstall.js +43 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/framework-plugin-low-code",
|
|
3
|
-
"version": "1.0.3-alpha.
|
|
3
|
+
"version": "1.0.3-alpha.3",
|
|
4
4
|
"description": "云开发 Tencent CloudBase Framework Low Code Plugin,将低码配置生成完整项目并一键部署云开发资源。",
|
|
5
5
|
"author": "yhsunshining@gmail.com",
|
|
6
6
|
"homepage": "https://github.com/TencentCloudBase/cloudbase-framework#readme",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
15
|
"lib",
|
|
16
|
-
"template"
|
|
16
|
+
"template",
|
|
17
|
+
"scripts"
|
|
17
18
|
],
|
|
18
19
|
"publishConfig": {
|
|
19
20
|
"access": "public"
|
|
@@ -29,7 +30,8 @@
|
|
|
29
30
|
"prebuild": "rm -rf ./lib && rm -rf ./tsconfig.tsbuildinfo && npm run template",
|
|
30
31
|
"build": "tsc",
|
|
31
32
|
"test": "jest",
|
|
32
|
-
"link": "node scripts/link-packages.js"
|
|
33
|
+
"link": "node scripts/link-packages.js",
|
|
34
|
+
"postinstall": "node scripts/postinstall.js"
|
|
33
35
|
},
|
|
34
36
|
"bugs": {
|
|
35
37
|
"url": "https://github.com/TencentCloudBase/cloudbase-framework/issues"
|
|
@@ -38,7 +40,7 @@
|
|
|
38
40
|
"@cloudbase/cals": "^0.3.35",
|
|
39
41
|
"@cloudbase/framework-core": "^1.8.16",
|
|
40
42
|
"@cloudbase/framework-plugin-auth": "^1.8.16",
|
|
41
|
-
"@cloudbase/framework-plugin-mp": "
|
|
43
|
+
"@cloudbase/framework-plugin-mp": "1.9.5-beta.1",
|
|
42
44
|
"@cloudbase/framework-plugin-website": "^1.8.17",
|
|
43
45
|
"@cloudbase/lowcode-builder": "^1.0.12",
|
|
44
46
|
"@formily/react-schema-renderer": "1.1.7",
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -x
|
|
3
|
+
|
|
4
|
+
NPM_VERSION=$(node -e "(function () { console.log(require('./package.json').version) })()")
|
|
5
|
+
NPM_NAME=$(node -e "(function () { console.log(require('./package.json').name) })()")
|
|
6
|
+
# 现网版本号
|
|
7
|
+
VERSION=0.6.17
|
|
8
|
+
# 产出文件名
|
|
9
|
+
NAME=plugin.tar.gz
|
|
10
|
+
# 产出目录,默认:脚本执行目录
|
|
11
|
+
DIST_PATH=`pwd`
|
|
12
|
+
|
|
13
|
+
cd $TMPDIR
|
|
14
|
+
# 清理历史目录
|
|
15
|
+
rm -rf $NPM_NAME/$NPM_VERSION
|
|
16
|
+
# 创建产出目录
|
|
17
|
+
mkdir -p $NPM_NAME/$NPM_VERSION
|
|
18
|
+
cd $NPM_NAME/$NPM_VERSION
|
|
19
|
+
pwd
|
|
20
|
+
# 安装包,@todo 目前保持老打包逻辑(安装方式),这块是否可以考虑不安装直接使用项目构建产出
|
|
21
|
+
npm i $NPM_NAME@$NPM_VERSION
|
|
22
|
+
cd node_modules/$NPM_NAME
|
|
23
|
+
pwd
|
|
24
|
+
# 安装生产依赖
|
|
25
|
+
yarn --production
|
|
26
|
+
# 更换版本号为现网版本号 0.6.17
|
|
27
|
+
npm version $VERSION
|
|
28
|
+
# 打包
|
|
29
|
+
tar -zcvf $NAME ./*
|
|
30
|
+
# 拷贝到产出目录
|
|
31
|
+
mv ./$NAME $DIST_PATH
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const glob = require('glob');
|
|
4
|
+
|
|
5
|
+
const chokidar = require('chokidar');
|
|
6
|
+
const TEMPLATE_PATH = path.join(__dirname, '../template/generator');
|
|
7
|
+
|
|
8
|
+
// One-liner for current directory
|
|
9
|
+
generateTemplate();
|
|
10
|
+
if (process.env.npm_config_watch) {
|
|
11
|
+
chokidar.watch(TEMPLATE_PATH).on('all', (event, path) => {
|
|
12
|
+
console.log(event, path);
|
|
13
|
+
generateTemplate();
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function generateTemplate() {
|
|
18
|
+
const files = glob.sync('**/*', { cwd: TEMPLATE_PATH, nodir: true });
|
|
19
|
+
const filesObj = files.reduce((obj, file) => {
|
|
20
|
+
obj[`/src/${file}`] = {
|
|
21
|
+
code: fs.readFileSync(path.join(TEMPLATE_PATH, file), {
|
|
22
|
+
encoding: 'utf8',
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
return obj;
|
|
26
|
+
}, {});
|
|
27
|
+
fs.writeFileSync(
|
|
28
|
+
path.join(__dirname, '../src/generator/template.ts'),
|
|
29
|
+
`export default ${JSON.stringify(filesObj, null, 2)}`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tencent is pleased to support the open source community by making CloudBaseFramework - 云原生一体化部署工具 available.
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
|
5
|
+
*
|
|
6
|
+
* Please refer to license text included with this package for license details.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const link = require('./link');
|
|
10
|
+
|
|
11
|
+
link();
|
package/scripts/link.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tencent is pleased to support the open source community by making CloudBaseFramework - 云原生一体化部署工具 available.
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
|
5
|
+
*
|
|
6
|
+
* Please refer to license text included with this package for license details.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const os = require('os');
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const del = require('del');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
const mkdirp = require('mkdirp');
|
|
14
|
+
const { execSync } = require('child_process');
|
|
15
|
+
const { createSymlink } = require('@lerna/create-symlink');
|
|
16
|
+
|
|
17
|
+
const globalNpmPath = execSync('npm root -g', {
|
|
18
|
+
encoding: 'utf-8',
|
|
19
|
+
}).trim();
|
|
20
|
+
// 如果不支持workspace 可以用下面写死
|
|
21
|
+
// const globalNpmPath = '/usr/local/lib/node_modules';
|
|
22
|
+
|
|
23
|
+
const pluginRegistry = path.join(os.homedir(), 'cloudbase-framework/registry');
|
|
24
|
+
|
|
25
|
+
module.exports = async function main() {
|
|
26
|
+
// await linkCore();
|
|
27
|
+
initRegistry();
|
|
28
|
+
await linkPlugins();
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
async function linkCore() {
|
|
32
|
+
await link(
|
|
33
|
+
path.join(process.cwd(), 'packages/framework-core'),
|
|
34
|
+
path.join(globalNpmPath, '@cloudbase/cli'),
|
|
35
|
+
'@cloudbase/framework-core'
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function initRegistry() {
|
|
40
|
+
if (!fs.existsSync(pluginRegistry)) {
|
|
41
|
+
mkdirp.sync(pluginRegistry, { recursive: true });
|
|
42
|
+
}
|
|
43
|
+
const packageJSON = path.join(pluginRegistry, 'package.json');
|
|
44
|
+
if (!fs.existsSync(packageJSON)) {
|
|
45
|
+
fs.writeFileSync(
|
|
46
|
+
packageJSON,
|
|
47
|
+
JSON.stringify({
|
|
48
|
+
name: 'cloudbase-framework-registry',
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function linkPlugins() {
|
|
55
|
+
const files = ['framework-plugin-low-code'];
|
|
56
|
+
|
|
57
|
+
const plugins = files.filter((file) => file.includes('plugin'));
|
|
58
|
+
// 插件列表
|
|
59
|
+
console.log(plugins);
|
|
60
|
+
|
|
61
|
+
for (const plugin of plugins) {
|
|
62
|
+
console.log('\n', 'Link Plugin', plugin, '\n');
|
|
63
|
+
// 创建软连接
|
|
64
|
+
await link(
|
|
65
|
+
path.join(process.cwd()),
|
|
66
|
+
pluginRegistry,
|
|
67
|
+
`@cloudbase/${plugin}`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 将 global tcb cli 工具中的 framework-core link 到 packages/framework-core
|
|
73
|
+
async function link(src, dest, packageName) {
|
|
74
|
+
const prevCwd = process.cwd();
|
|
75
|
+
const destPlugin = path.join(dest, 'node_modules', '@cloudbase');
|
|
76
|
+
// 确保目录存在
|
|
77
|
+
mkdirp.sync(destPlugin);
|
|
78
|
+
// 切换 cwd
|
|
79
|
+
process.chdir(destPlugin);
|
|
80
|
+
console.log('创建软连接:', process.cwd());
|
|
81
|
+
const pathName = packageName.replace('@cloudbase/', '');
|
|
82
|
+
// 删除已存在的文件
|
|
83
|
+
if (fs.existsSync(pathName)) {
|
|
84
|
+
del.sync([pathName]);
|
|
85
|
+
}
|
|
86
|
+
console.log('src', src);
|
|
87
|
+
console.log('pathName', pathName);
|
|
88
|
+
await createSymlink(src, pathName, 'junction');
|
|
89
|
+
// 切回源目录
|
|
90
|
+
process.chdir(prevCwd);
|
|
91
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import spawn from 'cross-spawn';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
export async function installDependencies(targetDir) {
|
|
6
|
+
if (!process.env.CLOUDBASE_CIID) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
let yarnExists = false;
|
|
11
|
+
try {
|
|
12
|
+
let { stdout } = spawn.sync('yarn', ['-v']);
|
|
13
|
+
let str = stdout.toString();
|
|
14
|
+
if (Number(str.split('.')?.[0]) <= 1) {
|
|
15
|
+
yarnExists = true;
|
|
16
|
+
}
|
|
17
|
+
} catch (e) {}
|
|
18
|
+
|
|
19
|
+
const npmOptions = ['--prefer-offline', '--no-audit', '--progress=false'];
|
|
20
|
+
|
|
21
|
+
let installProcess;
|
|
22
|
+
// 云端构建, 选用 npm
|
|
23
|
+
const installlProcessOptions = {
|
|
24
|
+
cwd: targetDir,
|
|
25
|
+
env: { ...process.env, NODE_ENV: '' },
|
|
26
|
+
stdio: 'inherit',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
if (yarnExists && process.env.CLOUDBASE_CIID) {
|
|
30
|
+
const addPackage = packageName ? ['add', packageName] : [];
|
|
31
|
+
|
|
32
|
+
installProcess = spawn.sync('yarn', [...addPackage, registry], installlProcessOptions);
|
|
33
|
+
} else {
|
|
34
|
+
installProcess = spawn.sync('npm', ['install', packageName, ...npmOptions], installlProcessOptions);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
await fs.remove(path.join(path.join(targetDir, 'package-lock.json')));
|
|
39
|
+
await fs.remove(path.join(path.join(targetDir, 'yarn.lock')));
|
|
40
|
+
} catch (e) {}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
installDependencies(path.join(__dirname, '../'));
|