@citruslime/create-boilerplate 1.0.0-beta.11 → 1.0.0-beta.12

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.
@@ -1,13 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { execSync } from 'child_process';
4
- import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'fs';
5
- import { dirname, join } from 'path';
6
- import { fileURLToPath } from 'url';
3
+ const { execSync } = require('child_process');
4
+ const { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } = require('fs');
5
+ const { join } = require('path');
7
6
 
8
- import { lightBlue, green, red } from 'kolorist';
9
- import parseArgs from 'minimist';
10
- import prompts from 'prompts';
7
+ const { lightBlue, green, red } = require('kolorist');
8
+ const parseArgs = require('minimist');
9
+ const prompts = require('prompts');
11
10
 
12
11
  const argv = parseArgs(process.argv.slice(2));
13
12
  const cwd = process.cwd();
@@ -208,6 +207,9 @@ async function init () {
208
207
  process.chdir(packageDir);
209
208
  installDependencies(packageManager);
210
209
 
210
+ print(lightBlue('Creating hooks...'), true);
211
+ copyHooks(packageDir, rootDir);
212
+
211
213
  print(green(`Package ${packageName} has been successfully initialised in ${packageDir}.`), true);
212
214
  }
213
215
 
@@ -258,12 +260,24 @@ function prepareDir (path, empty) {
258
260
  * @param {string} packageDir The directory of the new package.
259
261
  */
260
262
  function copyTemplate (packageDir) {
261
- const codeDir = fileURLToPath(dirname(import.meta.url));
262
- const templateDir = join(codeDir, 'template');
263
+ const templateDir = join(__dirname, 'template');
263
264
 
264
265
  forEachInDir(templateDir, (item) => copy(templateDir, packageDir, item));
265
266
  }
266
267
 
268
+ /**
269
+ * Copies the hooks directory into the husky directory for the repository.
270
+ *
271
+ * @param {string} packageDir The directory of the new package.
272
+ * @param {string} rootDir The relative path from the package directory to the root of the repository.
273
+ */
274
+ function copyHooks (packageDir, rootDir) {
275
+ const hooksDir = join(__dirname, 'hooks');
276
+ const huskyDir = join(cwd, packageDir, rootDir, '.husky');
277
+
278
+ forEachInDir(hooksDir, (item) => copy(hooksDir, huskyDir, item));
279
+ }
280
+
267
281
  /**
268
282
  * Copies a file or directory from one location to another.
269
283
  *
@@ -284,22 +298,28 @@ function copy (source, destination, item) {
284
298
  }
285
299
  else {
286
300
  const destinationFile = filesToRename[item] ? join(destination, filesToRename[item]) : join(destination, item);
287
- const options = {
288
- encoding: 'utf-8'
289
- };
290
301
 
291
- print(lightBlue(`Copying ${item}...`), true);
302
+ if (existsSync(destinationFile)) {
303
+ print(lightBlue(`Skipping ${item}...`), true);
304
+ }
305
+ else {
306
+ const options = {
307
+ encoding: 'utf-8'
308
+ };
292
309
 
293
- let contents = readFileSync(sourceItem, options);
310
+ print(lightBlue(`Copying ${item}...`), true);
294
311
 
295
- for (const [
296
- key,
297
- value
298
- ] of Object.entries(placeholdersToReplace)) {
299
- contents = contents.replace(key, value);
300
- }
312
+ let contents = readFileSync(sourceItem, options);
301
313
 
302
- writeFileSync(destinationFile, contents, options);
314
+ for (const [
315
+ key,
316
+ value
317
+ ] of Object.entries(placeholdersToReplace)) {
318
+ contents = contents.replace(key, value);
319
+ }
320
+
321
+ writeFileSync(destinationFile, contents, options);
322
+ }
303
323
  }
304
324
  }
305
325
 
@@ -365,9 +385,5 @@ function print (message, clearPrevious = false) {
365
385
  process.stdout.write(message);
366
386
  }
367
387
 
368
- try {
369
- await init();
370
- }
371
- catch (e) {
372
- print(red(e.message));
373
- }
388
+ init()
389
+ .catch(e => print(red(`\n${e.message}`)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@citruslime/create-boilerplate",
3
- "version": "1.0.0-beta.11",
3
+ "version": "1.0.0-beta.12",
4
4
  "author": {
5
5
  "name": "Citrus-Lime Ltd",
6
6
  "url": "https://citruslime.com"
@@ -11,12 +11,12 @@
11
11
  "access": "public"
12
12
  },
13
13
  "files": [
14
- "main.mjs",
14
+ "main.js",
15
15
  "template-*"
16
16
  ],
17
- "main": "main.mjs",
17
+ "main": "main.js",
18
18
  "bin": {
19
- "create-boilerplate": "main.mjs"
19
+ "create-boilerplate": "main.js"
20
20
  },
21
21
  "engines": {
22
22
  "node": ">=14.0.0"