create-widget 0.0.4 → 0.0.5
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/LICENSE +33 -0
- package/lib/index.cjs +7913 -0
- package/package.json +5 -5
- package/lib/index.js +0 -184
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-widget",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"author": "Neo Fu",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"private": false,
|
|
8
8
|
"bin": {
|
|
9
|
-
"create-widget": "lib/index.
|
|
9
|
+
"create-widget": "lib/index.cjs"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
|
-
"lib/index.
|
|
12
|
+
"lib/index.cjs",
|
|
13
13
|
"template"
|
|
14
14
|
],
|
|
15
15
|
"publishConfig": {
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"vitest": "^0.34.6"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
|
-
"build": "
|
|
46
|
-
"watch": "tsup-node src/index.ts --format
|
|
45
|
+
"build": "zx ./scripts/build.mjs",
|
|
46
|
+
"watch": "tsup-node src/index.ts --format cjs --watch",
|
|
47
47
|
"build:run": "npm run build && npm run create-widget",
|
|
48
48
|
"create-widget": "node ./lib/index.js",
|
|
49
49
|
"pnpm:publish": "npm run build && pnpm publish --no-git-checks"
|
package/lib/index.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __copyProps = (to, from, except, desc) => {
|
|
8
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
-
for (let key of __getOwnPropNames(from))
|
|
10
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
-
}
|
|
13
|
-
return to;
|
|
14
|
-
};
|
|
15
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
23
|
-
|
|
24
|
-
// src/index.ts
|
|
25
|
-
var import_fs = __toESM(require("fs"));
|
|
26
|
-
var process = __toESM(require("process"));
|
|
27
|
-
var import_gradient_string = __toESM(require("gradient-string"));
|
|
28
|
-
var import_prompts = __toESM(require("prompts"));
|
|
29
|
-
var import_minimist = __toESM(require("minimist"));
|
|
30
|
-
var import_chalk = __toESM(require("chalk"));
|
|
31
|
-
var import_path = __toESM(require("path"));
|
|
32
|
-
|
|
33
|
-
// src/utils/directoryTraverse.ts
|
|
34
|
-
var fs = __toESM(require("fs"));
|
|
35
|
-
var path = __toESM(require("path"));
|
|
36
|
-
function postOrderDirectoryTraverse(dir, dirCallback, fileCallback) {
|
|
37
|
-
for (const filename of fs.readdirSync(dir)) {
|
|
38
|
-
if (filename === ".git") {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
const fullpath = path.resolve(dir, filename);
|
|
42
|
-
if (fs.lstatSync(fullpath).isDirectory()) {
|
|
43
|
-
postOrderDirectoryTraverse(fullpath, dirCallback, fileCallback);
|
|
44
|
-
dirCallback(fullpath);
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
fileCallback(fullpath);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// src/utils/getCommand.ts
|
|
52
|
-
function getCommand(packageManager, scriptName, args) {
|
|
53
|
-
if (scriptName === "install") {
|
|
54
|
-
return packageManager === "yarn" ? "yarn" : `${packageManager} install`;
|
|
55
|
-
}
|
|
56
|
-
if (args) {
|
|
57
|
-
return packageManager === "npm" ? `npm run ${scriptName} -- ${args}` : `${packageManager} ${scriptName} ${args}`;
|
|
58
|
-
} else {
|
|
59
|
-
return packageManager === "npm" ? `npm run ${scriptName}` : `${packageManager} ${scriptName}`;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// src/utils/FileUtils.ts
|
|
64
|
-
var fs2 = __toESM(require("fs"));
|
|
65
|
-
var import_fs_extra = require("fs-extra");
|
|
66
|
-
var FileUtils = class {
|
|
67
|
-
static async copyFolderRecursive(src, dest) {
|
|
68
|
-
try {
|
|
69
|
-
await (0, import_fs_extra.ensureDir)(dest);
|
|
70
|
-
const items = await fs2.promises.readdir(src);
|
|
71
|
-
for (const item of items) {
|
|
72
|
-
const srcPath = `${src}/${item}`;
|
|
73
|
-
const destPath = `${dest}/${item}`;
|
|
74
|
-
const stats = await fs2.promises.stat(srcPath);
|
|
75
|
-
if (stats.isDirectory()) {
|
|
76
|
-
await this.copyFolderRecursive(srcPath, destPath);
|
|
77
|
-
} else {
|
|
78
|
-
await (0, import_fs_extra.copy)(srcPath, destPath);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
} catch (error) {
|
|
82
|
-
console.error(`Error copying folder: ${error.message}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
// src/index.ts
|
|
88
|
-
function canSkipEmptying(dir) {
|
|
89
|
-
if (!import_fs.default.existsSync(dir)) {
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
const files = import_fs.default.readdirSync(dir);
|
|
93
|
-
if (files.length === 0) {
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
if (files.length === 1 && files[0] === ".git") {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
function emptyDir(dir) {
|
|
102
|
-
if (!import_fs.default.existsSync(dir)) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
postOrderDirectoryTraverse(
|
|
106
|
-
dir,
|
|
107
|
-
(dir2) => import_fs.default.rmdirSync(dir2),
|
|
108
|
-
(file) => import_fs.default.unlinkSync(file)
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
async function init() {
|
|
112
|
-
console.log();
|
|
113
|
-
let defaultBanner = "Widget.js - The Desktop Widget Framework";
|
|
114
|
-
const gradientBanner = (0, import_gradient_string.default)([
|
|
115
|
-
{ color: "#42d392", pos: 0 },
|
|
116
|
-
{ color: "#42d392", pos: 0.1 },
|
|
117
|
-
{ color: "#647eff", pos: 1 }
|
|
118
|
-
])(defaultBanner);
|
|
119
|
-
console.log(process.stdout.isTTY && process.stdout.getColorDepth() > 8 ? gradientBanner : defaultBanner);
|
|
120
|
-
console.log();
|
|
121
|
-
const argv2 = (0, import_minimist.default)(process.argv.slice(2), {
|
|
122
|
-
alias: {
|
|
123
|
-
typescript: ["ts"],
|
|
124
|
-
"with-tests": ["tests"],
|
|
125
|
-
router: ["vue-router"]
|
|
126
|
-
},
|
|
127
|
-
string: ["_"],
|
|
128
|
-
// all arguments are treated as booleans
|
|
129
|
-
boolean: true
|
|
130
|
-
});
|
|
131
|
-
let targetDir = argv2._[0];
|
|
132
|
-
const defaultProjectName = !targetDir ? "widget-project" : targetDir;
|
|
133
|
-
const forceOverwrite = argv2.force;
|
|
134
|
-
const cwd2 = process.cwd();
|
|
135
|
-
let result = {};
|
|
136
|
-
result = await (0, import_prompts.default)(
|
|
137
|
-
[
|
|
138
|
-
{
|
|
139
|
-
name: "projectName",
|
|
140
|
-
type: targetDir ? null : "text",
|
|
141
|
-
message: "Project name:",
|
|
142
|
-
initial: defaultProjectName,
|
|
143
|
-
onState: (state) => targetDir = String(state.value).trim() || defaultProjectName
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
name: "shouldOverwrite",
|
|
147
|
-
type: () => canSkipEmptying(targetDir) || forceOverwrite ? null : "confirm",
|
|
148
|
-
message: () => {
|
|
149
|
-
const dirForPrompt = targetDir === "." ? "Current directory" : `Target directory "${targetDir}"`;
|
|
150
|
-
return `${dirForPrompt} is not empty. Remove existing files and continue?`;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
],
|
|
154
|
-
{
|
|
155
|
-
onCancel: () => {
|
|
156
|
-
throw new Error(import_chalk.default.red("\u2716") + " Operation cancelled");
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
);
|
|
160
|
-
const { projectName, shouldOverwrite = argv2.force } = result;
|
|
161
|
-
const root = import_path.default.join(cwd2, targetDir);
|
|
162
|
-
if (import_fs.default.existsSync(root) && shouldOverwrite) {
|
|
163
|
-
emptyDir(root);
|
|
164
|
-
} else if (!import_fs.default.existsSync(root)) {
|
|
165
|
-
import_fs.default.mkdirSync(root);
|
|
166
|
-
}
|
|
167
|
-
console.log(`
|
|
168
|
-
Scaffolding project in ${root}...`);
|
|
169
|
-
const templateRoot = import_path.default.join(__dirname, "../template");
|
|
170
|
-
await FileUtils.copyFolderRecursive(templateRoot, root);
|
|
171
|
-
const userAgent = process.env.npm_config_user_agent ?? "";
|
|
172
|
-
const packageManager = /pnpm/.test(userAgent) ? "pnpm" : /yarn/.test(userAgent) ? "yarn" : "npm";
|
|
173
|
-
console.log(`
|
|
174
|
-
Done. Now run:
|
|
175
|
-
`);
|
|
176
|
-
if (root !== cwd2) {
|
|
177
|
-
const cdProjectName = import_path.default.relative(cwd2, root);
|
|
178
|
-
console.log(` ${import_chalk.default.bold(import_chalk.default.green(`cd ${cdProjectName.includes(" ") ? `"${cdProjectName}"` : cdProjectName}`))}`);
|
|
179
|
-
}
|
|
180
|
-
console.log(` ${import_chalk.default.bold(import_chalk.default.green(getCommand(packageManager, "install")))}`);
|
|
181
|
-
}
|
|
182
|
-
init().catch((e) => {
|
|
183
|
-
console.error(e);
|
|
184
|
-
});
|