yds-tool 0.0.9 → 0.0.10

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/fe-build.js ADDED
@@ -0,0 +1,82 @@
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+
4
+
5
+
6
+ // 获取domainkey
7
+ const pkJsonPath = path.resolve(__dirname, './package.json')
8
+ const pkJsonStr = fs.readFileSync(pkJsonPath).toString()
9
+ const pkJson = JSON.parse(pkJsonStr)
10
+ const domainKey = pkJson.domainKey
11
+ // static目录,获取verison信息
12
+ const staticPath = path.resolve(__dirname, `./static`)
13
+ const versionPath = staticPath + `/public/${domainKey}/version.json`
14
+ let versionStr = fs.readFileSync(versionPath).toString()
15
+ const versionObj = JSON.parse(versionStr)
16
+ const version = versionObj.version
17
+ // 创建打包目录
18
+ const buildproductPath = path.resolve(__dirname, './yonyoucloud-buildproduct')
19
+ function deleteDir(url){
20
+ var files = [];
21
+
22
+ if( fs.existsSync(url) ) { //判断给定的路径是否存在
23
+
24
+ files = fs.readdirSync(url); //返回文件和子目录的数组
25
+ files.forEach(function(file,index){
26
+ var curPath = path.join(url,file);
27
+
28
+ if(fs.statSync(curPath).isDirectory()) { //同步读取文件夹文件,如果是文件夹,则函数回调
29
+ deleteDir(curPath);
30
+ } else {
31
+ fs.unlinkSync(curPath); //是指定文件,则删除
32
+ }
33
+
34
+ });
35
+
36
+ fs.rmdirSync(url); //清除文件夹
37
+ }else{
38
+ console.log("给定的路径不存在!");
39
+ }
40
+
41
+ }
42
+
43
+ deleteDir(buildproductPath)
44
+ fs.mkdirSync(buildproductPath)
45
+ fs.mkdirSync(buildproductPath + '/' + domainKey)
46
+ fs.mkdirSync(buildproductPath + '/' + domainKey + '/version')
47
+ fs.mkdirSync(buildproductPath + '/' + domainKey + '/' + version)
48
+ fs.mkdirSync(buildproductPath + '/' + domainKey + '/' + version + '/config')
49
+
50
+
51
+
52
+ function copyFolderSync(source, target) {
53
+ // 如果目标文件夹不存在,则创建
54
+ if (!fs.existsSync(target)) {
55
+ fs.mkdirSync(target)
56
+ }
57
+
58
+ // 获取源文件夹下的所有文件和子文件夹
59
+ const files = fs.readdirSync(source)
60
+
61
+ // 遍历文件和子文件夹,并递归拷贝
62
+ for (const file of files) {
63
+ const sourcePath = path.join(source, file)
64
+ const targetPath = path.join(target, file)
65
+
66
+ if (fs.lstatSync(sourcePath).isDirectory()) {
67
+ copyFolderSync(sourcePath, targetPath)
68
+ } else {
69
+ fs.copyFileSync(sourcePath, targetPath)
70
+ }
71
+ }
72
+ return true
73
+
74
+ }
75
+
76
+ copyFolderSync(staticPath + `/public/${domainKey}`, buildproductPath + '/' + domainKey + '/' + version)
77
+ //copyFolderSync(path.resolve(__dirname, './conf-build'), buildproductPath + '/' + domainKey + '/' + version + '/config')
78
+ //copyFolderSync(path.resolve(__dirname, './conf-build'), buildproductPath + '/' + domainKey + '/' + version)
79
+
80
+
81
+ fs.copyFileSync(path.resolve(__dirname, './module.xml'), buildproductPath + '/' + domainKey + '/module.xml')
82
+ fs.copyFileSync(staticPath + `/public/${domainKey}/version.json`, buildproductPath + '/' + domainKey + '/version/private_version.json')
@@ -0,0 +1,60 @@
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+ const child_process = require('child_process')
4
+
5
+ const isAdmin = () => {
6
+ try {
7
+ // 尝试执行一个只有管理员才能运行的命令
8
+ // 使用 >nul 2>&1 来抑制输出
9
+ child_process.execSync('net session >nul 2>&1');
10
+ return true; // 成功执行
11
+ } catch (err) {
12
+ return false; // 执行失败,权限不足
13
+ }
14
+ }
15
+
16
+ // 获取domainkey
17
+ const pkJsonPath = path.resolve(__dirname, './package.json')
18
+ const pkJsonStr = fs.readFileSync(pkJsonPath).toString()
19
+ const pkJson = JSON.parse(pkJsonStr)
20
+ const domainKey = pkJson.domainKey
21
+ // static目录,获取verison信息
22
+ const versionPath = path.resolve(__dirname, `./version.json`)
23
+ let versionStr = fs.readFileSync(versionPath).toString()
24
+ const versionObj = JSON.parse(versionStr)
25
+ const version = versionObj.version
26
+ // 创建打包目录
27
+ const buildProductName = 'yonyoucloud-buildproduct';
28
+ const buildProductPath = path.resolve(__dirname, buildProductName)
29
+
30
+
31
+ if (fs.existsSync(buildProductPath)) {
32
+ fs.rmdirSync(buildProductPath, { recursive: true})
33
+ }
34
+ let domainDir = `${buildProductPath}/${domainKey}`;
35
+ let outputDir = `${domainDir}/${version}`;
36
+ let versionDir = `${domainDir}/version`;
37
+ if(!fs.existsSync(versionDir)) {
38
+ fs.mkdirSync(versionDir, { recursive: true })
39
+ }
40
+ if(!fs.existsSync(outputDir)) {
41
+ fs.mkdirSync(outputDir, {recursive: true})
42
+ }
43
+
44
+ // 拷贝所有产物
45
+ let srcDir = path.resolve(__dirname);
46
+ for(let filename of fs.readdirSync(srcDir)) {
47
+ if (/(.git|__tests__|.npm)/.test(filename) || buildProductName === filename) {
48
+ continue;
49
+ }
50
+ if (filename === 'node_modules' && isAdmin()) {
51
+ // linkSync 硬链接:多个文件名对应同一个物理数据(inode),无法区分“原文件”和“链接”。
52
+ // symlinkSync 软链接:是一个独立的文件,内容是目标路径的字符串,类似 Windows 快捷方式。
53
+ fs.symlinkSync(path.resolve(__dirname, filename), `${outputDir}/${filename}`, 'dir')
54
+ continue;
55
+ }
56
+ fs.cpSync(path.resolve(__dirname, filename), `${outputDir}/${filename}`, { recursive: true })
57
+ }
58
+
59
+ fs.copyFileSync(path.resolve(__dirname, 'module.xml'), `${domainDir}/module.xml`)
60
+ fs.copyFileSync(versionPath, `${versionDir}/private_version.json`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yds-tool",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "isv本地制盘工具",
5
5
  "main": "./bin/index.js",
6
6
  "bin": {
@@ -11,7 +11,9 @@
11
11
  "src",
12
12
  "unzip.exe",
13
13
  "zip.exe",
14
- "wget.exe"
14
+ "wget.exe",
15
+ "fe-build.js",
16
+ "fecode-build.js"
15
17
  ],
16
18
  "keywords": [
17
19
  "yds"