Skip to content

Commit

Permalink
Merge pull request #1 from marchintosh94/dev
Browse files Browse the repository at this point in the history
Console improvements and fix on project builder
  • Loading branch information
marchintosh94 authored May 15, 2024
2 parents 53d5e59 + 31e28bb commit caca674
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 45 deletions.
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"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": [
"dist"
],
"scripts": {
"build": "rm -rf dist && tsc",
"build": "rm -rf dist && tsc && cp -rv ./template dist/",
"start": "ts-node src/index.ts"
},
"bin": {
Expand All @@ -26,6 +26,7 @@
},
"dependencies": {
"@inquirer/prompts": "^5.0.1",
"asciiart-logo": "^0.2.7"
"asciiart-logo": "^0.2.7",
"chalk": "^4.1.2"
}
}
86 changes: 54 additions & 32 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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! 🚀')
}
Expand Down
2 changes: 0 additions & 2 deletions template/.gitignore

This file was deleted.

5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
"module": "commonjs",
"outDir": "./dist",
"strict": true,
"typeRoots": ["./node_modules/@types", "./src/"],
"typeRoots": ["./node_modules/@types", "./src/**/*.d.ts"],
"skipLibCheck": true
},
"include": [
"./src/**/*.ts",
"./src/**/*.d.ts",
],
"exclude": [
"node_modules"
"node_modules",
"template"
]
}

0 comments on commit caca674

Please sign in to comment.