create-widget 0.0.3 → 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 +6 -7
- package/lib/index.js +0 -166
package/package.json
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
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
|
-
"type": "module",
|
|
16
15
|
"publishConfig": {
|
|
17
16
|
"access": "public"
|
|
18
17
|
},
|
|
@@ -20,7 +19,7 @@
|
|
|
20
19
|
"node": "^12.0.0 || >= 14.0.0"
|
|
21
20
|
},
|
|
22
21
|
"dependencies": {
|
|
23
|
-
"chalk": "^
|
|
22
|
+
"chalk": "^4.1.2",
|
|
24
23
|
"consola": "^2.15.3",
|
|
25
24
|
"ejs": "^3.1.8",
|
|
26
25
|
"fs-extra": "^11.2.0",
|
|
@@ -43,8 +42,8 @@
|
|
|
43
42
|
"vitest": "^0.34.6"
|
|
44
43
|
},
|
|
45
44
|
"scripts": {
|
|
46
|
-
"build": "
|
|
47
|
-
"watch": "tsup-node src/index.ts --format
|
|
45
|
+
"build": "zx ./scripts/build.mjs",
|
|
46
|
+
"watch": "tsup-node src/index.ts --format cjs --watch",
|
|
48
47
|
"build:run": "npm run build && npm run create-widget",
|
|
49
48
|
"create-widget": "node ./lib/index.js",
|
|
50
49
|
"pnpm:publish": "npm run build && pnpm publish --no-git-checks"
|
package/lib/index.js
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import fs3 from "fs";
|
|
3
|
-
import * as process from "process";
|
|
4
|
-
import gradient from "gradient-string";
|
|
5
|
-
import prompts from "prompts";
|
|
6
|
-
import minimist from "minimist";
|
|
7
|
-
import chalk from "chalk";
|
|
8
|
-
import path2 from "path";
|
|
9
|
-
|
|
10
|
-
// src/utils/directoryTraverse.ts
|
|
11
|
-
import * as fs from "node:fs";
|
|
12
|
-
import * as path from "node:path";
|
|
13
|
-
function postOrderDirectoryTraverse(dir, dirCallback, fileCallback) {
|
|
14
|
-
for (const filename of fs.readdirSync(dir)) {
|
|
15
|
-
if (filename === ".git") {
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
const fullpath = path.resolve(dir, filename);
|
|
19
|
-
if (fs.lstatSync(fullpath).isDirectory()) {
|
|
20
|
-
postOrderDirectoryTraverse(fullpath, dirCallback, fileCallback);
|
|
21
|
-
dirCallback(fullpath);
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
fileCallback(fullpath);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// src/utils/getCommand.ts
|
|
29
|
-
function getCommand(packageManager, scriptName, args) {
|
|
30
|
-
if (scriptName === "install") {
|
|
31
|
-
return packageManager === "yarn" ? "yarn" : `${packageManager} install`;
|
|
32
|
-
}
|
|
33
|
-
if (args) {
|
|
34
|
-
return packageManager === "npm" ? `npm run ${scriptName} -- ${args}` : `${packageManager} ${scriptName} ${args}`;
|
|
35
|
-
} else {
|
|
36
|
-
return packageManager === "npm" ? `npm run ${scriptName}` : `${packageManager} ${scriptName}`;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// src/index.ts
|
|
41
|
-
import { fileURLToPath } from "url";
|
|
42
|
-
|
|
43
|
-
// src/utils/FileUtils.ts
|
|
44
|
-
import * as fs2 from "fs";
|
|
45
|
-
import { copy, ensureDir } from "fs-extra";
|
|
46
|
-
var FileUtils = class {
|
|
47
|
-
static async copyFolderRecursive(src, dest) {
|
|
48
|
-
try {
|
|
49
|
-
await ensureDir(dest);
|
|
50
|
-
const items = await fs2.promises.readdir(src);
|
|
51
|
-
for (const item of items) {
|
|
52
|
-
const srcPath = `${src}/${item}`;
|
|
53
|
-
const destPath = `${dest}/${item}`;
|
|
54
|
-
const stats = await fs2.promises.stat(srcPath);
|
|
55
|
-
if (stats.isDirectory()) {
|
|
56
|
-
await this.copyFolderRecursive(srcPath, destPath);
|
|
57
|
-
} else {
|
|
58
|
-
await copy(srcPath, destPath);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
} catch (error) {
|
|
62
|
-
console.error(`Error copying folder: ${error.message}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// src/index.ts
|
|
68
|
-
var __filename = fileURLToPath(import.meta.url);
|
|
69
|
-
var __dirname = path2.dirname(__filename);
|
|
70
|
-
function canSkipEmptying(dir) {
|
|
71
|
-
if (!fs3.existsSync(dir)) {
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
const files = fs3.readdirSync(dir);
|
|
75
|
-
if (files.length === 0) {
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
if (files.length === 1 && files[0] === ".git") {
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
function emptyDir(dir) {
|
|
84
|
-
if (!fs3.existsSync(dir)) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
postOrderDirectoryTraverse(
|
|
88
|
-
dir,
|
|
89
|
-
(dir2) => fs3.rmdirSync(dir2),
|
|
90
|
-
(file) => fs3.unlinkSync(file)
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
async function init() {
|
|
94
|
-
console.log();
|
|
95
|
-
let defaultBanner = "Widget.js - The Desktop Widget Framework";
|
|
96
|
-
const gradientBanner = gradient([
|
|
97
|
-
{ color: "#42d392", pos: 0 },
|
|
98
|
-
{ color: "#42d392", pos: 0.1 },
|
|
99
|
-
{ color: "#647eff", pos: 1 }
|
|
100
|
-
])(defaultBanner);
|
|
101
|
-
console.log(process.stdout.isTTY && process.stdout.getColorDepth() > 8 ? gradientBanner : defaultBanner);
|
|
102
|
-
console.log();
|
|
103
|
-
const argv2 = minimist(process.argv.slice(2), {
|
|
104
|
-
alias: {
|
|
105
|
-
typescript: ["ts"],
|
|
106
|
-
"with-tests": ["tests"],
|
|
107
|
-
router: ["vue-router"]
|
|
108
|
-
},
|
|
109
|
-
string: ["_"],
|
|
110
|
-
// all arguments are treated as booleans
|
|
111
|
-
boolean: true
|
|
112
|
-
});
|
|
113
|
-
let targetDir = argv2._[0];
|
|
114
|
-
const defaultProjectName = !targetDir ? "widget-project" : targetDir;
|
|
115
|
-
const forceOverwrite = argv2.force;
|
|
116
|
-
const cwd2 = process.cwd();
|
|
117
|
-
let result = {};
|
|
118
|
-
result = await prompts(
|
|
119
|
-
[
|
|
120
|
-
{
|
|
121
|
-
name: "projectName",
|
|
122
|
-
type: targetDir ? null : "text",
|
|
123
|
-
message: "Project name:",
|
|
124
|
-
initial: defaultProjectName,
|
|
125
|
-
onState: (state) => targetDir = String(state.value).trim() || defaultProjectName
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
name: "shouldOverwrite",
|
|
129
|
-
type: () => canSkipEmptying(targetDir) || forceOverwrite ? null : "confirm",
|
|
130
|
-
message: () => {
|
|
131
|
-
const dirForPrompt = targetDir === "." ? "Current directory" : `Target directory "${targetDir}"`;
|
|
132
|
-
return `${dirForPrompt} is not empty. Remove existing files and continue?`;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
],
|
|
136
|
-
{
|
|
137
|
-
onCancel: () => {
|
|
138
|
-
throw new Error(chalk.red("\u2716") + " Operation cancelled");
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
);
|
|
142
|
-
const { projectName, shouldOverwrite = argv2.force } = result;
|
|
143
|
-
const root = path2.join(cwd2, targetDir);
|
|
144
|
-
if (fs3.existsSync(root) && shouldOverwrite) {
|
|
145
|
-
emptyDir(root);
|
|
146
|
-
} else if (!fs3.existsSync(root)) {
|
|
147
|
-
fs3.mkdirSync(root);
|
|
148
|
-
}
|
|
149
|
-
console.log(`
|
|
150
|
-
Scaffolding project in ${root}...`);
|
|
151
|
-
const templateRoot = path2.join(__dirname, "../template");
|
|
152
|
-
await FileUtils.copyFolderRecursive(templateRoot, root);
|
|
153
|
-
const userAgent = process.env.npm_config_user_agent ?? "";
|
|
154
|
-
const packageManager = /pnpm/.test(userAgent) ? "pnpm" : /yarn/.test(userAgent) ? "yarn" : "npm";
|
|
155
|
-
console.log(`
|
|
156
|
-
Done. Now run:
|
|
157
|
-
`);
|
|
158
|
-
if (root !== cwd2) {
|
|
159
|
-
const cdProjectName = path2.relative(cwd2, root);
|
|
160
|
-
console.log(` ${chalk.bold(chalk.green(`cd ${cdProjectName.includes(" ") ? `"${cdProjectName}"` : cdProjectName}`))}`);
|
|
161
|
-
}
|
|
162
|
-
console.log(` ${chalk.bold(chalk.green(getCommand(packageManager, "install")))}`);
|
|
163
|
-
}
|
|
164
|
-
init().catch((e) => {
|
|
165
|
-
console.error(e);
|
|
166
|
-
});
|