This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.js
274 lines (257 loc) · 8.97 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
'use strict';
var chalk = require('chalk');
var mkdirp = require('mkdirp');
var path = require('path');
var yeoman = require('yeoman-generator');
var yosay = require('yosay');
var helper = require('./validationHelper');
module.exports = yeoman.extend({
prompting: function () {
// Have Yeoman greet the user.
this.log(yosay(
'Welcome to the awesome ' + chalk.red('generator-kodi') + ' generator!'
));
var prompts = [{
type: 'list',
name: 'type',
message: 'Choose the type of addon you want to create.',
choices: ['Contextmenu', 'Module', 'Plugin', 'Resource', 'Script', 'Service', 'Subtitle'],
default: 0
}];
return this.prompt(prompts).then(function (props) {
// To access props later use this.props.someAnswer;
this.props = props;
}.bind(this));
},
askForAddonData: function () {
var prompts = [];
var kodiVersion = [{
name: 'Krypton',
value: '2.25.0'
}, {
name: 'Jarvis',
value: '2.24.0'
}];
if (this.props.type == 'Plugin' || this.props.type == 'Script') {
prompts.push({
type: 'checkbox',
name: 'provides',
message: 'Your addon will provide the following media types.',
choices: ['audio', 'image', 'executable', 'game', 'video']
});
}
if (this.props.type == 'Service') {
prompts.push({
type: 'list',
name: 'start',
message: 'Your service should start at:',
choices: ['login', 'startup']
});
}
var scriptidMessage;
var validationHelper;
if (this.props.type == 'Contextmenu') {
scriptidMessage = 'Your addon id, it should be in the format context.name.name and not contain spaces. (for e.g. context.hello.menu)';
validationHelper = helper.validateContextmenuName;
} else if (this.props.type == 'Module') {
scriptidMessage = 'Your addon id, it should be in the format script.module.name and not contain spaces. (for e.g. script.module.hello)';
validationHelper = helper.validateModuleName;
} else if (this.props.type == 'Plugin') {
scriptidMessage = 'Your addon id, it should be in the format plugin.name and not contain spaces. (for e.g. plugin.test.hello)';
validationHelper = helper.validatePluginName;
} else if (this.props.type == 'Resource') {
scriptidMessage = 'Your addon id, it should be in the format resource.resourcetype.name and not contain spaces. (for e.g. resource.images.hello)';
validationHelper = helper.validateResourceName;
} else if (this.props.type == 'Service') {
scriptidMessage = 'Your addon id, it should be in the format service.name and not contain spaces. (for e.g. service.test.hello)';
validationHelper = helper.validateServiceName;
} else if (this.props.type == 'Script') {
scriptidMessage = 'Your addon id, it should be in the format script.name and not contain spaces. (for e.g. script.test.hello)';
validationHelper = helper.validateScriptName;
} else if (this.props.type == 'Subtitle') {
scriptidMessage = 'Your addon id, it should be in the format service.subtitles.name and not contain spaces. (for e.g. service.subtitles.hello)';
validationHelper = helper.validateSubtitleName;
}
prompts.push({
type: 'input',
name: 'scriptid',
message: scriptidMessage,
validate: validationHelper
}, {
type: 'input',
name: 'scriptname',
message: 'Your addon name, it should be easily readable. (for e.g. Hello World)',
validate: helper.validateScriptNameLength
}, {
type: 'list',
name: 'kodiVersion',
message: 'Choose the minimal Kodi Version your targeting.',
choices: kodiVersion,
default: 0
}, {
type: 'checkbox',
name: 'platforms',
message: 'Which platforms does this run with?',
choices: ['all', 'android', 'linux', 'osx', 'windx']
}, {
type: 'list',
name: 'license',
message: 'Choose your license.',
choices: require('generator-license').licenses,
default: 0
}, {
type: 'input',
name: 'authors',
message: 'All author names? (seperated by ,)'
}, {
type: 'input',
name: 'summary',
message: 'What does your addon do?'
}, {
type: 'input',
name: 'authorName',
message: 'Your real name? We are using this for the license creation.'
}, {
type: 'input',
name: 'email',
message: 'Your email address? (for e.g. john.doe@gmail.com)'
}, {
type: 'input',
name: 'website',
message: 'Your website URL? (for e.g. www.kodi.tv)'
});
return this.prompt(prompts).then(function (props) {
// To access props later use this.props.someAnswer;
this.props = Object.assign(this.props, props);
}.bind(this));
},
default: function () {
if (path.basename(this.destinationPath()) !== this.props.scriptid) {
this.log(
'Your generator must be inside a folder named ' + this.props.scriptid + '\n' +
'I\'ll automatically create this folder.'
);
mkdirp(this.props.scriptid);
this.destinationRoot(this.destinationPath(this.props.scriptid));
}
},
writing: function () {
this.fs.copyTpl(
this.templatePath('addon.xml'),
this.destinationPath('addon.xml'), {
props: this.props,
platforms: this.props.platforms === undefined ? this.props.platforms : this.props.platforms.toString().replace(/[,]/g, ' '),
provides: this.props.provides === undefined ? this.props.provides : this.props.provides.toString().replace(/[,]/g, ' ')
}
);
this.fs.copy(
this.templatePath('.gitignore'),
this.destinationPath('.gitignore')
);
this.fs.copy(
this.templatePath('changelog.txt'),
this.destinationPath('changelog.txt')
);
this.fs.copy(
this.templatePath('README.md'),
this.destinationPath('README.md')
);
if (this.props.type != 'Module' && this.props.type != 'Resource') {
this.fs.copyTpl(
this.templatePath('main.py'),
this.destinationPath('main.py'), {
props: this.props
}
);
}
if (this.props.type == 'Contextmenu') {
this.fs.copy(
this.templatePath('resources/lib/context.py'),
this.destinationPath('resources/lib/context.py')
);
} else if (this.props.type == 'Plugin') {
this.fs.copy(
this.templatePath('resources/lib/plugin.py'),
this.destinationPath('resources/lib/plugin.py')
);
} else if (this.props.type == 'Script') {
this.fs.copy(
this.templatePath('resources/lib/script.py'),
this.destinationPath('resources/lib/script.py')
);
} else if (this.props.type == 'Service') {
this.fs.copy(
this.templatePath('resources/lib/service.py'),
this.destinationPath('resources/lib/service.py')
);
} else if (this.props.type == 'Subtitle') {
this.fs.copy(
this.templatePath('resources/lib/subtitle.py'),
this.destinationPath('resources/lib/subtitle.py')
);
}
if (this.props.type != 'Module' && this.props.type != 'Resource' && this.props.type != 'Contextmenu') {
this.fs.copy(
this.templatePath('tests/**'),
this.destinationPath('tests/')
);
}
if (this.props.type != 'Module' && this.props.type != 'Resource') {
if (this.props.type == 'Contextmenu') {
this.fs.copy(
this.templatePath('resources/language/**'),
this.destinationPath('resources/language/')
);
} else {
this.fs.copyTpl(
this.templatePath('resources/*'),
this.destinationPath('resources/'), {
props: this.props
}
);
this.fs.copyTpl(
this.templatePath('resources/language/**'),
this.destinationPath('resources/language/'), {
props: this.props
}
);
this.fs.copyTpl(
this.templatePath('resources/lib/__init__.py'),
this.destinationPath('resources/lib/__init__.py'), {
props: this.props
}
);
this.fs.copyTpl(
this.templatePath('resources/lib/utilities.py'),
this.destinationPath('resources/lib/utilities.py'), {
props: this.props
}
);
this.fs.copyTpl(
this.templatePath('resources/lib/kodiLogging.py'),
this.destinationPath('resources/lib/kodiLogging.py'), {
props: this.props
}
);
this.fs.copyTpl(
this.templatePath('resources/lib/README.md'),
this.destinationPath('resources/lib/README.md'), {
props: this.props
}
);
}
}
if (this.props.type == 'Resource') {
mkdirp(this.destinationPath('resources/'));
}
this.composeWith(require.resolve('generator-license/app'), {
name: this.props.authorName,
email: this.props.email,
website: this.props.website,
license: this.props.license
});
this.composeWith(require.resolve('generator-git-init'), {
commit: 'Created initial addon structure'
});
}
});