This repository was archived by the owner on Mar 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdeployer.js
More file actions
354 lines (332 loc) · 11.1 KB
/
Copy pathdeployer.js
File metadata and controls
354 lines (332 loc) · 11.1 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
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/usr/bin/env node
const { exec } = require('child_process');
const fs = require('fs');
const KEY_MAP = {
'code-time': 'code-time',
'music-time': 'music-time',
};
const CODE_TIME_DESC =
'Code Time is an open source plugin that provides programming metrics right in Visual Studio Code.';
const MUSIC_TIME_DESC =
'Music Time is an open source plugin that curates and launches playlists for coding right from your editor.';
const CODE_TIME_VERSION = '1.1.14';
const MUSIC_TIME_VERSION = '0.2.4';
const CODE_TIME_DISPLAY = 'Code Time';
const MUSIC_TIME_DISPLAY = 'Music Time';
// copy the scripts data to dist/scripts
async function deploy() {
const args = process.argv;
console.log(args);
let packageIt = false;
if (!args || args.length <= 2) {
console.error('Usage: node deployer <code-time|music-time> [package]');
process.exit(1);
}
let pluginKey = process.argv[2];
if (process.argv[3]) {
packageIt = process.argv[3] === 'package';
}
if (!KEY_MAP[pluginKey]) {
console.error('No matching plugin found');
console.error('Usage: node deployer <code-time|music-time> [package]');
process.exit(1);
}
let pluginName = KEY_MAP[pluginKey];
if (!pluginName) {
console.error(
`The plugin extension name is not found based on the key: ${key}`
);
console.error('Usage: node deployer name={swdc-atom|music-time}');
process.exit(1);
}
debug(`------------- Building plugin: ${pluginName}`);
let extInfoJson = getJsonFromFile(getExtensionFile());
extInfoJson['name'] = pluginName;
let packageJson = getJsonFromFile(getPackageFile());
packageJson['name'] = pluginName;
if (pluginName === 'code-time') {
// remove contributes.viewsContainers and contributes.views
if (
packageJson.contributes &&
packageJson.contributes.viewsContainers
) {
delete packageJson.contributes.viewsContainers;
}
if (packageJson.contributes && packageJson.contributes.views) {
delete packageJson.contributes.views;
}
if (packageJson.contributes && packageJson.contributes.menus) {
delete packageJson.contributes.menus;
}
packageJson['description'] = CODE_TIME_DESC;
packageJson['version'] = CODE_TIME_VERSION;
packageJson['displayName'] = CODE_TIME_DISPLAY;
extInfoJson['displayName'] = CODE_TIME_DISPLAY;
let codeTimeCommands = [];
let existingCommands = packageJson.contributes['commands'];
for (let i = 0; i < existingCommands.length; i++) {
let commandObj = existingCommands[i];
if (commandObj.command.indexOf('musictime.') === -1) {
codeTimeCommands.push(commandObj);
}
}
packageJson.contributes['commands'] = codeTimeCommands;
} else if (pluginName === 'music-time') {
//
// add the viewsContainers and views
packageJson.contributes['viewsContainers'] = {
activitybar: [
{
id: 'music-time',
title: 'Music Time',
icon: 'resources/dark/headphone-symbol.svg',
},
],
};
packageJson.contributes['views'] = {
'music-time': [
{
id: 'music-time-playlists',
name: 'Music Time',
},
{
id: 'my-playlists',
name: 'My Playlists',
},
{
id: 'music-time-players',
name: 'Players',
},
],
};
packageJson.contributes['menus'] = {
'view/item/context': [
{
command: 'musictime.play',
when: 'viewItem =~ /.*item-paused$/',
group: 'inline',
},
{
command: 'musictime.pause',
when: 'viewItem =~ /.*item-playing$/',
group: 'inline',
},
{
command: 'musictime.sharePlaylist',
when: 'viewItem =~ /playlist-item.*/',
group: 'inline',
},
{
command: 'musictime.shareTrack',
when: 'viewItem =~ /track-item.*/',
group: 'inline',
},
],
'view/title': [
{
command: 'musictime.refreshReconcile',
group: 'navigation',
when: 'view =~ /.*-playlists/',
},
],
};
packageJson['description'] = MUSIC_TIME_DESC;
packageJson['version'] = MUSIC_TIME_VERSION;
packageJson['displayName'] = MUSIC_TIME_DISPLAY;
extInfoJson['displayName'] = MUSIC_TIME_DISPLAY;
let commands = [];
commands.push({
command: 'musictime.next',
title: 'Play Next Song',
});
commands.push({
command: 'musictime.previous',
title: 'Play Previous Song',
});
commands.push({
command: 'musictime.play',
title: 'Play',
icon: {
light: 'resources/light/play-button.svg',
dark: 'resources/dark/play-button.svg',
},
});
commands.push({
command: 'musictime.copyTrack',
title: 'Copy Track Link',
icon: {
light: 'resources/light/icons8-copy-to-clipboard-16.png',
dark: 'resources/dark/icons8-copy-to-clipboard-16.png',
},
});
commands.push({
command: 'musictime.copyPlaylist',
title: 'Copy Playlist Link',
icon: {
light: 'resources/light/icons8-copy-to-clipboard-16.png',
dark: 'resources/dark/icons8-copy-to-clipboard-16.png',
},
});
commands.push({
command: 'musictime.shareTrack',
title: 'Share Track',
icon: {
light: 'resources/light/share.svg',
dark: 'resources/dark/share.svg',
},
});
commands.push({
command: 'musictime.sharePlaylist',
title: 'Share Playlist',
icon: {
light: 'resources/light/share.svg',
dark: 'resources/dark/share.svg',
},
});
commands.push({
command: 'musictime.pause',
title: 'Pause',
icon: {
light: 'resources/light/pause-button.svg',
dark: 'resources/dark/pause-button.svg',
},
});
commands.push({
command: 'musictime.itunesPlaylist',
title: 'Switch to iTunes',
icon: {
light: 'resources/light/icons8-itunes.svg',
dark: 'resources/dark/icons8-itunes.svg',
},
});
commands.push({
command: 'musictime.spotifyPlaylist',
title: 'Switch to Spotify',
icon: {
light: 'resources/light/icons8-spotify.svg',
dark: 'resources/dark/icons8-spotify.svg',
},
});
commands.push({
command: 'musictime.refreshReconcile',
title: 'Refresh Playlists',
icon: {
light: 'resources/light/refresh.svg',
dark: 'resources/dark/refresh.svg',
},
});
commands.push({
command: 'musictime.like',
title: 'Like Song',
});
commands.push({
command: 'musictime.unlike',
title: 'Unlike Song',
});
commands.push({
command: 'musictime.menu',
title: 'Click to see more from Music Time',
});
commands.push({
command: 'musictime.currentSong',
title: 'Click to view track',
});
commands.push({
command: 'musictime.connectSpotify',
title: 'Connect your Spotify account',
tooltip: 'Connect your Spotify account to view your playlists',
});
commands.push({
command: 'musictime.disconnectSpotify',
title: 'Disconnect your Spotify account',
tooltip: 'Disconnect your Spotify account',
});
commands.push({
command: 'musictime.refreshPlaylist',
title: 'Refresh',
});
commands.push({
command: 'musictime.refreshSettings',
title: 'Refresh',
});
packageJson.contributes['commands'] = commands;
}
updateJsonContent(extInfoJson, getExtensionFile());
updateJsonContent(packageJson, getPackageFile());
}
function isWindows() {
return process.platform.indexOf('win32') !== -1;
}
function getExtensionFile() {
return __dirname + '/lib/extensioninfo.json';
}
function getPackageFile() {
return __dirname + '/package.json';
}
function getJsonFromFile(filename) {
let content = fs.readFileSync(filename, {encoding: 'utf8'}).toString();
if (content) {
try {
const data = JSON.parse(content);
return data;
} catch (e) {
//
}
}
return null;
}
function updateJsonContent(packageJson, filename) {
try {
// JSON.stringify(data, replacer, number of spaces)
const content = JSON.stringify(packageJson, null, 4);
fs.writeFileSync(filename, content, err => {
if (err)
console.log(
'Deployer: Error updating the package content: ',
err.message
);
process.exit(1);
});
} catch (e) {
//
}
}
async function runCommand(cmd, execMsg, ignoreError = false) {
debug('Executing task to ' + execMsg + '.');
let execResult = await wrapExecPromise(cmd);
if (execResult && execResult.status === 'failed' && !ignoreError) {
/* error happened */
debug('Failed to ' + execMsg + ', reason: ' + execResult.message);
process.exit(1);
}
}
async function wrapExecPromise(cmd, dir) {
let result = null;
try {
let dir = __dirname;
let opts = dir !== undefined && dir !== null ? { cwd: dir } : {};
result = await execPromise(cmd, opts);
} catch (e) {
result = { status: 'failed', message: e.message };
}
return result;
}
function execPromise(command, opts) {
return new Promise(function(resolve, reject) {
exec(command, opts, (error, stdout, stderr) => {
if (stderr) {
resolve({ status: 'failed', message: stderr.trim() });
return;
} else if (error) {
resolve({ status: 'failed', message: error.message });
return;
} else {
resolve({ status: 'success', message: stdout.trim() });
}
});
});
}
function debug(message) {
console.log('-- ' + message + '\n');
}
deploy();