This repository has been archived by the owner on Mar 29, 2024. It is now read-only.
/
index.js
83 lines (76 loc) · 2.16 KB
/
index.js
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
73
74
75
76
77
78
79
80
81
82
83
import fs from 'fs'
import { promisify } from 'util'
import enquirer from 'enquirer'
import degit from 'degit'
const readFile = promisify(fs.readFile)
const writeFile = promisify(fs.writeFile)
export const init = async () => {
const response = await enquirer.prompt([
{
type: 'input',
name: 'humanProjectName',
message: 'What is the name of your project? (e.g. Svelte)'
},
{
type: 'input',
name: 'projectName',
message: 'What is the npm project name? (e.g. svelte-js)'
},
{
type: 'input',
name: 'repository',
message: 'What is your repository (<username>/<repo>)? (e.g. FullHuman/tosin)'
},
{
type: 'input',
name: 'developerName',
message: 'What is your name (used for the licence)?'
},
{
type: 'input',
name: 'email',
message: 'What is the email to be use for the code of conduct?'
}
])
// clone the template library
const emitter = degit('FullHuman/tosin-template-library', {
cache: false,
force: true,
verbose: false
})
await emitter.clone('.')
const replaceSets = [
['{% project name %}', response.projectName],
['{% human project name %}', response.humanProjectName],
['{% developer name %}', response.developerName],
['{% email %}', response.email],
['{% repository %}', response.repository],
['{% lowercase repository %}', response.repository.toLowerCase()]
]
const filesToModify = [
'.github/ISSUE_TEMPLATE/BUG_REPORT.md',
'.github/CODE_OF_CONDUCT.md',
'.github/PULL_REQUEST_TEMPLATE.md',
'scripts/deploy_docs.sh',
'CONTRIBUTING.md',
'LICENSE',
'package.json',
'README.md',
'rollup.config.js',
// docs
'docs/.vuepress/config.js',
'docs/Guide.md',
'docs/README.md'
]
for (const file of filesToModify) {
await replaceInFile(file, replaceSets)
}
}
export const replaceInFile = async (filePath, replaceSets) => {
const fileContent = await readFile(filePath, 'utf-8')
let result = fileContent
replaceSets.forEach(([toReplace, value]) => {
result = result.replace(new RegExp(toReplace, 'g'), value)
})
await writeFile(filePath, result, 'utf8')
}