@widget-js/cli 1.1.5 → 1.1.7
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/index.js +155695 -28
- package/package.json +12 -10
- package/src/createWidget.ts +199 -194
- package/src/index.ts +1 -4
- package/template/Widget.ejs +1 -4
- package/template/WidgetConfig.ejs +13 -25
- package/template/WidgetDefine.ejs +26 -27
- package/template/WidgetRoutes.ejs +3 -3
- package/template/WidgetView.ejs +3 -10
- package/widget.ts +24 -0
- package/lib/build-BTARJMCZ.js +0 -31
- package/lib/chunk-3GPAHQ6O.js +0 -18
- package/lib/chunk-NJPDF23X.js +0 -34
- package/lib/createWidget-LWD7JPGR.js +0 -193
- package/lib/dependencies-J3BZI237.js +0 -87
- package/lib/index.cjs +0 -689
- package/lib/index.d.ts +0 -2
- package/lib/release-W3SP4YSR.js +0 -212
package/lib/release-W3SP4YSR.js
DELETED
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
promptChecker_default
|
|
3
|
-
} from "./chunk-3GPAHQ6O.js";
|
|
4
|
-
import {
|
|
5
|
-
getPackageVersion
|
|
6
|
-
} from "./chunk-NJPDF23X.js";
|
|
7
|
-
|
|
8
|
-
// src/release/release.ts
|
|
9
|
-
import fs4 from "fs";
|
|
10
|
-
import path2 from "path";
|
|
11
|
-
|
|
12
|
-
// src/release/update-zip.ts
|
|
13
|
-
import fs from "fs";
|
|
14
|
-
import archiver from "archiver";
|
|
15
|
-
function zipDirectory(sourceDir, outPath, ignoreDir) {
|
|
16
|
-
const archive = archiver("zip", { zlib: { level: 9 } });
|
|
17
|
-
const stream = fs.createWriteStream(outPath);
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
archive.glob("**/*", { cwd: sourceDir, ignore: ["node_modules/**"] }).on("error", (err) => reject(err)).pipe(stream);
|
|
20
|
-
stream.on("close", () => resolve());
|
|
21
|
-
archive.finalize();
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
var update_zip_default = zipDirectory;
|
|
25
|
-
|
|
26
|
-
// src/release/oss.ts
|
|
27
|
-
import OSS from "ali-oss";
|
|
28
|
-
import fs2 from "fs";
|
|
29
|
-
import chalk from "chalk";
|
|
30
|
-
var packageData = JSON.parse(fs2.readFileSync("./package.json").toString());
|
|
31
|
-
var AccessKeyID = packageData.oss?.id ?? "default";
|
|
32
|
-
var AccessKeySecret = packageData.oss?.secret ?? "default";
|
|
33
|
-
var headers = {
|
|
34
|
-
// 指定Object的存储类型。
|
|
35
|
-
"x-oss-storage-class": "Standard",
|
|
36
|
-
// 指定Object的访问权限。
|
|
37
|
-
"x-oss-object-acl": "public-read",
|
|
38
|
-
"x-oss-forbid-overwrite": "false",
|
|
39
|
-
"Cache-Control": "no-cache"
|
|
40
|
-
};
|
|
41
|
-
var clinet = new OSS({
|
|
42
|
-
// yourRegion填写Bucket所在地域。以华东1(杭州)为例,Region填写为oss-cn-hangzhou。
|
|
43
|
-
region: "oss-cn-hangzhou",
|
|
44
|
-
// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
|
|
45
|
-
accessKeyId: AccessKeyID,
|
|
46
|
-
accessKeySecret: AccessKeySecret,
|
|
47
|
-
bucket: "widget-fun"
|
|
48
|
-
});
|
|
49
|
-
async function put(ossPath, file) {
|
|
50
|
-
try {
|
|
51
|
-
const result = await clinet.put(ossPath, file, { headers });
|
|
52
|
-
console.log(chalk.green(`\u4E0A\u4F20\u6210\u529F\uFF1A${file}->${ossPath}`));
|
|
53
|
-
} catch (e) {
|
|
54
|
-
console.log(e);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
async function copy(dist, src) {
|
|
58
|
-
try {
|
|
59
|
-
const result = await clinet.copy(dist, src, { headers });
|
|
60
|
-
console.log(chalk.green(`\u590D\u5236\u6210\u529F\uFF1A${src}->${dist}`));
|
|
61
|
-
} catch (e) {
|
|
62
|
-
console.error(e);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/release/release.ts
|
|
67
|
-
import chalk2 from "chalk";
|
|
68
|
-
|
|
69
|
-
// src/release/ftp.ts
|
|
70
|
-
import path from "path";
|
|
71
|
-
import fs3 from "fs";
|
|
72
|
-
import SSHConfig from "@widget-js/ssh-config";
|
|
73
|
-
import os from "os";
|
|
74
|
-
import Client from "ssh2-sftp-client";
|
|
75
|
-
import consola from "consola";
|
|
76
|
-
import inquirer from "inquirer";
|
|
77
|
-
import ora from "ora";
|
|
78
|
-
import * as process from "process";
|
|
79
|
-
async function checkParentDir(ftpClient, file, onMkdir) {
|
|
80
|
-
let dir = path.dirname(file);
|
|
81
|
-
const dirExists = await ftpClient.exists(dir);
|
|
82
|
-
if (!dirExists) {
|
|
83
|
-
onMkdir(dir);
|
|
84
|
-
await ftpClient.mkdir(dir, true);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
async function runSSH(sshConfig, releaseConfig) {
|
|
88
|
-
consola.info("run ssh:", sshConfig);
|
|
89
|
-
const answer = await inquirer.prompt([{ type: "password", name: "password", mask: "*", message: "Enter key pair password" }]);
|
|
90
|
-
let ftpClient = new Client();
|
|
91
|
-
const port = sshConfig["Port"];
|
|
92
|
-
const key = fs3.readFileSync(path.resolve(os.homedir(), ".ssh/id_rsa"));
|
|
93
|
-
const spinner = ora("Connecting");
|
|
94
|
-
try {
|
|
95
|
-
spinner.start();
|
|
96
|
-
await ftpClient.connect({
|
|
97
|
-
host: sshConfig["HostName"],
|
|
98
|
-
port: port ? parseInt(port) : 22,
|
|
99
|
-
username: sshConfig["User"],
|
|
100
|
-
passphrase: answer.password,
|
|
101
|
-
privateKey: key
|
|
102
|
-
});
|
|
103
|
-
releaseConfig.fileMap.sort((it1, it2) => (it1.order ?? 0) - (it2.order ?? 0));
|
|
104
|
-
for (let item of releaseConfig.fileMap) {
|
|
105
|
-
if (typeof item.src == "string") {
|
|
106
|
-
if (item.remoteCopy) {
|
|
107
|
-
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
108
|
-
spinner.warn(`Create Dir: ${dir}`);
|
|
109
|
-
});
|
|
110
|
-
let destExists = await ftpClient.exists(item.dest);
|
|
111
|
-
if (destExists) {
|
|
112
|
-
spinner.warn(`Delete exists file:${item.dest}`);
|
|
113
|
-
await ftpClient.delete(item.dest);
|
|
114
|
-
}
|
|
115
|
-
spinner.info(`Copying File: ${item.src} -> ${item.dest}`);
|
|
116
|
-
await ftpClient.rcopy(item.src, item.dest);
|
|
117
|
-
} else {
|
|
118
|
-
const localFile = path.resolve(process.cwd(), item.src);
|
|
119
|
-
if (!item.remoteCopy && !fs3.existsSync(localFile)) {
|
|
120
|
-
spinner.warn(`Skip not exists file:${localFile}`);
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
if (fs3.lstatSync(localFile).isDirectory()) {
|
|
124
|
-
spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
|
|
125
|
-
await ftpClient.uploadDir(localFile, item.dest);
|
|
126
|
-
} else {
|
|
127
|
-
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
128
|
-
spinner.warn(`Create Dir: ${dir}`);
|
|
129
|
-
});
|
|
130
|
-
spinner.info(`Uploading File: ${localFile} -> ${item.dest}`);
|
|
131
|
-
await ftpClient.put(localFile, item.dest);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
} else {
|
|
135
|
-
await ftpClient.put(Buffer.from(JSON.stringify(item.src), "utf-8"), item.dest);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
spinner.succeed("Files uploaded!");
|
|
139
|
-
await ftpClient.end();
|
|
140
|
-
} catch (e) {
|
|
141
|
-
spinner.fail(`Connection error:${e}`);
|
|
142
|
-
await ftpClient.end();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
async function ftpUpload() {
|
|
146
|
-
const releaseJsonFilePath = path.join(process.cwd(), "release.json");
|
|
147
|
-
const packageVersion = getPackageVersion();
|
|
148
|
-
consola.info("Package Version:", packageVersion);
|
|
149
|
-
let releaseJson = fs3.readFileSync(releaseJsonFilePath).toString().replaceAll("${version}", packageVersion);
|
|
150
|
-
const releaseConfig = JSON.parse(releaseJson);
|
|
151
|
-
const sshConfigFile = path.resolve(os.homedir(), ".ssh/config");
|
|
152
|
-
consola.info("SSH Config File Path:", sshConfigFile);
|
|
153
|
-
const sshConfigs = SSHConfig.parse(fs3.readFileSync(sshConfigFile).toString());
|
|
154
|
-
for (let host of releaseConfig.ftpConfig.host) {
|
|
155
|
-
let sshConfig = sshConfigs.compute(host);
|
|
156
|
-
if (!sshConfig) {
|
|
157
|
-
consola.error(`SSH config ${releaseConfig.ftpConfig.host} not found`);
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
await runSSH(sshConfig, releaseConfig);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// src/release/release.ts
|
|
165
|
-
var release = async (options) => {
|
|
166
|
-
if (options.type == "ftp") {
|
|
167
|
-
await ftpUpload();
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
const packageJSON = JSON.parse(fs4.readFileSync("package.json", "utf-8"));
|
|
171
|
-
const changelogJSON = JSON.parse(fs4.readFileSync("changelog.json", "utf-8"));
|
|
172
|
-
const version = packageJSON["version"];
|
|
173
|
-
const changelog = changelogJSON[version];
|
|
174
|
-
let needUpdateElectron = await promptChecker_default({
|
|
175
|
-
type: "confirm",
|
|
176
|
-
name: "electron",
|
|
177
|
-
message: chalk2.blue("\u7528\u6237\u662F\u5426\u9700\u8981\u66F4\u65B0Electron?")
|
|
178
|
-
});
|
|
179
|
-
const versionInfo = {
|
|
180
|
-
version,
|
|
181
|
-
releaseNote: changelog,
|
|
182
|
-
updateElectron: needUpdateElectron,
|
|
183
|
-
updateNodeModule: false,
|
|
184
|
-
updateWindowsApi: false,
|
|
185
|
-
downloadLink: ""
|
|
186
|
-
};
|
|
187
|
-
let installerPath = path2.join(`./packaged/widgets-${version}-setup-win-x64.exe`);
|
|
188
|
-
if (!fs4.existsSync(installerPath)) {
|
|
189
|
-
installerPath = path2.join(`./packaged/electron-${version}-setup-win-x64.exe`);
|
|
190
|
-
}
|
|
191
|
-
if (!fs4.existsSync(installerPath)) {
|
|
192
|
-
installerPath = path2.join(`./packaged/app-${version}-setup-win-x64.exe`);
|
|
193
|
-
}
|
|
194
|
-
const updateZipPath = path2.join(`./packaged/update.zip`);
|
|
195
|
-
console.log(chalk2.blue("\u538B\u7F29\u66F4\u65B0\u6587\u4EF6\u4E2D"));
|
|
196
|
-
await update_zip_default("./release", updateZipPath);
|
|
197
|
-
console.log(chalk2.blue("\u4E0A\u4F20installer.exe\u5230OSS"));
|
|
198
|
-
await put("version/installer.exe", installerPath);
|
|
199
|
-
console.log(chalk2.blue("\u4E0A\u4F20update.zip\u5230OSS"));
|
|
200
|
-
await put("version/update.zip", updateZipPath);
|
|
201
|
-
console.log(chalk2.blue("\u66F4\u65B0\u7248\u672C\u4FE1\u606F"));
|
|
202
|
-
versionInfo.downloadLink = "https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip";
|
|
203
|
-
const versionJSON = JSON.stringify(versionInfo, null, 2);
|
|
204
|
-
await put("version/version.json", Buffer.from(versionJSON));
|
|
205
|
-
copy(`version/history/${version}.exe`, "version/installer.exe");
|
|
206
|
-
copy(`version/history/update-${version}.zip`, "version/update.zip");
|
|
207
|
-
console.log(chalk2.yellow(versionJSON));
|
|
208
|
-
};
|
|
209
|
-
var release_default = release;
|
|
210
|
-
export {
|
|
211
|
-
release_default as default
|
|
212
|
-
};
|