@mateoserrano/simple-config 1.1.3 → 1.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mateoserrano/simple-config",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "description": "Initialize ESLint, Prettier, Husky and lint-staged for modern TypeScript projects",
package/src/constants.js CHANGED
@@ -62,11 +62,7 @@ export const devDepFiles = {
62
62
  },
63
63
  ],
64
64
  }
65
- export const addHuskyPrepare = 'npm pkg set scripts.prepare="husky"'
65
+ export const addHuskyPrepare = 'npm pkg set scripts.prepare="husky init"'
66
66
  export const installCmd = (installNames) => `npm install -D ${installNames.join(' ')} --save-exact`
67
- export const setupHuskyCommand = 'echo "' +
68
- '#!/usr/bin/env sh\n' +
69
- '. "$(dirname -- "$0")/_/husky.sh"\n\n' +
70
- 'npx lint-staged"' +
71
- '> .husky/pre-commit'
72
- export const authorizeHuskyCommand = 'chmod +x .husky/pre-commit'
67
+ export const prepareHuskyCommand = 'npx run prepare'
68
+ export const setupHuskyCommand = 'npx husky add .husky/pre-commit "npx lint-staged"'
package/src/core/deps.js CHANGED
@@ -1,4 +1,5 @@
1
- import { getPackageRoot, moveFromPath } from './utils/index.js'
1
+ import { moveFromPath } from './utils/index.js'
2
+ import { getPackageRoot } from './urls.js'
2
3
  import { copyFileToFolderOrSkip } from './files.js'
3
4
 
4
5
  export const getTemplatesFolder = (templatesRelativePath) => {
@@ -0,0 +1,20 @@
1
+ import { fileURLToPath } from 'node:url'
2
+ import { moveFromPath, verifyValidFile } from './utils/files.js'
3
+
4
+ export function getPackageRoot() {
5
+ let current = fileURLToPath(new URL('.', import.meta.url))
6
+
7
+ while (true) {
8
+ if (verifyValidFile(moveFromPath(current, 'package.json'))) {
9
+ return current
10
+ }
11
+
12
+ const parent = moveFromPath(current, '..')
13
+
14
+ if (parent === current) {
15
+ throw new Error('package.json not found')
16
+ }
17
+
18
+ current = parent
19
+ }
20
+ }
@@ -1,2 +1 @@
1
1
  export * from './files.js'
2
- export * from './urls.js'
package/src/functions.js CHANGED
@@ -6,18 +6,19 @@ import {
6
6
  verifyNodePackage,
7
7
  } from './core/index.js'
8
8
  import {
9
- addHuskyPrepare, authorizeHuskyCommand,
9
+ addHuskyPrepare,
10
10
  devDepFiles,
11
11
  devDeps,
12
12
  installCmd,
13
+ prepareHuskyCommand,
13
14
  setupHuskyCommand,
14
15
  } from './constants.js'
15
16
 
16
17
  const runAddPrepareCommand = () => runCommandSilent(addHuskyPrepare)
17
18
  const runInstallCommand = (installNames) => runCommandSilent(installCmd(installNames))
18
19
  const runHuskyCommand = () => {
20
+ runCommandSilent(prepareHuskyCommand)
19
21
  runCommandSilent(setupHuskyCommand)
20
- runCommandSilent(authorizeHuskyCommand)
21
22
  }
22
23
  const getInstallationArguments = () => getInstallNames(devDeps)
23
24
 
@@ -38,6 +39,6 @@ export const configureHusky = () => {
38
39
  }
39
40
  export const copyConfigurationFiles = () => {
40
41
  console.log('Copying configuration files...')
41
- const templatesDirectory = getTemplatesFolder('../templates')
42
+ const templatesDirectory = getTemplatesFolder('templates')
42
43
  copyFilesToTargetOrSkip(devDepFiles, templatesDirectory)
43
44
  }
@@ -1,7 +0,0 @@
1
- import { fileURLToPath } from 'node:url'
2
- import { resolve } from "node:path";
3
-
4
- export function getPackageRoot() {
5
- const currentDir = fileURLToPath(new URL('.', import.meta.url))
6
- return resolve(currentDir, '..', '..')
7
- }