forked from rockcarver/frodo-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
153 lines (137 loc) · 3.65 KB
/
gulpfile.js
File metadata and controls
153 lines (137 loc) · 3.65 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
/* eslint-disable no-param-reassign */
import gulp from 'gulp';
import install from 'gulp-install';
import babel from 'gulp-babel';
import del from 'del';
import sourcemaps from 'gulp-sourcemaps';
import map from 'map-stream';
import { exec } from 'pkg';
import { spawn } from 'child_process';
gulp.task('link-frodo-lib', (cb) => {
const cmd = spawn('npm', ['link', '../frodo-lib'], { stdio: 'inherit' });
cmd.on('close', (code) => {
console.log(`link-frodo-lib exited with code ${code}`);
cb(code);
});
});
gulp.task('clean-esm', () => del(['esm']));
gulp.task('transpile-esm', () =>
gulp
.src(['src/*.ts', 'src/**/*.ts'])
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(babel({ configFile: './babel.config.esm.json' }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('esm'))
);
gulp.task('resources-esm', () =>
gulp
.src(['src/**/*.json', 'src/**/*.txt', 'src/**/*.xml'], { base: './src/' })
.pipe(gulp.dest('esm'))
);
gulp.task('install', () =>
gulp.src(['package.json'], { base: '.' }).pipe(install())
);
gulp.task('dist-clean', () => del(['dist/src']));
gulp.task('dist-package', () =>
gulp
.src('package.json')
.pipe(
map((file, done) => {
const json = JSON.parse(file.contents.toString());
delete json.type;
json.main = 'src/app.js';
json.bin.frodo = './src/app.js';
// eslint-disable-next-line no-param-reassign
file.contents = Buffer.from(JSON.stringify(json));
done(null, file);
})
)
.pipe(gulp.dest('dist'))
);
gulp.task('dist-install', () =>
gulp.src(['dist/package.json'], { base: 'dist' }).pipe(install())
);
gulp.task('dist-transpile', () =>
gulp
.src(['src/*.ts', 'src/**/*.ts'])
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(
babel({
configFile: './babel.config.esm.json',
plugins: [
[
'@babel/plugin-transform-modules-commonjs',
{
importInterop: 'babel',
},
],
['babel-plugin-transform-import-meta'],
],
})
)
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('dist/src'))
);
gulp.task('dist-resources', () =>
gulp.src(['src/**/*.json'], { base: './' }).pipe(gulp.dest('dist'))
);
gulp.task('dist-pkg', () => {
switch (process.platform) {
case 'darwin':
console.log(`Building MacOS (${process.arch}) binary.`);
return exec([
'-C',
'Gzip',
'-t',
`node18-macos-${process.arch}`,
'-o',
'dist/bin/macos/frodo',
'dist',
]);
case 'linux':
console.log(`Building Linux (${process.arch}) binary.`);
return exec([
'-C',
'Gzip',
'-t',
`node18-linux-${process.arch}`,
'-o',
'dist/bin/linux/frodo',
'dist',
]);
case 'win32':
console.log(`Building Windows (${process.arch}) binary.`);
return exec([
'-C',
'Gzip',
'-t',
`node18-win-${process.arch}`,
'-o',
'dist/bin/win/frodo',
'dist',
]);
default:
console.log('Unsupported OS - not building binaries.');
return null;
}
});
gulp.task(
'build-local',
gulp.series('install', 'clean-esm', 'transpile-esm', 'resources-esm')
);
gulp.task(
'build-binary',
gulp.series(
'dist-clean',
'dist-package',
'dist-install',
'dist-transpile',
'dist-resources',
'dist-pkg'
)
);
gulp.task('default', gulp.parallel('build-local', 'build-binary'));
gulp.task('do-watch', () => {
gulp.watch(['src/*.ts', 'src/**/*.ts'], gulp.series('transpile-esm'));
});
gulp.task('watch', gulp.series('link-frodo-lib', 'do-watch'));