diff options
author | Stefan Malzner <stefan@adlk.io> | 2017-10-13 12:29:40 +0200 |
---|---|---|
committer | Stefan Malzner <stefan@adlk.io> | 2017-10-13 12:29:40 +0200 |
commit | 58cda9cc7fb79ca9df6746de7f9662bc08dc156a (patch) | |
tree | 1211600c2a5d3b5f81c435c6896618111a611720 /gulpfile.babel.js | |
download | ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.gz ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.zst ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.zip |
initial commit
Diffstat (limited to 'gulpfile.babel.js')
-rw-r--r-- | gulpfile.babel.js | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/gulpfile.babel.js b/gulpfile.babel.js new file mode 100644 index 000000000..d947974b3 --- /dev/null +++ b/gulpfile.babel.js | |||
@@ -0,0 +1,131 @@ | |||
1 | /* eslint max-len: 0 */ | ||
2 | import gulp from 'gulp'; | ||
3 | import babel from 'gulp-babel'; | ||
4 | import sass from 'gulp-sass'; | ||
5 | import server from 'gulp-server-livereload'; | ||
6 | import del from 'del'; | ||
7 | import { exec } from 'child_process'; | ||
8 | import dotenv from 'dotenv'; | ||
9 | import sassVariables from 'gulp-sass-variables'; | ||
10 | |||
11 | import config from './package.json'; | ||
12 | |||
13 | dotenv.config(); | ||
14 | |||
15 | const paths = { | ||
16 | src: 'src', | ||
17 | dest: 'build', | ||
18 | tmp: '.tmp', | ||
19 | package: `out/${config.version}`, | ||
20 | html: { | ||
21 | src: 'src/**/*.html', | ||
22 | dest: 'build/', | ||
23 | watch: 'src/**/*.html', | ||
24 | }, | ||
25 | styles: { | ||
26 | src: 'src/styles/main.scss', | ||
27 | dest: 'build/styles', | ||
28 | watch: 'src/styles/**/*.scss', | ||
29 | }, | ||
30 | scripts: { | ||
31 | src: 'src/**/*.js', | ||
32 | dest: 'build/', | ||
33 | watch: 'src/**/*.js', | ||
34 | }, | ||
35 | }; | ||
36 | |||
37 | function _shell(cmd, cb) { | ||
38 | exec(cmd, { | ||
39 | cwd: paths.dest, | ||
40 | }, (error, stdout, stderr) => { | ||
41 | if (error) { | ||
42 | console.error(`exec error: ${error}`); | ||
43 | return; | ||
44 | } | ||
45 | console.log(`stdout: ${stdout}`); | ||
46 | console.log(`stderr: ${stderr}`); | ||
47 | |||
48 | cb(); | ||
49 | }); | ||
50 | } | ||
51 | |||
52 | const clean = () => del([paths.tmp, paths.dest]); | ||
53 | export { clean }; | ||
54 | |||
55 | export function mvSrc() { | ||
56 | return gulp.src( | ||
57 | [ | ||
58 | `${paths.src}/*`, | ||
59 | `${paths.src}/*/**`, | ||
60 | `!${paths.scripts.watch}`, | ||
61 | `!${paths.src}/styles/**`, | ||
62 | ], { since: gulp.lastRun(mvSrc) }) | ||
63 | .pipe(gulp.dest(paths.dest)); | ||
64 | } | ||
65 | |||
66 | export function mvPackageJson() { | ||
67 | return gulp.src( | ||
68 | [ | ||
69 | './package.json', | ||
70 | ]) | ||
71 | .pipe(gulp.dest(paths.dest)); | ||
72 | } | ||
73 | |||
74 | export function html() { | ||
75 | return gulp.src(paths.html.src, { since: gulp.lastRun(html) }) | ||
76 | .pipe(gulp.dest(paths.html.dest)); | ||
77 | } | ||
78 | |||
79 | export function styles() { | ||
80 | return gulp.src(paths.styles.src) | ||
81 | .pipe(sassVariables({ | ||
82 | $env: process.env.NODE_ENV === 'development' ? 'development' : 'production', | ||
83 | })) | ||
84 | .pipe(sass({ | ||
85 | includePaths: [ | ||
86 | './node_modules', | ||
87 | '../node_modules', | ||
88 | ], | ||
89 | }).on('error', sass.logError)) | ||
90 | .pipe(gulp.dest(paths.styles.dest)); | ||
91 | } | ||
92 | |||
93 | export function scripts() { | ||
94 | return gulp.src(paths.scripts.src, { since: gulp.lastRun(scripts) }) | ||
95 | .pipe(babel({ | ||
96 | comments: false, | ||
97 | })) | ||
98 | .pipe(gulp.dest(paths.scripts.dest)); | ||
99 | } | ||
100 | |||
101 | export function watch() { | ||
102 | gulp.watch(paths.scripts.watch, scripts); | ||
103 | gulp.watch(paths.styles.watch, styles); | ||
104 | |||
105 | gulp.watch([ | ||
106 | paths.src, | ||
107 | `${paths.scripts.src}`, | ||
108 | `${paths.styles.src}`, | ||
109 | ], mvSrc); | ||
110 | } | ||
111 | |||
112 | export function webserver() { | ||
113 | gulp.src(paths.dest) | ||
114 | .pipe(server({ | ||
115 | livereload: true, | ||
116 | })); | ||
117 | } | ||
118 | |||
119 | export function sign(done) { | ||
120 | _shell(`codesign --verbose=4 --deep --strict --force --sign "${process.env.SIGNING_IDENTITY}" "${__dirname}/node_modules/electron/dist/Electron.app"`, done); | ||
121 | } | ||
122 | |||
123 | const build = gulp.series( | ||
124 | clean, | ||
125 | gulp.parallel(mvSrc, mvPackageJson), | ||
126 | gulp.parallel(html, scripts, styles), | ||
127 | ); | ||
128 | export { build }; | ||
129 | |||
130 | const dev = gulp.series(build, gulp.parallel(webserver, watch)); | ||
131 | export { dev }; | ||