Skip to content

Commit

Permalink
Adding logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreshnik committed Apr 6, 2020
1 parent f66b86f commit e7dd652
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 27 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"watch": "parcel watch packages/@servitor/cli/index.ts -d packages/@servitor/cli/bin --target node"
},
"devDependencies": {
"@types/node": "13.9.8",
"@types/node": "13.11.0",
"lerna": "3.20.2"
}
}
13 changes: 8 additions & 5 deletions packages/@servitor/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import ConfigManager from "../config-manager";
import AddApacheVHostTask from "../tasks/AddApacheVHostTask"
import AddToHostTask from "../tasks/AddToHostTask"
import DownloadRepositoryTask from "../tasks/DownloadRepositoryTask"
import chalk from "chalk";

import Logger from "../logger";

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

Expand Down Expand Up @@ -42,20 +43,22 @@ class CLI {
}

setup(){
this.prompt().then(this.execute).catch((reject) => console.log(reject));
this.prompt().then(() => this.execute()).catch((reject) => console.log(reject));
}

async prompt(){
for(const task of this._tasks) {
task.setup();
console.log(chalk.gbBlue.black('Task'),chalk.bgGreen.black(task.description));
Logger.log(
`Task ${task.description}`
);
await prompt(task.questions).then((answers) => {
task.answers = answers;
});
}
},
}

execute(){
async execute(){
this._tasks.forEach(task => {
task.execute()
});
Expand Down
30 changes: 30 additions & 0 deletions packages/@servitor/logger/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import chalk from "chalk";
class Logger {

log(message){
console.log(
chalk.white(message),
);
}

success(message){
console.log(
chalk.green(message),
);
}
warning(message){
console.log(
chalk.orange(message),
);
}

fail(message){
console.log(
chalk.red(message),
);
}

}


export default new Logger;
12 changes: 12 additions & 0 deletions packages/@servitor/logger/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@servitor/logger",
"version": "0.1.0",
"description": "Servitor Logger",
"main": "index.ts",
"dependencies": {
"chalk": "3.0.0"
},
"devDependencies": {
"typescript": "3.8.3"
}
}
2 changes: 1 addition & 1 deletion packages/@servitor/questions/ProjectDirectory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ProjectDirectory extends Question {
super();
this.name = "directory.project";
this.type = "input";
this.message = "Where should the project be created?";
this.message = "What is the project directory?";
}

}
Expand Down
30 changes: 20 additions & 10 deletions packages/@servitor/tasks/AddApacheVHostTask.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/// <reference path="../node_modules/@types/fs-extra/index.d.ts" />

import fs from "fs-extra";

import TaskInterface from "./TaskInterface";
import Task from "./Task";

// import hostStub from "../stubs/server/apache/host";

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

class AddApacheVHostTask extends Task implements TaskInterface {

private readonly fileName = '';
private readonly stub;
private readonly virtualHostDirectory = '/etc/apache2/vhosts';

constructor(){
super();
this.description = "Create apache vhost file";
this.description = "Create an apache vhost file";
}

setup(): void {
this.questions = [
new ProjectUrlQuestion,
new ProjectDirectory,
new ProjectUrlQuestion,
new VirtualHostDirectory,
];
}

execute(): Promise<Function> {
this.fileName = `${this.answers.url}.conf`;
const fileName = `${this.answers.url}.conf`;
return new Promise((resolve, reject) => {
try {
fs.accessSync(this.virtualHostDirectory, fs.constants.R_OK | fs.constants.W_OK);
fs.accessSync(this.answers.directory.vhost, fs.constants.R_OK | fs.constants.W_OK);
fs.appendFile(
this.fileName,
this.stub.compiled,
this.answers.directory.vhost + '/' + fileName,
`
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerAlias ${this.answers.url}
DocumentRoot ${this.answers.directory.project}
<Directory "${this.answers.directory.project}">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
</VirtualHost>
`,
error => {
if (error) return reject(error);
resolve();
Expand Down
9 changes: 6 additions & 3 deletions packages/@servitor/tasks/AddToHostTask.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/// <reference path="../node_modules/@types/fs-extra/index.d.ts" />

import fs from "fs-extra";

import Logger from "../logger";

import TaskInterface from "./TaskInterface";
import Task from "./Task";

Expand All @@ -26,14 +29,14 @@ class AddToHostTask extends Task implements TaskInterface {
try {
fs.accessSync(this.answers.file.hostFile, fs.constants.R_OK | fs.constants.W_OK);
fs.appendFile(
this.hostFile,
`127.0.0.1 ${this.answers.url}`,
this.answers.file.hostFile,
`127.0.0.1 ${this.answers.url}\n`,
error => {
if (error) return reject(error);
Logger.success(`The URL was successfully added to the host file`);
resolve();
}
);

} catch (err) {
return reject(err);
}
Expand Down
1 change: 1 addition & 0 deletions packages/@servitor/tasks/Task.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Question from "./../questions/Question";

abstract class Task{

protected answers;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -896,10 +896,10 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.7.7.tgz#1628e6461ba8cc9b53196dfeaeec7b07fa6eea99"
integrity sha512-Uo4chgKbnPNlxQwoFmYIwctkQVkMMmsAoGGU4JKwLuvBefF0pCq4FybNSnfkfRCpC7ZW7kttcC/TrRtAJsvGtg==

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

"@zkochan/cmd-shim@^3.1.0":
version "3.1.0"
Expand Down

0 comments on commit e7dd652

Please sign in to comment.