Skip to content

Commit e7dd652

Browse files
committed
Adding logger
1 parent f66b86f commit e7dd652

File tree

10 files changed

+86
-27
lines changed

10 files changed

+86
-27
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"watch": "parcel watch packages/@servitor/cli/index.ts -d packages/@servitor/cli/bin --target node"
1616
},
1717
"devDependencies": {
18-
"@types/node": "13.9.8",
18+
"@types/node": "13.11.0",
1919
"lerna": "3.20.2"
2020
}
2121
}

packages/@servitor/cli/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import ConfigManager from "../config-manager";
66
import AddApacheVHostTask from "../tasks/AddApacheVHostTask"
77
import AddToHostTask from "../tasks/AddToHostTask"
88
import DownloadRepositoryTask from "../tasks/DownloadRepositoryTask"
9-
import chalk from "chalk";
9+
10+
import Logger from "../logger";
1011

1112
import Task from "../tasks/Task";
1213

@@ -42,20 +43,22 @@ class CLI {
4243
}
4344

4445
setup(){
45-
this.prompt().then(this.execute).catch((reject) => console.log(reject));
46+
this.prompt().then(() => this.execute()).catch((reject) => console.log(reject));
4647
}
4748

4849
async prompt(){
4950
for(const task of this._tasks) {
5051
task.setup();
51-
console.log(chalk.gbBlue.black('Task'),chalk.bgGreen.black(task.description));
52+
Logger.log(
53+
`Task ${task.description}`
54+
);
5255
await prompt(task.questions).then((answers) => {
5356
task.answers = answers;
5457
});
5558
}
56-
},
59+
}
5760

58-
execute(){
61+
async execute(){
5962
this._tasks.forEach(task => {
6063
task.execute()
6164
});

packages/@servitor/logger/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import chalk from "chalk";
2+
class Logger {
3+
4+
log(message){
5+
console.log(
6+
chalk.white(message),
7+
);
8+
}
9+
10+
success(message){
11+
console.log(
12+
chalk.green(message),
13+
);
14+
}
15+
warning(message){
16+
console.log(
17+
chalk.orange(message),
18+
);
19+
}
20+
21+
fail(message){
22+
console.log(
23+
chalk.red(message),
24+
);
25+
}
26+
27+
}
28+
29+
30+
export default new Logger;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@servitor/logger",
3+
"version": "0.1.0",
4+
"description": "Servitor Logger",
5+
"main": "index.ts",
6+
"dependencies": {
7+
"chalk": "3.0.0"
8+
},
9+
"devDependencies": {
10+
"typescript": "3.8.3"
11+
}
12+
}

packages/@servitor/questions/ProjectDirectory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ProjectDirectory extends Question {
66
super();
77
this.name = "directory.project";
88
this.type = "input";
9-
this.message = "Where should the project be created?";
9+
this.message = "What is the project directory?";
1010
}
1111

1212
}

packages/@servitor/tasks/AddApacheVHostTask.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/// <reference path="../node_modules/@types/fs-extra/index.d.ts" />
22

33
import fs from "fs-extra";
4+
45
import TaskInterface from "./TaskInterface";
56
import Task from "./Task";
7+
68
// import hostStub from "../stubs/server/apache/host";
79

810
import ProjectDirectory from "./../questions/ProjectDirectory";
@@ -11,31 +13,39 @@ import VirtualHostDirectory from "./../questions/VirtualHostDirectory";
1113

1214
class AddApacheVHostTask extends Task implements TaskInterface {
1315

14-
private readonly fileName = '';
15-
private readonly stub;
16-
private readonly virtualHostDirectory = '/etc/apache2/vhosts';
17-
1816
constructor(){
1917
super();
20-
this.description = "Create apache vhost file";
18+
this.description = "Create an apache vhost file";
2119
}
2220

2321
setup(): void {
2422
this.questions = [
25-
new ProjectUrlQuestion,
2623
new ProjectDirectory,
24+
new ProjectUrlQuestion,
2725
new VirtualHostDirectory,
2826
];
2927
}
3028

3129
execute(): Promise<Function> {
32-
this.fileName = `${this.answers.url}.conf`;
30+
const fileName = `${this.answers.url}.conf`;
3331
return new Promise((resolve, reject) => {
3432
try {
35-
fs.accessSync(this.virtualHostDirectory, fs.constants.R_OK | fs.constants.W_OK);
33+
fs.accessSync(this.answers.directory.vhost, fs.constants.R_OK | fs.constants.W_OK);
3634
fs.appendFile(
37-
this.fileName,
38-
this.stub.compiled,
35+
this.answers.directory.vhost + '/' + fileName,
36+
`
37+
<VirtualHost *:80>
38+
ServerAdmin webmaster@localhost
39+
ServerAlias ${this.answers.url}
40+
41+
DocumentRoot ${this.answers.directory.project}
42+
43+
<Directory "${this.answers.directory.project}">
44+
Options Indexes FollowSymLinks MultiViews
45+
AllowOverride All
46+
</Directory>
47+
</VirtualHost>
48+
`,
3949
error => {
4050
if (error) return reject(error);
4151
resolve();

packages/@servitor/tasks/AddToHostTask.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/// <reference path="../node_modules/@types/fs-extra/index.d.ts" />
22

33
import fs from "fs-extra";
4+
5+
import Logger from "../logger";
6+
47
import TaskInterface from "./TaskInterface";
58
import Task from "./Task";
69

@@ -26,14 +29,14 @@ class AddToHostTask extends Task implements TaskInterface {
2629
try {
2730
fs.accessSync(this.answers.file.hostFile, fs.constants.R_OK | fs.constants.W_OK);
2831
fs.appendFile(
29-
this.hostFile,
30-
`127.0.0.1 ${this.answers.url}`,
32+
this.answers.file.hostFile,
33+
`127.0.0.1 ${this.answers.url}\n`,
3134
error => {
3235
if (error) return reject(error);
36+
Logger.success(`The URL was successfully added to the host file`);
3337
resolve();
3438
}
3539
);
36-
3740
} catch (err) {
3841
return reject(err);
3942
}

packages/@servitor/tasks/Task.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Question from "./../questions/Question";
2+
23
abstract class Task{
34

45
protected answers;

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -896,10 +896,10 @@
896896
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.7.7.tgz#1628e6461ba8cc9b53196dfeaeec7b07fa6eea99"
897897
integrity sha512-Uo4chgKbnPNlxQwoFmYIwctkQVkMMmsAoGGU4JKwLuvBefF0pCq4FybNSnfkfRCpC7ZW7kttcC/TrRtAJsvGtg==
898898

899-
"@types/node@13.9.8":
900-
version "13.9.8"
901-
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.9.8.tgz#09976420fc80a7a00bf40680c63815ed8c7616f4"
902-
integrity sha512-1WgO8hsyHynlx7nhP1kr0OFzsgKz5XDQL+Lfc3b1Q3qIln/n8cKD4m09NJ0+P1Rq7Zgnc7N0+SsMnoD1rEb0kA==
899+
"@types/node@13.11.0":
900+
version "13.11.0"
901+
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.11.0.tgz#390ea202539c61c8fa6ba4428b57e05bc36dc47b"
902+
integrity sha512-uM4mnmsIIPK/yeO+42F2RQhGUIs39K2RFmugcJANppXe6J1nvH87PvzPZYpza7Xhhs8Yn9yIAVdLZ84z61+0xQ==
903903

904904
"@zkochan/cmd-shim@^3.1.0":
905905
version "3.1.0"

0 commit comments

Comments
 (0)