From 254ef12df74973b788876efa6b4434186e606426 Mon Sep 17 00:00:00 2001 From: Marco Baratto Date: Thu, 16 May 2024 00:06:50 +0200 Subject: [PATCH 1/2] Fix on the process that copies files from template folder - minor improvement on console outputs - fix on the order of the installation and configuration of git and husky --- package-lock.json | 13 +++---- package.json | 5 +-- src/index.ts | 86 ++++++++++++++++++++++++++++----------------- template/.gitignore | 2 -- tsconfig.json | 5 +-- 5 files changed, 67 insertions(+), 44 deletions(-) delete mode 100644 template/.gitignore diff --git a/package-lock.json b/package-lock.json index e79e321..d873b0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,17 @@ { - "name": "create-node-ts", - "version": "1.0.0", + "name": "@marchintosh94/create-node-ts", + "version": "1.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "create-node-ts", - "version": "1.0.0", - "license": "ISC", + "name": "@marchintosh94/create-node-ts", + "version": "1.0.1", + "license": "MIT", "dependencies": { "@inquirer/prompts": "^5.0.1", - "asciiart-logo": "^0.2.7" + "asciiart-logo": "^0.2.7", + "chalk": "^4.1.2" }, "bin": { "create-node-ts": "dist/index.js" diff --git a/package.json b/package.json index b419313..af3238d 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "dist" ], "scripts": { - "build": "rm -rf dist && tsc", + "build": "rm -rf dist && tsc && cp -rv ./template dist/", "start": "ts-node src/index.ts" }, "bin": { @@ -26,6 +26,7 @@ }, "dependencies": { "@inquirer/prompts": "^5.0.1", - "asciiart-logo": "^0.2.7" + "asciiart-logo": "^0.2.7", + "chalk": "^4.1.2" } } diff --git a/src/index.ts b/src/index.ts index 314549a..a6e9079 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,8 @@ import { getPackageJson } from './packageJson' import { tsconfigJson } from './tsconfigJson' import * as fs from 'fs' import { execSync } from 'child_process' +import * as path from 'path' +import * as chalk from 'chalk' const wantsCreateNewFolder = async () => await select({ @@ -68,51 +70,71 @@ const main = async () => { console.log('✅ tsconfig.json created') fs.mkdirSync('src') console.log('✅ src folder created') - fs.writeFileSync('src/index.ts', '') + fs.writeFileSync('src/index.ts', 'console.log("Hello NodeTS! 🚀")') console.log('✅ src/index.ts created') + console.log('') //install dev dependencies console.log('Installing dev dependencies...') - execSync('npm install --save-dev typescript', { stdio: 'inherit' }) - console.log('✅ typescript installed') - execSync('npm install --save-dev ts-node', { stdio: 'inherit' }) - console.log('✅ ts-node installed') - execSync('npm install --save-dev jest', { stdio: 'inherit' }) - console.log('✅ jest installed') - execSync('npm install --save-dev @types/jest', { stdio: 'inherit' }) - console.log('✅ @types/jest installed') - execSync('npm install --save-dev @types/node', { stdio: 'inherit' }) - console.log('✅ @types/node installed') - execSync('npm install --save-dev ts-jest', { stdio: 'inherit' }) - console.log('✅ ts-jest installed') - execSync('npm install --save-dev husky', { stdio: 'inherit' }) - console.log('✅ husky installed') - execSync('npm install --save-dev lint-staged', { stdio: 'inherit' }) - console.log('✅ lint-staged installed') - console.log('✅ All dev dependencies installed') + const devDependencies = [ + 'typescript', + 'jest', + 'ts-jest', + 'husky', + 'lint-staged', + '@types/jest', + '@types/node', + 'ts-node' + ] + execSync(`npm install --save-dev -s ${devDependencies.join(' ')}`, { + stdio: 'inherit' + }) + console.log(`✅ ${chalk.greenBright('typescript')} installed`) + console.log(`✅ ${chalk.greenBright('ts-node')} installed`) + console.log(`✅ ${chalk.greenBright('jest')} installed`) + console.log(`✅ ${chalk.greenBright('@types/jest')} installed`) + console.log(`✅ ${chalk.greenBright('@types/node')} installed`) + console.log(`✅ ${chalk.greenBright('ts-jest')} installed`) + console.log(`✅ ${chalk.greenBright('husky')} installed`) + console.log(`✅ ${chalk.greenBright('lint-staged')} installed`) + console.log(`✅ All dev dependencies installed`) + console.log('') //copy all configuration files from template folder console.log('Copying configuration files...') - fs.copyFileSync('../template/jest.config.ts', 'jest.config.ts') - console.log('✅ jest.config.ts copied') - fs.copyFileSync('../template/.gitignore', '.gitignore') - console.log('✅ .gitignore copied') - fs.copyFileSync('../template/.prettierrc', '.prettierrc') - console.log('✅ .prettierrc copied') - fs.copyFileSync('../template/.prettierignore', '.prettierignore') - console.log('✅ .prettierignore copied') + const templatePath = path.join(__dirname, 'template') + const files = fs.readdirSync(templatePath) + files.forEach((file) => { + fs.copyFileSync(path.join(templatePath, file), file) + console.log(`✅ ${file} copied`) + }) + + //init git + console.log('') + console.log('Initializing git...') + const gitIgnore = [ + 'node_modules', + 'dist', + '.DS_Store', + '.env.local', + '.env.development.local', + '.env.test.local', + '.env.production.local', + 'coverage', + 'build' + ] + fs.writeFileSync('.gitignore', gitIgnore.join('\n')) + execSync('git init -b main', { stdio: 'inherit' }) + console.log('✅ git initialized') //init and config husky and lint-staged + console.log('') console.log('Configuring husky...') execSync('npx husky init', { stdio: 'inherit' }) - execSync("echo 'npm test' >> .husky/pre-commit", { stdio: 'inherit' }) - execSync("echo 'npx lint-staged' >> .husky/pre-commit", { stdio: 'inherit' }) + execSync("echo npx lint-staged >> .husky/pre-commit", { stdio: 'inherit' }) console.log('✅ husky configured') - //init git - console.log('Initializing git...') - execSync('git init -b main', { stdio: 'inherit' }) - + console.log('') console.log('✅ All done!') console.log('Happy coding! 🚀') } diff --git a/template/.gitignore b/template/.gitignore deleted file mode 100644 index 7cafbdb..0000000 --- a/template/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -coverage -node_modules \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 2676cb1..1e2e385 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ "module": "commonjs", "outDir": "./dist", "strict": true, - "typeRoots": ["./node_modules/@types", "./src/"], + "typeRoots": ["./node_modules/@types", "./src/**/*.d.ts"], "skipLibCheck": true }, "include": [ @@ -12,6 +12,7 @@ "./src/**/*.d.ts", ], "exclude": [ - "node_modules" + "node_modules", + "template" ] } \ No newline at end of file From 31e28bb09063f8fa303d746110246034043f0dbe Mon Sep 17 00:00:00 2001 From: Marco Baratto Date: Thu, 16 May 2024 00:11:43 +0200 Subject: [PATCH 2/2] Updated version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index af3238d..bbb6a7c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@marchintosh94/create-node-ts", - "version": "1.0.1", + "version": "1.0.2", "description": "NodeJS TypeScript projects generator by @marchintosh", "main": "dist/index.js", "files": [