@mateoserrano/simple-config 1.1.0 → 1.1.1

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.0",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "description": "Initialize ESLint, Prettier, Husky and lint-staged for modern TypeScript projects",
@@ -14,7 +14,8 @@
14
14
  ],
15
15
  "files": [
16
16
  "scripts/",
17
- "templates/"
17
+ "templates/",
18
+ "src/**"
18
19
  ],
19
20
  "bin": {
20
21
  "dev-config": "./scripts/init.js"
@@ -0,0 +1,67 @@
1
+ export const devDeps = {
2
+ tsx: {
3
+ package: 'tsx',
4
+ version: '4.20.6',
5
+ },
6
+ eslint: {
7
+ package: 'eslint',
8
+ version: '9.39.1',
9
+ },
10
+ typescriptEslint: {
11
+ package: 'typescript-eslint',
12
+ version: '8.46.4',
13
+ },
14
+ eslintJs: {
15
+ package: '@eslint/js',
16
+ version: '9.39.1',
17
+ },
18
+ prettier: {
19
+ package: 'prettier',
20
+ version: '3.6.2',
21
+ },
22
+ eslintConfigPrettier: {
23
+ package: 'eslint-config-prettier',
24
+ version: '10.1.8',
25
+ },
26
+ lintStaged: {
27
+ package: 'lint-staged',
28
+ version: '16.2.7',
29
+ },
30
+ husky: {
31
+ package: 'husky',
32
+ version: '9.1.7',
33
+ },
34
+ globals: {
35
+ package: 'globals',
36
+ version: '17.0.0',
37
+ }
38
+ }
39
+ export const devDepFiles = {
40
+ eslint: [
41
+ {
42
+ source: 'eslint.config.js',
43
+ target: '.',
44
+ },
45
+ ],
46
+ prettier: [
47
+ {
48
+ source: 'prettier.config.js',
49
+ target: '.',
50
+ },
51
+ ],
52
+ lintStaged: [
53
+ {
54
+ source: 'lint-staged.config.js',
55
+ target: '.',
56
+ },
57
+ ],
58
+ typescript: [
59
+ {
60
+ source: 'tsconfig.json',
61
+ target: '.',
62
+ },
63
+ ],
64
+ }
65
+ export const addHuskyPrepare = 'npm pkg set scripts.prepare="husky"'
66
+ export const installCmd = (installNames) => `npm install -D ${installNames.join(' ')} --save-exact`
67
+ export const setupHuskyCommand = 'npx husky add .husky/pre-commit "npx lint-staged"'
@@ -0,0 +1,4 @@
1
+ import { execSync } from 'node:child_process'
2
+
3
+ export const runCommand = (command) => execSync(command, { stdio: 'inherit' })
4
+ export const runCommandSilent = (command) => execSync(command, { stdio: 'ignore' })
@@ -0,0 +1,19 @@
1
+ import { getRemoteUrl, moveFromPath } from './utils/index.js'
2
+ import { copyFileToFolderOrSkip } from './files.js'
3
+
4
+ export const getTemplatesFolder = (templatesRelativePath) => {
5
+ const repositoryDirname = getRemoteUrl()
6
+ return moveFromPath(repositoryDirname, templatesRelativePath)
7
+ }
8
+ export const getInstallNames = (devDeps) =>
9
+ Object.values(devDeps).map((dep) => `${dep.package}@${dep.version}`)
10
+ export const copyFilesToTargetOrSkip = (devDepFiles, templatesDirectory) => {
11
+ const cwd = process.cwd()
12
+ Object.values(devDepFiles).forEach((group) =>
13
+ group.forEach((file) => {
14
+ const source = moveFromPath(templatesDirectory, file.source)
15
+ const targetFolder = moveFromPath(cwd, file.target)
16
+ copyFileToFolderOrSkip(source, targetFolder)
17
+ }),
18
+ )
19
+ }
@@ -0,0 +1,24 @@
1
+ import { basename } from 'node:path'
2
+ import { cpSync } from 'node:fs'
3
+ import { createFolder, verifyValidFile, verifyValidDirectory, moveFromPath } from './utils/index.js'
4
+
5
+ export const verifyNodePackage = () => verifyValidFile(moveFromPath(process.cwd(), 'package.json'))
6
+ export function copyFileToFolderOrSkip(sourceFile, targetDirectory) {
7
+ const sourceFileName = basename(sourceFile)
8
+ const outputFileName = moveFromPath(targetDirectory, sourceFileName)
9
+
10
+ if (!verifyValidFile(sourceFile)) {
11
+ console.error(`File does not exist: ${sourceFile}`)
12
+ return
13
+ }
14
+ if (!verifyValidDirectory(targetDirectory)) {
15
+ console.log(`Creating folder ${targetDirectory}...`)
16
+ createFolder(targetDirectory)
17
+ }
18
+ if (verifyValidFile(outputFileName)) {
19
+ console.log(`File ${sourceFileName} already exists in ${targetDirectory}. Skipping...`)
20
+ return
21
+ }
22
+ const destinationPath = moveFromPath(targetDirectory, sourceFileName)
23
+ cpSync(sourceFile, destinationPath)
24
+ }
@@ -0,0 +1,3 @@
1
+ export * from './commands.js'
2
+ export * from './deps.js'
3
+ export * from './files.js'
@@ -0,0 +1,7 @@
1
+ import { join } from 'node:path'
2
+ import { existsSync, mkdirSync } from 'node:fs'
3
+
4
+ export const createFolder = (dirname) => mkdirSync(dirname, { recursive: true })
5
+ export const verifyValidFile = (filePath) => existsSync(filePath)
6
+ export const verifyValidDirectory = (directory) => existsSync(directory)
7
+ export const moveFromPath = (directory, filename) => join(directory, filename)
@@ -0,0 +1,2 @@
1
+ export * from './files.js'
2
+ export * from './urls.js'
@@ -0,0 +1,5 @@
1
+ import { fileURLToPath } from 'node:url'
2
+
3
+ export function getRemoteUrl() {
4
+ return fileURLToPath(new URL('.', import.meta.url))
5
+ }
@@ -0,0 +1,43 @@
1
+ import {
2
+ copyFilesToTargetOrSkip,
3
+ getInstallNames,
4
+ getTemplatesFolder,
5
+ runCommand,
6
+ runCommandSilent,
7
+ verifyNodePackage,
8
+ } from './core/index.js'
9
+ import {
10
+ addHuskyPrepare,
11
+ devDepFiles,
12
+ devDeps,
13
+ installCmd,
14
+ setupHuskyCommand,
15
+ } from './constants.js'
16
+
17
+ const runAddPrepareCommand = () => runCommandSilent(addHuskyPrepare)
18
+ const runInstallCommand = (installNames) => runCommandSilent(installCmd(installNames))
19
+ const runHuskyCommand = () => {
20
+ runCommand(setupHuskyCommand)
21
+ }
22
+ const getInstallationArguments = () => getInstallNames(devDeps)
23
+
24
+ export const assertValidNodePackage = () => {
25
+ if (!verifyNodePackage()) {
26
+ console.error('Error: package.json not found.')
27
+ process.exit(1)
28
+ }
29
+ }
30
+ export const installDependencies = () => {
31
+ console.log('Installing dependencies...')
32
+ runAddPrepareCommand()
33
+ runInstallCommand(getInstallationArguments())
34
+ }
35
+ export const configureHusky = () => {
36
+ console.log('Configuring Husky...')
37
+ runHuskyCommand()
38
+ }
39
+ export const copyConfigurationFiles = () => {
40
+ console.log('Copying configuration files...')
41
+ const templatesDirectory = getTemplatesFolder('../templates')
42
+ copyFilesToTargetOrSkip(devDepFiles, templatesDirectory)
43
+ }
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './functions.js'