11/// <reference path="../node_modules/@types/fs-extra/index.d.ts" />
22
33import fs from "fs-extra" ;
4+
45import TaskInterface from "./TaskInterface" ;
56import Task from "./Task" ;
7+
68// import hostStub from "../stubs/server/apache/host";
79
810import ProjectDirectory from "./../questions/ProjectDirectory" ;
@@ -11,31 +13,39 @@ import VirtualHostDirectory from "./../questions/VirtualHostDirectory";
1113
1214class 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 ( ) ;
0 commit comments