create-blocklet 0.4.74 → 0.4.75

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.
@@ -0,0 +1,28 @@
1
+ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
+
3
+ # dependencies
4
+ .pnp
5
+ .pnp.js
6
+ .DS_Store
7
+ node_modules
8
+
9
+ # testing
10
+ coverage
11
+
12
+ # production
13
+ build
14
+ dist
15
+ dist-ssr
16
+ .blocklet
17
+
18
+ # local env files
19
+ *.local
20
+
21
+ # Log files
22
+ logs
23
+ *.log
24
+ npm-debug.log*
25
+ yarn-debug.log*
26
+ yarn-error.log*
27
+ pnpm-debug.log*
28
+ lerna-debug.log*
package/common/_npmrc ADDED
@@ -0,0 +1,3 @@
1
+ ## force pnpm to hoist
2
+ shamefully-hoist=true
3
+ strict-peer-dependencies=false
package/index.js CHANGED
@@ -16,6 +16,7 @@ import { checkServerInstalled, checkServerRunning, checkSatisfiedVersion, getSer
16
16
  import { toBlockletDid } from './lib/did.js';
17
17
  import { initGitRepo } from './lib/git.js';
18
18
  import {
19
+ copy,
19
20
  emptyDir,
20
21
  isEmpty,
21
22
  isValidPackageName,
@@ -114,7 +115,11 @@ const templates = [
114
115
  },
115
116
  ];
116
117
 
117
-
118
+ //see: https://github.com/npm/npm/issues/3763
119
+ const renameFiles = {
120
+ _gitignore: '.gitignore',
121
+ _npmrc: '.npmrc',
122
+ };
118
123
 
119
124
  async function init() {
120
125
  const { version } = await fs.readJSONSync(path.resolve(__dirname, 'package.json'));
@@ -122,7 +127,7 @@ async function init() {
122
127
 
123
128
  let targetDir = argv._[0] ? String(argv._[0]) : undefined;
124
129
  const inputTemplateName = argv.template;
125
- if (inputTemplateName && !templates.find(item => item.name === inputTemplateName)) {
130
+ if (inputTemplateName && !templates.find((item) => item.name === inputTemplateName)) {
126
131
  console.error(`${red('✖')} The template ${inputTemplateName} is invalid.`);
127
132
  return;
128
133
  }
@@ -168,40 +173,42 @@ async function init() {
168
173
  initial: () => toValidPackageName(targetDir),
169
174
  validate: (dir) => isValidPackageName(dir) || 'Invalid package.json name',
170
175
  },
171
- ...(inputTemplateName ? [] : [
172
- {
173
- type: 'autocompleteMultiselect',
174
- name: 'templateNames',
175
- message: 'Choose one or more blocklet templates:',
176
- choices: templates.map((template) => {
177
- const templateColor = template.color;
178
- return {
179
- title: templateColor(template.display),
180
- value: template.name,
181
- };
182
- }),
183
- min: 1,
184
- suggest: (input, choices) => Promise.resolve(choices.filter((i) => i.title.includes(input))),
185
- },
186
- // 这里需要添加一步 如果选择了 多项 就要提示用户设置主应用
187
- {
188
- type: (templateNames = []) => {
189
- return templateNames.length > 1 ? 'select' : null;
190
- },
191
- name: 'mainBlocklet',
192
- message: 'Please choose the main blocklet',
193
- //
194
- choices: (templateNames = []) =>
195
- templateNames.map((templateName) => {
196
- const template = templates.find((x) => x.name === templateName);
197
- return {
198
- title: template.display,
199
- value: template.name,
200
- };
201
- }),
202
- initial: 1,
203
- },
204
- ]),
176
+ ...(inputTemplateName
177
+ ? []
178
+ : [
179
+ {
180
+ type: 'autocompleteMultiselect',
181
+ name: 'templateNames',
182
+ message: 'Choose one or more blocklet templates:',
183
+ choices: templates.map((template) => {
184
+ const templateColor = template.color;
185
+ return {
186
+ title: templateColor(template.display),
187
+ value: template.name,
188
+ };
189
+ }),
190
+ min: 1,
191
+ suggest: (input, choices) => Promise.resolve(choices.filter((i) => i.title.includes(input))),
192
+ },
193
+ // 这里需要添加一步 如果选择了 多项 就要提示用户设置主应用
194
+ {
195
+ type: (templateNames = []) => {
196
+ return templateNames.length > 1 ? 'select' : null;
197
+ },
198
+ name: 'mainBlocklet',
199
+ message: 'Please choose the main blocklet',
200
+ //
201
+ choices: (templateNames = []) =>
202
+ templateNames.map((templateName) => {
203
+ const template = templates.find((x) => x.name === templateName);
204
+ return {
205
+ title: template.display,
206
+ value: template.name,
207
+ };
208
+ }),
209
+ initial: 1,
210
+ },
211
+ ]),
205
212
  {
206
213
  type: 'text',
207
214
  name: 'authorName',
@@ -229,7 +236,14 @@ async function init() {
229
236
  }
230
237
 
231
238
  // user choice associated with prompts
232
- const { mainBlocklet = null, templateNames = inputTemplateName ? [inputTemplateName] : [], overwrite, packageName, authorName, authorEmail } = result;
239
+ const {
240
+ mainBlocklet = null,
241
+ templateNames = inputTemplateName ? [inputTemplateName] : [],
242
+ overwrite,
243
+ packageName,
244
+ authorName,
245
+ authorEmail,
246
+ } = result;
233
247
 
234
248
  await echoDocument();
235
249
 
@@ -260,7 +274,12 @@ async function init() {
260
274
  if (mainBlocklet) {
261
275
  await checkLerna();
262
276
  await checkYarn();
263
- fs.copySync(path.join(__dirname, 'templates', 'monorepo'), root);
277
+ const monorepoDir = path.join(__dirname, 'templates', 'monorepo');
278
+ const monorepoFiles = fs.readdirSync(monorepoDir);
279
+ for (const file of monorepoFiles) {
280
+ const targetPath = path.join(root, renameFiles[file]||file);
281
+ copy(path.join(monorepoDir, file), targetPath);
282
+ }
264
283
  }
265
284
 
266
285
  for (const templateName of templateNames) {
@@ -273,7 +292,7 @@ async function init() {
273
292
  const commonFiles = fs.readdirSync(commonDir);
274
293
  for (const file of commonFiles) {
275
294
  // 如果选择多个模板,每个子 package 中 只会包含必要的 文件
276
- if (mainBlocklet && !['screenshots', 'public', 'logo.png', '.prettierrc','LICENSE'].includes(file)) {
295
+ if (mainBlocklet && !['screenshots', 'public', 'logo.png', '.prettierrc', 'LICENSE'].includes(file)) {
277
296
  continue;
278
297
  }
279
298
  // xmark 相关的模板不添加 .husky
@@ -281,16 +300,18 @@ async function init() {
281
300
  // eslint-disable-next-line no-continue
282
301
  continue;
283
302
  }
284
- const targetPath = path.join(root, mainBlocklet ? `blocklets/${templateName}` : '', file);
303
+ const targetPath = renameFiles[file]
304
+ ? path.join(root, mainBlocklet ? `blocklets/${templateName}` : '', renameFiles[file])
305
+ : path.join(root, mainBlocklet ? `blocklets/${templateName}` : '', file);
285
306
 
286
- fs.copySync(path.join(commonDir, file), targetPath);
307
+ copy(path.join(commonDir, file), targetPath);
287
308
  }
288
309
  })();
289
310
 
290
311
  // copy template files
291
312
  (() => {
292
313
  // 过滤掉 template-info.json 文件
293
- const files = fs.readdirSync(templateDir).filter(file => file !== 'template-info.json');
314
+ const files = fs.readdirSync(templateDir).filter((file) => file !== 'template-info.json');
294
315
  for (const file of files) {
295
316
  write(file, null, templateDir, templateName);
296
317
  }
@@ -510,11 +531,13 @@ async function init() {
510
531
 
511
532
  // inside functions
512
533
  function write(file, content, templateDir, templateName) {
513
- const targetPath = path.join(root, mainBlocklet ? `blocklets/${templateName}` : '', file);
534
+ const targetPath = renameFiles[file]
535
+ ? path.join(root, mainBlocklet ? `blocklets/${templateName}` : '', renameFiles[file])
536
+ : path.join(root, mainBlocklet ? `blocklets/${templateName}` : '', file);
514
537
  if (content) {
515
538
  fs.writeFileSync(targetPath, content);
516
539
  } else {
517
- fs.copySync(path.join(templateDir, file), targetPath);
540
+ copy(path.join(templateDir, file), targetPath);
518
541
  }
519
542
  }
520
543
  function read(file, templateName) {
package/lib/utils.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { fs, path, $, echo, chalk } from 'zx';
2
+
2
3
  $.verbose = false;
3
4
 
4
5
  // common functions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-blocklet",
3
- "version": "0.4.74",
3
+ "version": "0.4.75",
4
4
  "exports": "./index.js",
5
5
  "type": "module",
6
6
  "repository": "git@github.com:blocklet/create-blocklet.git",
@@ -0,0 +1,28 @@
1
+ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
+
3
+ # dependencies
4
+ .pnp
5
+ .pnp.js
6
+ .DS_Store
7
+ node_modules
8
+
9
+ # testing
10
+ coverage
11
+
12
+ # production
13
+ build
14
+ dist
15
+ dist-ssr
16
+ .blocklet
17
+
18
+ # local env files
19
+ *.local
20
+
21
+ # Log files
22
+ logs
23
+ *.log
24
+ npm-debug.log*
25
+ yarn-debug.log*
26
+ yarn-error.log*
27
+ pnpm-debug.log*
28
+ lerna-debug.log*
@@ -70,7 +70,7 @@
70
70
  "npm-run-all": "^4.1.5",
71
71
  "prettier": "^2.7.1",
72
72
  "vite": "^3.1.8",
73
- "vite-plugin-blocklet": "^0.4.74",
73
+ "vite-plugin-blocklet": "^0.4.75",
74
74
  "vite-plugin-html": "^3.2.0",
75
75
  "vite-plugin-svgr": "^2.2.2"
76
76
  }
@@ -70,7 +70,7 @@
70
70
  "npm-run-all": "^4.1.5",
71
71
  "prettier": "^2.7.1",
72
72
  "vite": "^3.1.8",
73
- "vite-plugin-blocklet": "^0.4.74",
73
+ "vite-plugin-blocklet": "^0.4.75",
74
74
  "vite-plugin-html": "^3.2.0",
75
75
  "vite-plugin-svgr": "^2.2.2"
76
76
  }
@@ -50,7 +50,7 @@
50
50
  "lint-staged": "^12.5.0",
51
51
  "prettier": "^2.7.1",
52
52
  "vite": "^3.1.8",
53
- "vite-plugin-blocklet": "^0.4.74",
53
+ "vite-plugin-blocklet": "^0.4.75",
54
54
  "vite-plugin-html": "^3.2.0",
55
55
  "vite-plugin-svgr": "^2.2.2"
56
56
  }
@@ -32,7 +32,7 @@
32
32
  "npm-run-all": "^4.1.5",
33
33
  "prettier": "^2.7.1",
34
34
  "vite": "^3.1.8",
35
- "vite-plugin-blocklet": "^0.4.74",
35
+ "vite-plugin-blocklet": "^0.4.75",
36
36
  "vite-plugin-html": "^3.2.0",
37
37
  "vite-plugin-solid": "^2.3.9"
38
38
  },
@@ -26,7 +26,7 @@
26
26
  "lint-staged": "^12.5.0",
27
27
  "prettier": "^2.7.1",
28
28
  "vite": "^3.1.8",
29
- "vite-plugin-blocklet": "^0.4.74",
29
+ "vite-plugin-blocklet": "^0.4.75",
30
30
  "vite-plugin-html": "^3.2.0",
31
31
  "vite-plugin-solid": "^2.3.9"
32
32
  },
@@ -46,7 +46,7 @@
46
46
  "prettier": "^2.7.1",
47
47
  "svelte": "^3.51.0",
48
48
  "vite": "^3.1.8",
49
- "vite-plugin-blocklet": "^0.4.74",
49
+ "vite-plugin-blocklet": "^0.4.75",
50
50
  "vite-plugin-html": "^3.2.0"
51
51
  },
52
52
  "lint-staged": {
@@ -27,7 +27,7 @@
27
27
  "prettier": "^2.7.1",
28
28
  "svelte": "^3.51.0",
29
29
  "vite": "^3.1.8",
30
- "vite-plugin-blocklet": "^0.4.74",
30
+ "vite-plugin-blocklet": "^0.4.75",
31
31
  "vite-plugin-html": "^3.2.0"
32
32
  },
33
33
  "lint-staged": {
@@ -49,7 +49,7 @@
49
49
  "npm-run-all": "^4.1.5",
50
50
  "prettier": "^2.7.1",
51
51
  "vite": "^3.1.8",
52
- "vite-plugin-blocklet": "^0.4.74"
52
+ "vite-plugin-blocklet": "^0.4.75"
53
53
  },
54
54
  "lint-staged": {
55
55
  "*.{mjs,js,vue}": [
@@ -28,7 +28,7 @@
28
28
  "lint-staged": "^12.5.0",
29
29
  "prettier": "^2.7.1",
30
30
  "vite": "^3.1.8",
31
- "vite-plugin-blocklet": "^0.4.74",
31
+ "vite-plugin-blocklet": "^0.4.75",
32
32
  "vite-plugin-html": "^3.2.0"
33
33
  },
34
34
  "lint-staged": {