forked from linuxmint/cinnamon-spices-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
132 lines (108 loc) · 3.63 KB
/
gulpfile.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
const fs = require('fs');
const os = require('os');
const gulp = require('gulp');
const clear = require('clear');
const {exec, execSync} = require('child_process');
const getArgs = function() {
const argv = require('yargs')
.option('uuid', {
alias: 'u'
})
.argv;
const UUID = argv.u;
if (!UUID) {
throw new Error('Unable to get the UUID.');
}
return UUID;
}
gulp.task('install', (done) => {
const UUID = getArgs();
const homeDir = os.homedir();
const systemXletDir = `${homeDir}/.local/share/cinnamon/extensions/${UUID}/`;
const localXletDir = `./${UUID}/files/${UUID}/`;
const systemDirExists = fs.existsSync(systemXletDir);
const localDirExists = fs.existsSync(localXletDir);
const userInfo = os.userInfo();
if (!systemDirExists) {
console.log(
'Xlet does not exist in the system directory. Attempting to create the directory:\n' +
systemXletDir
);
execSync(`mkdir ${systemXletDir}`);
}
if (!localDirExists) {
throw new Error('Xlet does not exist in the local directory.');
}
const {uid, gid} = fs.statSync(systemXletDir);
if (uid !== userInfo.uid || gid !== userInfo.gid) {
throw new Error(`Incorrect permission are set for the extensions directory. Please run 'gulp help'.`);
}
exec(`rm -rf ${systemXletDir} && ` +
`cp -arf ${localXletDir} ${systemXletDir}`,
function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
done();
}
);
});
const reload = function(done) {
const UUID = getArgs();
exec(
'dbus-send --session --dest=org.Cinnamon.LookingGlass --type=method_call '
+ '/org/Cinnamon/LookingGlass org.Cinnamon.LookingGlass.ReloadExtension '
+ `string:'${UUID}' string:'EXTENSION'`,
function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
done();
}
);
};
gulp.task('reload', gulp.series('install', reload));
gulp.task('_watch', (done) => {
const UUID = getArgs();
const localXletDir = `./${UUID}/files/${UUID}`;
const glob = `${localXletDir}/**/**/**/*.{js,json,py,css,po}`;
const localDirExists = fs.existsSync(localXletDir);
if (!localDirExists) {
throw new Error('Xlet does not exist in the local directory.');
}
console.log(`Watching glob pattern: ${glob}`)
gulp.watch(glob)
.on('change', gulp.parallel('reload'));
done();
});
gulp.task('clear-terminal', (done) => {
clear();
done();
});
gulp.task('watch', gulp.series('clear-terminal', (done) => {
let [, , , uuid] = process.argv;
let spawnWatch = () => {
let proc = require('child_process').spawn('gulp', ['_watch', uuid], {stdio: 'inherit'});
proc.on('close', function(code) {
spawnWatch();
});
};
spawnWatch();
done();
}));
gulp.task('help', gulp.series('clear-terminal', (done) => {
console.log(
`Usage: gulp watch [flags]
This file uses gulp to provide a watch task for xlet development.
It will copy the xlet files from the UUID directory specified and
auto-reload the extension on code change.
Install gulp globally.
npm: 'npm install -g gulp@^4.0.0'
yarn: 'yarn global add gulp@^4.0.0'
To use this script, run 'gulp watch --uuid="<xlet uuid>"'.
Example: 'gulp watch --uuid="[email protected]"'
Options:
--uuid UUID of the xlet to watch.
`
);
done();
}));
gulp.task('default', gulp.series('watch', (done) => done()));