forked from lirantal/create-node-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaofile.js
More file actions
115 lines (112 loc) · 3.03 KB
/
saofile.js
File metadata and controls
115 lines (112 loc) · 3.03 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
'use strict'
const validateNpmPackageName = require('validate-npm-package-name')
const SUPPORTED_NPM_CLIENTS = ['npm', 'yarn']
module.exports = {
description: 'Scaffolding out a node library.',
templateData: {
year: new Date().getFullYear(),
npmClientInstall: ({ npmClient }) => {
return npmClient === 'npm' ? 'install' : 'add'
}
},
prompts() {
return [
{
name: 'npmClient',
message: 'Which package manager do you want to use?',
default: 'npm',
type: 'list',
choices: SUPPORTED_NPM_CLIENTS
},
{
name: 'projectName',
message: 'What is the name of the new project',
default: this.outFolder,
filter: val => val.toLowerCase(),
validate: projectName => {
const validation = validateNpmPackageName(projectName)
return !validation.errors && !validation.warnings
}
},
{
name: 'description',
message: 'How would you describe the new project',
default: ''
},
{
name: 'keywords',
message: 'Comma-separated list of package keywords for npm',
default: ''
},
{
name: 'author',
message: 'What is your name',
default: this.gitUser.name,
store: true,
required: true
},
{
name: 'username',
message: 'What is your GitHub username',
default:
this.gitUser.username ||
this.gitUser.name
.toLowerCase()
.split(' ')
.join(''),
filter: val => val.toLowerCase(),
store: true
},
{
name: 'email',
message: 'What is your email?',
default: this.gitUser.email,
store: true,
validate: v => /.+@.+/.test(v)
},
{
name: 'projectRepository',
message: 'The URL of the repository',
default({ username, projectName }) {
return `https://github.com/${username}/${projectName}`
},
store: true
}
]
},
actions() {
const lockfile = this.answers.npmClient === 'npm' ? 'package-lock.json' : 'yarn.lock'
return [
{
type: 'add',
templateDir: 'template',
files: '**'
},
{
type: 'modify',
files: 'package.json',
handler(data, filepath) {
data.scripts[
'lint:lockfile'
] = `lockfile-lint --path ${lockfile} --validate-https --allowed-hosts npm yarn`
return data
}
}
// we already have the .gitignore file as part of the template/ directory
// {
// type: 'move',
// patterns: {
// gitignore: '.gitignore'
// // '_package.json': 'package.json'
// }
// }
]
},
async completed() {
this.gitInit()
await this.npmInstall({ npmClient: this.answers.npmClient })
await this.npmInstall({ npmClient: this.answers.npmClient, args: ['run', 'prepare'] })
this.showProjectTips()
this.logger.tip('You\'re all setup. hack away!')
}
}