Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit d411bf2

Browse files
committed
fix: exit process with appropriate exit codes
1 parent 330a47a commit d411bf2

File tree

2 files changed

+55
-48
lines changed

2 files changed

+55
-48
lines changed

bin/run.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ const argv = process.argv.slice(2)
77
if (argv.length > 0) {
88
runTasks(argv[0])
99
} else {
10-
console.log(bgRed('Error'))
11-
console.log(red('Please specify project name'))
10+
console.error(bgRed('Error'))
11+
console.error(red('Please specify project name'))
1212
}

index.ts

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* file that was distributed with this source code.
88
*/
99

10-
import { ensureDirSync } from 'fs-extra'
1110
import { bgRed, red } from 'kleur'
11+
import { ensureDirSync } from 'fs-extra'
1212
import { isAbsolute, join, basename } from 'path'
1313
import { Application } from '@poppinss/application'
1414
import { executeInstructions, isEmptyDir } from '@adonisjs/sink'
@@ -38,60 +38,67 @@ export async function runTasks (projectRoot: string) {
3838
*/
3939
const isEmpty = isEmptyDir(absPath)
4040
if (!isEmpty) {
41-
console.log(bgRed(`Error`))
42-
console.log(red(`- Cannot overwrite existing contents in {${projectRoot}} directory`))
43-
console.log(red(`- Make sure that {${projectRoot}} directory is empty`))
44-
return
41+
console.error(bgRed(`Error`))
42+
console.error(red(`- Cannot overwrite existing contents in {${projectRoot}} directory`))
43+
console.error(red(`- Make sure that {${projectRoot}} directory is empty`))
44+
process.exit(1)
4545
}
4646

47-
/**
48-
* Pulling the project name from the project root path
49-
*/
50-
const projectName = basename(absPath)
47+
try {
48+
/**
49+
* Pulling the project name from the project root path
50+
*/
51+
const projectName = basename(absPath)
5152

52-
/**
53-
* Creating the `.adonisrc.json` file
54-
*/
55-
createRcFile(absPath, application)
53+
/**
54+
* Creating the `.adonisrc.json` file
55+
*/
56+
createRcFile(absPath, application)
5657

57-
/**
58-
* Creating the `.env` file
59-
*/
60-
createEnvFile(absPath)
58+
/**
59+
* Creating the `.env` file
60+
*/
61+
createEnvFile(absPath)
6162

62-
/**
63-
* Creating the `.gitignore` file
64-
*/
65-
createGitIgnore(absPath)
63+
/**
64+
* Creating the `.gitignore` file
65+
*/
66+
createGitIgnore(absPath)
6667

67-
/**
68-
* Creating the `.editorconfig` file
69-
*/
70-
createEditorConfig(absPath)
68+
/**
69+
* Creating the `.editorconfig` file
70+
*/
71+
createEditorConfig(absPath)
7172

72-
/**
73-
* Creating `tsconfig.json` file
74-
*/
75-
createTsConfig(absPath)
73+
/**
74+
* Creating `tsconfig.json` file
75+
*/
76+
createTsConfig(absPath)
7677

77-
/**
78-
* Creating `tslint.json` file
79-
*/
80-
createTsLint(absPath)
78+
/**
79+
* Creating `tslint.json` file
80+
*/
81+
createTsLint(absPath)
8182

82-
/**
83-
* Creating `package.json` file and install required dependencies
84-
*/
85-
createPackageFile(absPath, projectName)
83+
/**
84+
* Creating `package.json` file and install required dependencies
85+
*/
86+
createPackageFile(absPath, projectName)
8687

87-
/**
88-
* Copy application templates
89-
*/
90-
copyTemplates(absPath)
88+
/**
89+
* Copy application templates
90+
*/
91+
copyTemplates(absPath)
9192

92-
/**
93-
* Executing instructions from `@adonisjs/core`. Please check the package
94-
* repo to see the actions executed there
95-
*/
96-
await executeInstructions('@adonisjs/core', absPath, application)
93+
/**
94+
* Executing instructions from `@adonisjs/core` and `@adonisjs/bodyparser`.
95+
* Please check the packages repos to see the actions executed there.
96+
*/
97+
await executeInstructions('@adonisjs/core', absPath, application)
98+
await executeInstructions('@adonisjs/bodyparser', absPath, application)
99+
process.exit(0)
100+
} catch (error) {
101+
console.error(error)
102+
process.exit(1)
103+
}
97104
}

0 commit comments

Comments
 (0)