/
index.js
138 lines (120 loc) · 3.34 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const path = require('path');
const Generator = require('yeoman-generator');
const {paramCase, camelCase} = require('change-case');
const ora = require('ora');
const getFreePort = require('../app/get-free-port');
const getLatestVersions = require('../app/get-latest-versions');
const packages = [
'generator-ring-ui',
'ring-ui',
'jetbrains-logos',
'jetbrains-icons',
'hub-dashboard-addons'
];
const BASE_GENERATOR_PATH = path.resolve(
require.resolve('../app/index'),
'../templates'
);
const additionalDevServerOptions = `
headers: {
'Access-Control-Allow-Origin': '*'
},`;
module.exports = class extends Generator.Base {
prompting() {
let spinner;
const prompt = this.prompt([
{
type: 'input',
name: 'widgetName',
message: 'What\'s your widget name, i.e. "My first cool widget"',
default: this.appname
},
{
type: 'input',
name: 'widgetDescription',
message: 'Your widget description',
default: ''
},
{
type: 'input',
name: 'widgetAuthor',
message: 'Widget author name, i.e. "Alice <alice@example.com>"',
default: ''
}
]).then(answers => {
spinner = ora('Getting info').start();
return answers;
});
return Promise.all([prompt, getFreePort(), getLatestVersions(packages)]).
then(([answers, port, versions]) => {
const projectName = paramCase(answers.widgetName);
const camelCaseName = camelCase(answers.widgetName);
this.props = Object.assign({
projectName,
camelCaseName,
additionalDevServerOptions,
port
}, answers, versions);
}).
then(() => {
if (spinner) {
spinner.succeed();
}
});
}
files() {
// Hub-widget template files
this.fs.copyTpl(
this.templatePath('*.{json,js}'),
this.destinationPath(''),
this.props
);
// Hub-widget sources
this.fs.copyTpl(
this.templatePath('src/**/*'),
this.destinationPath('src/'),
this.props
);
// Base generator files
this.fs.copyTpl(
this.templatePath(path.join(BASE_GENERATOR_PATH, '*.{json,js}')),
this.destinationPath(''),
this.props
);
// Modify package.json – add hub-dashboard-addons
this.fs.copy(
this.destinationPath('package.json'),
this.destinationPath('package.json'),
{
process: content => {
const pkg = JSON.parse(content);
pkg.config.components = './src';
pkg.dependencies['hub-dashboard-addons'] =
this.props.hubDashboardAddons;
const SPACES = 2;
return JSON.stringify(pkg, null, SPACES);
}
}
);
}
_copyTemplate(src, dst) {
this.fs.copyTpl(
this.templatePath(require.resolve(`../app/templates/${src}`)),
this.destinationPath(dst)
);
}
configuring() {
this._copyTemplate('npmrc', '.npmrc');
this._copyTemplate('editorconfig', '.editorconfig');
this._copyTemplate('gitignore', '.gitignore');
this._copyTemplate('eslintignore', '.eslintignore');
this._copyTemplate('eslintrc', '.eslintrc');
this._copyTemplate('src/eslintrc', 'src/.eslintrc');
}
install() {
this.installDependencies({
bower: false,
skipInstall: this.options['skip-install']
});
}
};