-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
167 lines (143 loc) · 4.25 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
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
/**
* Gnome Shell Extension tasks.
*
* @author emerino
*
*/
// sys deps
var fs = require('fs');
var path = require('path');
var zip = require('gulp-zip');
var spawn = require('child_process').spawn;
var argv = require("yargs").argv; // cmd arguments support
var webpack = require('webpack-stream');
var rimraf = require('rimraf'); // rimraf directly
// gulp plugins
var gulp = require("gulp");
var gulpsync = require('gulp-sync')(gulp);
//extension metadata
var metadata = JSON.parse(fs.readFileSync("metadata.json"));
var installDir = argv.installDir || path.join(process.env.HOME, ".local/share/gnome-shell/extensions/");
// local config
var config = {
srcDir: path.join(__dirname, "src"),
distDir: path.join(__dirname, "dist"),
buildDir: path.join(__dirname, "build"),
installDir: installDir + metadata.uuid,
singleRun: argv.singleRun || false,
browser: argv.browser || "PhantomJS",
transpile: argv.transpile || false
};
var enableExtension = function (enable, cb) {
var option = enable ? "-e" : "-d";
spawn("gnome-shell-extension-tool", [option, metadata.uuid], {stdio: "inherit"})
.on("exit", function () {
cb();
});
};
/**
* Native GJS testing using jasmine-gjs.
*/
gulp.task("test", ["build"], function (cb) {
spawn("jasmine", ["build/test.js"], {stdio: "inherit", stdout: "inherit"})
.on("exit", function () {
cb();
});
});
/**
* Clean build and dist dir
*/
gulp.task("clean", function (cb) {
rimraf("{config.distDir, 'build'}", cb);
});
/**
* Copy the extension to local extensions folder or specified installDir
*/
gulp.task("copy:extension", function () {
return gulp.src(["metadata.json", config.buildDir + "/extension.js"])
.pipe(gulp.dest(config.installDir));
});
/**
* This task uses webpack to generate a single JS extension file. It will
* use babel for transpiling and UMD for module handling.
*/
gulp.task('build', function () {
var webpackConfig = require("./webpack.config.js");
// transpile on demand
if (config.transpile) {
webpackConfig.module = {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: [
require('babel-preset-env'),
],
plugins: [
require('babel-plugin-transform-runtime'),
require('babel-plugin-transform-es2015-modules-umd'),
]
}
}
},
]
};
}
return webpack(webpackConfig)
.pipe(gulp.dest("build"));
});
/**
* Create ZIP file for distribution to GSE
*/
gulp.task("dist", gulpsync.sync(["build", "test"]), function () {
return gulp.src([
"metadata.json",
config.buildDir + "/extension.js"
])
.pipe(zip(metadata.uuid + ".zip"))
.pipe(gulp.dest(config.distDir));
});
/**
* Enable extension.
*/
gulp.task("enable", function (cb) {
enableExtension(true, cb);
});
/**
* Disable extension.
*/
gulp.task("disable", function (cb) {
enableExtension(false, cb);
});
/**
* Install extension locally (copies and enables).
*/
gulp.task("install", ["copy:extension"], function (cb) {
return gulp.start("enable");
});
/**
* Uninstall extension locally. Removes install dir and disables.
*/
gulp.task("uninstall", ["disable"], function (cb) {
rimraf(config.installDir, cb);
});
/**
* Restart gnome shell task.
*/
gulp.task("restart:gnome-shell", ["copy:extension"], function () {
var out = fs.openSync('./out.log', 'a');
var err = fs.openSync('./out.log', 'a');
var gs = spawn('gnome-shell', ["-r"], {detached: true});
gs.stdout.on("data", function (chunk) {
process.stdout.write(chunk.toString());
});
gs.stderr.on("data", function (chunk) {
process.stdout.write(chunk.toString());
});
gs.unref();
});
// run dist by default, which builds and tests the project
gulp.task("default", ["dist"]);