@mateoserrano/simple-config 1.0.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/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # Typescript Utilities
2
-
3
- ### Development dependencies
4
-
5
- 1. Typescript
6
- 2. ESLint
7
- 3. Prettier
8
- 4. lint-staged
9
- 5. Husky
1
+ # Typescript Utilities
2
+
3
+ ### Development dependencies
4
+
5
+ 1. Typescript
6
+ 2. ESLint
7
+ 3. Prettier
8
+ 4. lint-staged
9
+ 5. Husky
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mateoserrano/simple-config",
3
- "version": "1.0.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,12 +14,28 @@
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"
21
22
  },
22
23
  "engines": {
23
24
  "node": ">=20"
25
+ },
26
+ "devDependencies": {
27
+ "@eslint/js": "9.39.1",
28
+ "@types/node": "25.0.3",
29
+ "eslint": "9.39.1",
30
+ "eslint-config-prettier": "10.1.8",
31
+ "globals": "17.0.0",
32
+ "husky": "9.1.7",
33
+ "lint-staged": "16.2.7",
34
+ "prettier": "3.6.2",
35
+ "tsx": "4.20.6",
36
+ "typescript-eslint": "8.46.4"
37
+ },
38
+ "scripts": {
39
+ "prepare": "husky"
24
40
  }
25
41
  }
package/scripts/init.js CHANGED
@@ -1,128 +1,13 @@
1
- #!/usr/bin/env node
2
-
3
- import { execSync } from 'node:child_process'
4
- import { cpSync, existsSync, mkdirSync } from 'node:fs'
5
- import { basename, join } from 'node:path'
6
- import { fileURLToPath } from 'node:url';
7
-
8
- // Dependencies
9
- const devDeps = {
10
- tsx: {
11
- package: 'tsx',
12
- version: '4.20.6',
13
- },
14
- eslint: {
15
- package: 'eslint',
16
- version: '9.39.1',
17
- },
18
- typescriptEslint: {
19
- package: 'typescript-eslint',
20
- version: '8.46.4',
21
- },
22
- eslintJs: {
23
- package: '@eslint/js',
24
- version: '9.39.1',
25
- },
26
- prettier: {
27
- package: 'prettier',
28
- version: '3.6.2',
29
- },
30
- eslintConfigPrettier: {
31
- package: 'eslint-config-prettier',
32
- version: '10.1.8',
33
- },
34
- lintStaged: {
35
- package: 'lint-staged',
36
- version: '16.2.7',
37
- },
38
- husky: {
39
- package: 'husky',
40
- version: '9.1.7',
41
- },
42
- };
43
- const devDepFiles = {
44
- eslint: [
45
- {
46
- source: 'eslint.config.js',
47
- target: '.',
48
- },
49
- ],
50
- prettier: [
51
- {
52
- source: 'prettier.config.js',
53
- target: '.',
54
- },
55
- ],
56
- lintStaged: [
57
- {
58
- source: 'lint-staged.config.js',
59
- target: '.',
60
- },
61
- ],
62
- typescript: [
63
- {
64
- source: 'tsconfig.json',
65
- target: '.',
66
- },
67
- ],
68
- };
69
-
70
- function copyFileToFolderOrSkip(sourceFile, targetFolder) {
71
- const sourceFileName = basename(sourceFile);
72
- if (!existsSync(sourceFile)) {
73
- console.error(`Source file not found: ${sourceFile}`);
74
- return;
75
- }
76
-
77
- if (existsSync(join(targetFolder, sourceFileName))) {
78
- console.log(`File ${sourceFileName} already exists in ${targetFolder}. Skipping...`);
79
- return;
80
- }
81
- if (!existsSync(targetFolder)) {
82
- console.log(`Creating folder ${targetFolder}...`);
83
- mkdirSync(targetFolder, { recursive: true });
84
- }
85
-
86
- const destinationPath = join(targetFolder, sourceFileName);
87
- cpSync(sourceFile, destinationPath);
88
- }
89
-
90
- let installNames = [];
91
- for (const dep of Object.values(devDeps)) {
92
- installNames.push(`${dep.package}@${dep.version}`);
93
- }
94
-
95
- const installCmd = `npm install -D ${installNames.join(' ')}`;
96
- const installHuskyCmd = 'npx husky install';
97
- const setupHuskyCmd = 'npx husky add .husky/pre-commit "npx lint-staged"';
98
-
99
- const runSilent = cmd => execSync(cmd, { stdio: 'ignore' });
100
- const cwd = process.cwd();
101
-
102
- if (!existsSync(join(cwd, 'package.json'))) {
103
- console.error('No package.json found.');
104
- process.exit(1);
105
- }
106
-
107
- const repositoryDirname = fileURLToPath(new URL('.', import.meta.url));
108
- const templatesFolder = join(repositoryDirname, '../templates');
109
-
110
- // Install dependencies
111
- console.log('Installing dependencies...');
112
- runSilent(installCmd);
113
-
114
- // Husky
115
- console.log('Configuring Husky...');
116
- runSilent(installHuskyCmd);
117
- runSilent(setupHuskyCmd);
118
-
119
- // Copy files
120
- for (const fileGroup of Object.values(devDepFiles)) {
121
- for (const file of fileGroup) {
122
- const source = join(templatesFolder, file.source);
123
- const targetFolder = join(cwd, file.target);
124
- copyFileToFolderOrSkip(source, targetFolder);
125
- }
126
- }
127
-
128
- console.log('\nDependencies installed successfully.');
1
+ #!/usr/bin/env node
2
+
3
+ import {
4
+ assertValidNodePackage,
5
+ installDependencies,
6
+ configureHusky,
7
+ copyConfigurationFiles,
8
+ } from '../src/index.js'
9
+
10
+ assertValidNodePackage()
11
+ installDependencies()
12
+ configureHusky()
13
+ copyConfigurationFiles()
@@ -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'
@@ -1,16 +1,17 @@
1
- import js from '@eslint/js';
2
- import tseslint from 'typescript-eslint';
3
- import eslintConfigPrettier from 'eslint-config-prettier';
4
-
5
- export default tseslint.config(
6
- js.configs.recommended,
7
- ...tseslint.configs.recommended,
8
- eslintConfigPrettier,
9
- {
10
- rules: {
11
- '@typescript-eslint/no-unused-vars': 'warn',
12
- '@typescript-eslint/no-explicit-any': 'warn',
13
- 'no-console': 'off',
14
- },
15
- }
16
- );
1
+ import globals from 'globals'
2
+
3
+ export default [
4
+ {
5
+ files: ['**/*.js', '**/*.ts'],
6
+ languageOptions: {
7
+ ecmaVersion: 'latest',
8
+ sourceType: 'module',
9
+ globals: {
10
+ ...globals.node,
11
+ },
12
+ },
13
+ rules: {
14
+ 'no-console': 'off',
15
+ },
16
+ },
17
+ ]
@@ -1,6 +1,3 @@
1
- export default {
2
- '*.{ts,tsx,js,json}': [
3
- 'eslint --fix',
4
- 'prettier --write',
5
- ],
6
- };
1
+ export default {
2
+ '*.{ts,tsx,js,json}': ['eslint --fix', 'prettier --write'],
3
+ }
@@ -1,6 +1,6 @@
1
- export default {
2
- semi: false,
3
- singleQuote: true,
4
- trailingComma: 'all',
5
- printWidth: 100,
6
- };
1
+ export default {
2
+ semi: false,
3
+ singleQuote: true,
4
+ trailingComma: 'all',
5
+ printWidth: 100,
6
+ }
@@ -1,15 +1,15 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "commonjs",
5
- "outDir": "dist",
6
- "rootDir": "src",
7
- "esModuleInterop": true,
8
- "moduleResolution": "node",
9
- "resolveJsonModule": true,
10
- "forceConsistentCasingInFileNames": true,
11
- "strict": true,
12
- "skipLibCheck": true,
13
- },
14
- "include": ["src/**/*.ts"]
15
- }
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "outDir": "dist",
6
+ "rootDir": "src",
7
+ "esModuleInterop": true,
8
+ "moduleResolution": "node",
9
+ "resolveJsonModule": true,
10
+ "forceConsistentCasingInFileNames": true,
11
+ "strict": true,
12
+ "skipLibCheck": true
13
+ },
14
+ "include": ["src/**/*.ts"]
15
+ }