create-widget 0.0.3 → 0.0.4

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.
Files changed (2) hide show
  1. package/lib/index.js +53 -35
  2. package/package.json +3 -4
package/lib/index.js CHANGED
@@ -1,15 +1,38 @@
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
+
1
24
  // 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";
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"));
9
32
 
10
33
  // src/utils/directoryTraverse.ts
11
- import * as fs from "node:fs";
12
- import * as path from "node:path";
34
+ var fs = __toESM(require("fs"));
35
+ var path = __toESM(require("path"));
13
36
  function postOrderDirectoryTraverse(dir, dirCallback, fileCallback) {
14
37
  for (const filename of fs.readdirSync(dir)) {
15
38
  if (filename === ".git") {
@@ -37,16 +60,13 @@ function getCommand(packageManager, scriptName, args) {
37
60
  }
38
61
  }
39
62
 
40
- // src/index.ts
41
- import { fileURLToPath } from "url";
42
-
43
63
  // src/utils/FileUtils.ts
44
- import * as fs2 from "fs";
45
- import { copy, ensureDir } from "fs-extra";
64
+ var fs2 = __toESM(require("fs"));
65
+ var import_fs_extra = require("fs-extra");
46
66
  var FileUtils = class {
47
67
  static async copyFolderRecursive(src, dest) {
48
68
  try {
49
- await ensureDir(dest);
69
+ await (0, import_fs_extra.ensureDir)(dest);
50
70
  const items = await fs2.promises.readdir(src);
51
71
  for (const item of items) {
52
72
  const srcPath = `${src}/${item}`;
@@ -55,7 +75,7 @@ var FileUtils = class {
55
75
  if (stats.isDirectory()) {
56
76
  await this.copyFolderRecursive(srcPath, destPath);
57
77
  } else {
58
- await copy(srcPath, destPath);
78
+ await (0, import_fs_extra.copy)(srcPath, destPath);
59
79
  }
60
80
  }
61
81
  } catch (error) {
@@ -65,13 +85,11 @@ var FileUtils = class {
65
85
  };
66
86
 
67
87
  // src/index.ts
68
- var __filename = fileURLToPath(import.meta.url);
69
- var __dirname = path2.dirname(__filename);
70
88
  function canSkipEmptying(dir) {
71
- if (!fs3.existsSync(dir)) {
89
+ if (!import_fs.default.existsSync(dir)) {
72
90
  return true;
73
91
  }
74
- const files = fs3.readdirSync(dir);
92
+ const files = import_fs.default.readdirSync(dir);
75
93
  if (files.length === 0) {
76
94
  return true;
77
95
  }
@@ -81,26 +99,26 @@ function canSkipEmptying(dir) {
81
99
  return false;
82
100
  }
83
101
  function emptyDir(dir) {
84
- if (!fs3.existsSync(dir)) {
102
+ if (!import_fs.default.existsSync(dir)) {
85
103
  return;
86
104
  }
87
105
  postOrderDirectoryTraverse(
88
106
  dir,
89
- (dir2) => fs3.rmdirSync(dir2),
90
- (file) => fs3.unlinkSync(file)
107
+ (dir2) => import_fs.default.rmdirSync(dir2),
108
+ (file) => import_fs.default.unlinkSync(file)
91
109
  );
92
110
  }
93
111
  async function init() {
94
112
  console.log();
95
113
  let defaultBanner = "Widget.js - The Desktop Widget Framework";
96
- const gradientBanner = gradient([
114
+ const gradientBanner = (0, import_gradient_string.default)([
97
115
  { color: "#42d392", pos: 0 },
98
116
  { color: "#42d392", pos: 0.1 },
99
117
  { color: "#647eff", pos: 1 }
100
118
  ])(defaultBanner);
101
119
  console.log(process.stdout.isTTY && process.stdout.getColorDepth() > 8 ? gradientBanner : defaultBanner);
102
120
  console.log();
103
- const argv2 = minimist(process.argv.slice(2), {
121
+ const argv2 = (0, import_minimist.default)(process.argv.slice(2), {
104
122
  alias: {
105
123
  typescript: ["ts"],
106
124
  "with-tests": ["tests"],
@@ -115,7 +133,7 @@ async function init() {
115
133
  const forceOverwrite = argv2.force;
116
134
  const cwd2 = process.cwd();
117
135
  let result = {};
118
- result = await prompts(
136
+ result = await (0, import_prompts.default)(
119
137
  [
120
138
  {
121
139
  name: "projectName",
@@ -135,20 +153,20 @@ async function init() {
135
153
  ],
136
154
  {
137
155
  onCancel: () => {
138
- throw new Error(chalk.red("\u2716") + " Operation cancelled");
156
+ throw new Error(import_chalk.default.red("\u2716") + " Operation cancelled");
139
157
  }
140
158
  }
141
159
  );
142
160
  const { projectName, shouldOverwrite = argv2.force } = result;
143
- const root = path2.join(cwd2, targetDir);
144
- if (fs3.existsSync(root) && shouldOverwrite) {
161
+ const root = import_path.default.join(cwd2, targetDir);
162
+ if (import_fs.default.existsSync(root) && shouldOverwrite) {
145
163
  emptyDir(root);
146
- } else if (!fs3.existsSync(root)) {
147
- fs3.mkdirSync(root);
164
+ } else if (!import_fs.default.existsSync(root)) {
165
+ import_fs.default.mkdirSync(root);
148
166
  }
149
167
  console.log(`
150
168
  Scaffolding project in ${root}...`);
151
- const templateRoot = path2.join(__dirname, "../template");
169
+ const templateRoot = import_path.default.join(__dirname, "../template");
152
170
  await FileUtils.copyFolderRecursive(templateRoot, root);
153
171
  const userAgent = process.env.npm_config_user_agent ?? "";
154
172
  const packageManager = /pnpm/.test(userAgent) ? "pnpm" : /yarn/.test(userAgent) ? "yarn" : "npm";
@@ -156,10 +174,10 @@ Scaffolding project in ${root}...`);
156
174
  Done. Now run:
157
175
  `);
158
176
  if (root !== cwd2) {
159
- const cdProjectName = path2.relative(cwd2, root);
160
- console.log(` ${chalk.bold(chalk.green(`cd ${cdProjectName.includes(" ") ? `"${cdProjectName}"` : cdProjectName}`))}`);
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}`))}`);
161
179
  }
162
- console.log(` ${chalk.bold(chalk.green(getCommand(packageManager, "install")))}`);
180
+ console.log(` ${import_chalk.default.bold(import_chalk.default.green(getCommand(packageManager, "install")))}`);
163
181
  }
164
182
  init().catch((e) => {
165
183
  console.error(e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-widget",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "main": "lib/index.js",
5
5
  "author": "Neo Fu",
6
6
  "license": "MIT",
@@ -12,7 +12,6 @@
12
12
  "lib/index.js",
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": "^5.3.0",
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,7 +42,7 @@
43
42
  "vitest": "^0.34.6"
44
43
  },
45
44
  "scripts": {
46
- "build": "rimraf ./lib/ && tsup-node src/index.ts --format esm",
45
+ "build": "rimraf ./lib/ && tsup-node src/index.ts --format cjs",
47
46
  "watch": "tsup-node src/index.ts --format esm --watch",
48
47
  "build:run": "npm run build && npm run create-widget",
49
48
  "create-widget": "node ./lib/index.js",