Skip to content

Commit caca674

Browse files
Merge pull request #1 from marchintosh94/dev
Console improvements and fix on project builder
2 parents 53d5e59 + 31e28bb commit caca674

File tree

5 files changed

+68
-45
lines changed

5 files changed

+68
-45
lines changed

package-lock.json

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "@marchintosh94/create-node-ts",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "NodeJS TypeScript projects generator by @marchintosh",
55
"main": "dist/index.js",
66
"files": [
77
"dist"
88
],
99
"scripts": {
10-
"build": "rm -rf dist && tsc",
10+
"build": "rm -rf dist && tsc && cp -rv ./template dist/",
1111
"start": "ts-node src/index.ts"
1212
},
1313
"bin": {
@@ -26,6 +26,7 @@
2626
},
2727
"dependencies": {
2828
"@inquirer/prompts": "^5.0.1",
29-
"asciiart-logo": "^0.2.7"
29+
"asciiart-logo": "^0.2.7",
30+
"chalk": "^4.1.2"
3031
}
3132
}

src/index.ts

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { getPackageJson } from './packageJson'
55
import { tsconfigJson } from './tsconfigJson'
66
import * as fs from 'fs'
77
import { execSync } from 'child_process'
8+
import * as path from 'path'
9+
import * as chalk from 'chalk'
810

911
const wantsCreateNewFolder = async () =>
1012
await select({
@@ -68,51 +70,71 @@ const main = async () => {
6870
console.log('✅ tsconfig.json created')
6971
fs.mkdirSync('src')
7072
console.log('✅ src folder created')
71-
fs.writeFileSync('src/index.ts', '')
73+
fs.writeFileSync('src/index.ts', 'console.log("Hello NodeTS! 🚀")')
7274
console.log('✅ src/index.ts created')
75+
console.log('')
7376

7477
//install dev dependencies
7578
console.log('Installing dev dependencies...')
76-
execSync('npm install --save-dev typescript', { stdio: 'inherit' })
77-
console.log('✅ typescript installed')
78-
execSync('npm install --save-dev ts-node', { stdio: 'inherit' })
79-
console.log('✅ ts-node installed')
80-
execSync('npm install --save-dev jest', { stdio: 'inherit' })
81-
console.log('✅ jest installed')
82-
execSync('npm install --save-dev @types/jest', { stdio: 'inherit' })
83-
console.log('✅ @types/jest installed')
84-
execSync('npm install --save-dev @types/node', { stdio: 'inherit' })
85-
console.log('✅ @types/node installed')
86-
execSync('npm install --save-dev ts-jest', { stdio: 'inherit' })
87-
console.log('✅ ts-jest installed')
88-
execSync('npm install --save-dev husky', { stdio: 'inherit' })
89-
console.log('✅ husky installed')
90-
execSync('npm install --save-dev lint-staged', { stdio: 'inherit' })
91-
console.log('✅ lint-staged installed')
92-
console.log('✅ All dev dependencies installed')
79+
const devDependencies = [
80+
'typescript',
81+
'jest',
82+
'ts-jest',
83+
'husky',
84+
'lint-staged',
85+
'@types/jest',
86+
'@types/node',
87+
'ts-node'
88+
]
89+
execSync(`npm install --save-dev -s ${devDependencies.join(' ')}`, {
90+
stdio: 'inherit'
91+
})
92+
console.log(`✅ ${chalk.greenBright('typescript')} installed`)
93+
console.log(`✅ ${chalk.greenBright('ts-node')} installed`)
94+
console.log(`✅ ${chalk.greenBright('jest')} installed`)
95+
console.log(`✅ ${chalk.greenBright('@types/jest')} installed`)
96+
console.log(`✅ ${chalk.greenBright('@types/node')} installed`)
97+
console.log(`✅ ${chalk.greenBright('ts-jest')} installed`)
98+
console.log(`✅ ${chalk.greenBright('husky')} installed`)
99+
console.log(`✅ ${chalk.greenBright('lint-staged')} installed`)
100+
console.log(`✅ All dev dependencies installed`)
101+
console.log('')
93102

94103
//copy all configuration files from template folder
95104
console.log('Copying configuration files...')
96-
fs.copyFileSync('../template/jest.config.ts', 'jest.config.ts')
97-
console.log('✅ jest.config.ts copied')
98-
fs.copyFileSync('../template/.gitignore', '.gitignore')
99-
console.log('✅ .gitignore copied')
100-
fs.copyFileSync('../template/.prettierrc', '.prettierrc')
101-
console.log('✅ .prettierrc copied')
102-
fs.copyFileSync('../template/.prettierignore', '.prettierignore')
103-
console.log('✅ .prettierignore copied')
105+
const templatePath = path.join(__dirname, 'template')
106+
const files = fs.readdirSync(templatePath)
107+
files.forEach((file) => {
108+
fs.copyFileSync(path.join(templatePath, file), file)
109+
console.log(`✅ ${file} copied`)
110+
})
111+
112+
//init git
113+
console.log('')
114+
console.log('Initializing git...')
115+
const gitIgnore = [
116+
'node_modules',
117+
'dist',
118+
'.DS_Store',
119+
'.env.local',
120+
'.env.development.local',
121+
'.env.test.local',
122+
'.env.production.local',
123+
'coverage',
124+
'build'
125+
]
126+
fs.writeFileSync('.gitignore', gitIgnore.join('\n'))
127+
execSync('git init -b main', { stdio: 'inherit' })
128+
console.log('✅ git initialized')
104129

105130
//init and config husky and lint-staged
131+
console.log('')
106132
console.log('Configuring husky...')
107133
execSync('npx husky init', { stdio: 'inherit' })
108-
execSync("echo 'npm test' >> .husky/pre-commit", { stdio: 'inherit' })
109-
execSync("echo 'npx lint-staged' >> .husky/pre-commit", { stdio: 'inherit' })
134+
execSync("echo npx lint-staged >> .husky/pre-commit", { stdio: 'inherit' })
110135
console.log('✅ husky configured')
111136

112-
//init git
113-
console.log('Initializing git...')
114-
execSync('git init -b main', { stdio: 'inherit' })
115-
137+
console.log('')
116138
console.log('✅ All done!')
117139
console.log('Happy coding! 🚀')
118140
}

template/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
"module": "commonjs",
55
"outDir": "./dist",
66
"strict": true,
7-
"typeRoots": ["./node_modules/@types", "./src/"],
7+
"typeRoots": ["./node_modules/@types", "./src/**/*.d.ts"],
88
"skipLibCheck": true
99
},
1010
"include": [
1111
"./src/**/*.ts",
1212
"./src/**/*.d.ts",
1313
],
1414
"exclude": [
15-
"node_modules"
15+
"node_modules",
16+
"template"
1617
]
1718
}

0 commit comments

Comments
 (0)