-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
72 lines (59 loc) · 1.84 KB
/
setup.js
File metadata and controls
72 lines (59 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* eslint no-console: 0 */
const fs = require('fs')
const path = require('path')
const del = require('del');
const readline = require('readline')
const pkg = require('./package.json')
const execSync = require('child_process').execSync
const dirName = path.basename(__dirname)
if (dirName === pkg.name) {
return
}
const envFile = path.resolve(__dirname, '.env')
if (fs.existsSync(envFile)) {
console.log('The project has already been initialized\n')
return
}
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
// Collect answers
const answers = {}
rl.question(`What is your project name? (${dirName}) `, (project) => {
answers.projectName = (project && project !== '')
? project
: dirName
rl.question(`Which WordPress version do you want? (latest) `, (version) => {
answers.wordpressVersion = (version && version !== '')
? version
: 'latest'
rl.close()
const newPkg = Object.assign({}, pkg, {
name: answers.projectName,
description: "",
version: "0.1.0",
author: ""
})
const envVariables = fs.readFileSync(`${envFile}.example`, 'utf8')
.replace('HOSTNAME=wordpress.development', `HOSTNAME=${answers.projectName}`)
.replace('WORDPRESS_VERSION=latest', `WORDPRESS_VERSION=${answers.wordpressVersion}`)
console.log('\nCreating the .env file')
fs.writeFileSync(envFile, envVariables, 'utf8')
fs.unlinkSync(`${envFile}.example`)
console.log('Updating package.json variables')
fs.writeFileSync(
path.resolve(__dirname, 'package.json'),
JSON.stringify(newPkg, null, 2),
'utf-8'
)
try {
del.sync('./.git')
execSync('git init')
} catch (e) {
console.log('Failed to recreate git repostiory:');
console.log(e.message);
}
console.log('Finished project initialization\n');
})
})