Skip to content

Commit d636cb9

Browse files
committed
Inserting log in create project
1 parent cb4bf8b commit d636cb9

8 files changed

Lines changed: 55 additions & 41 deletions

src/generators/ControllerGenerator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const createController = (name: string) => {
2020
const contentFile = fs.readFileSync(source).toString();
2121
fs.writeFileSync(target, replaceMask(contentFile, { name }));
2222

23-
Log.Instance.successHeap(`The controller ${name} created.`);
23+
Log.Instance.successHeap(`The ${name} controller was created.`);
2424
Log.Instance.info(`Path: ${target}\n\n`);
2525
} catch (err) {
2626
Log.Instance.exception(err);

src/generators/ModelGenerator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const createModel = (name: string) => {
1919
const contentFile = fs.readFileSync(source).toString();
2020
fs.writeFileSync(target, replaceMask(contentFile, { name }));
2121

22-
Log.Instance.successHeap(`The model ${name} created.`);
22+
Log.Instance.successHeap(`The ${name} model was created.`);
2323
Log.Instance.info(`Path: ${target}\n\n`);
2424
} catch (err) {
2525
Log.Instance.exception(err);

src/generators/ProjectGenerator.ts

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,45 @@ import copyFolder from '../utils/copyFolder';
66
import createPackageJson from '../stages/CreatePackageJson';
77
import installDependencies from '../stages/InstallDependencies';
88
import initializeGit from '../stages/InitializeGit';
9-
10-
let projectName;
9+
import Log from '../Log';
10+
11+
const createProject = (name: string) => {
12+
if (name) {
13+
Log.Instance.infoHeap(`Creating the project`);
14+
15+
const source = path.join(__dirname, '/../../templates/project');
16+
const target = path.join(process.cwd(), name);
17+
18+
try {
19+
Log.Instance.infoHeap(`Copying files`);
20+
fs.mkdirSync(name);
21+
22+
copyFolder(source, target);
23+
fs.renameSync(
24+
path.join(target, 'gitignore'),
25+
path.join(target, '.gitignore')
26+
);
27+
28+
createPackageJson(target, name);
29+
installDependencies(target);
30+
initializeGit(name);
31+
32+
Log.Instance.successHeap(`The ${name} project was created.`);
33+
Log.Instance.info(`Path: ${target}\n\n`);
34+
} catch (err) {
35+
Log.Instance.exception(err);
36+
}
37+
} else {
38+
Log.Instance.errorHeap(`Specify the name project.`);
39+
Log.Instance.info(
40+
`For example: recife-cli project my-project-name\nRun --help for more information`
41+
);
42+
}
43+
};
1144

1245
commander
1346
.name(`recife-cli project`)
1447
.arguments('<project-name>')
15-
.action(name => (projectName = name))
48+
.action(name => createProject(name))
1649
.allowUnknownOption(false)
1750
.parse(process.argv);
18-
19-
if (projectName) {
20-
const source = path.join(__dirname, '/../../templates/project');
21-
const target = path.join(process.cwd(), projectName);
22-
23-
try {
24-
fs.mkdirSync(projectName);
25-
26-
copyFolder(source, target);
27-
fs.renameSync(
28-
path.join(target, 'gitignore'),
29-
path.join(target, '.gitignore')
30-
);
31-
32-
createPackageJson(target, projectName);
33-
installDependencies(target);
34-
initializeGit(projectName);
35-
36-
console.info(`\x1b[36mCreating the project ${projectName}.`, '\x1b[0m');
37-
console.info(`Path: ${target}`, '\x1b[0m\n');
38-
} catch (err) {
39-
console.log(`\x1b[31m${err}\x1b[0m`);
40-
}
41-
} else {
42-
console.error('\x1b[31mSpecify the name project.', '\x1b[0m');
43-
console.log(` For example: recife-cli project my-project-name`);
44-
console.log(` Run --help for more information\n`);
45-
}

src/generators/ScalarGenerator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const createScalar = (name: string) => {
2525
})
2626
);
2727

28-
Log.Instance.successHeap(`The scalar ${name} created.`);
28+
Log.Instance.successHeap(`The ${name} scalar was created.`);
2929
Log.Instance.info(`Path: ${target}\n\n`);
3030
} catch (err) {
3131
Log.Instance.exception(err);

src/generators/ValidatorGenerator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const createValidator = (name: string) => {
1919
const contentFile = fs.readFileSync(source).toString();
2020
fs.writeFileSync(target, replaceMask(contentFile, { name }));
2121

22-
Log.Instance.successHeap(`The validator ${name} created.`);
22+
Log.Instance.successHeap(`The ${name} validator was created.`);
2323
Log.Instance.info(`Path: ${target}\n\n`);
2424
} catch (err) {
2525
Log.Instance.exception(err);

src/stages/CreatePackageJson.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import fs from 'fs';
22
import path from 'path';
3+
import Log from '../Log';
34

45
const createPackageJson = (target: string, name: string) => {
6+
Log.Instance.infoHeap(`Creating file package.json`);
7+
58
const basePackageJson = {
69
name: name,
710
version: '0.0.1',

src/stages/InitializeGit.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { spawnSync } from 'child_process';
2+
import Log from '../Log';
23

34
const initializeGit = (projectName: string) => {
5+
Log.Instance.infoHeap(`Starting the git`);
6+
47
const originalDirectory = process.cwd();
58

69
try {
710
process.chdir(projectName);
811

9-
spawnSync('git', ['init'], { stdio: 'inherit' });
10-
spawnSync('git', ['add', '*'], { stdio: 'inherit' });
11-
spawnSync('git', ['commit', '-m', 'First Commit'], { stdio: 'inherit' });
12+
spawnSync('git', ['init'], { stdio: 'ignore' });
13+
spawnSync('git', ['add', '*'], { stdio: 'ignore' });
14+
spawnSync('git', ['commit', '-m', 'First Commit'], { stdio: 'ignore' });
1215
} catch (err) {
13-
console.log(`\x1b[31m${err}\x1b[0m`);
16+
Log.Instance.exception(err);
1417
}
1518

1619
process.chdir(originalDirectory);

src/stages/InstallDependencies.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { spawnSync } from 'child_process';
2+
import Log from '../Log';
23

34
const yarnInstalled = () => {
45
try {
@@ -10,15 +11,17 @@ const yarnInstalled = () => {
1011
};
1112

1213
const installDependencies = (target: string) => {
14+
Log.Instance.infoHeap(`Installing dependencies`);
15+
1316
const originalDirectory = process.cwd();
1417

1518
try {
1619
process.chdir(target);
1720

1821
if (yarnInstalled()) {
19-
spawnSync('yarnpkg', ['install'], { stdio: 'inherit' });
22+
spawnSync('yarnpkg', ['install'], { stdio: 'ignore' });
2023
} else {
21-
spawnSync('npm', ['install'], { stdio: 'inherit' });
24+
spawnSync('npm', ['install'], { stdio: 'ignore' });
2225
}
2326
} catch (err) {
2427
console.log(`\x1b[31m${err}\x1b[0m`);

0 commit comments

Comments
 (0)