|
15 | 15 | */ |
16 | 16 | const gulp = require("gulp"); |
17 | 17 | const mapapps = require('ct-mapapps-gulp-js'); |
| 18 | +const mapappsBrowserSync = require("ct-mapapps-browser-sync"); |
| 19 | + |
| 20 | +const isProduction = process.env.NODE_ENV === "production"; |
| 21 | +console.info(`Configuring gulp build for ${isProduction ? "production" : "development"}`); |
| 22 | + |
| 23 | +const localOverrides = (function () { |
| 24 | + if (isProduction) { |
| 25 | + // Never override defaults in production mode |
| 26 | + return undefined; |
| 27 | + } |
| 28 | + |
| 29 | + try { |
| 30 | + return require("./gulpfile.overrides"); |
| 31 | + } catch (e) { |
| 32 | + // File may not exist |
| 33 | + return undefined; |
| 34 | + } |
| 35 | +})(); |
| 36 | + |
| 37 | +// used to transport test urls in "run-browser-tests-local" task |
| 38 | +const runBrowserTests = []; |
18 | 39 |
|
19 | 40 | mapapps.registerTasks({ |
| 41 | + /** Enable debug logging */ |
| 42 | + debug: localOverrides?.debug ?? false, |
| 43 | + /** enable linting */ |
| 44 | + lintOnWatch: localOverrides?.lintOnWatch ?? true, |
| 45 | + /** enable es6 by default */ |
| 46 | + forceTranspile: true, |
20 | 47 | /* A detailed description of available setting is available at https://www.npmjs.com/package/ct-mapapps-gulp-js */ |
| 48 | + compress: isProduction, |
| 49 | + |
| 50 | + /* build source maps as e.g. ".js.map" */ |
| 51 | + sourceMaps: "file", |
| 52 | + |
| 53 | + /** Build Unit-Tests only in dev mode */ |
| 54 | + rollupBuildTests: !isProduction, |
| 55 | + /** Amount of Threads used to build the bundles, if there are only a few bundles 1 is ok. |
| 56 | + * More as 3 is normally not required. |
| 57 | + */ |
| 58 | + rollupBuildMaxWorkers: localOverrides?.rollupBuildMaxWorkers ?? 1, |
| 59 | + |
| 60 | + /** List of build time flags, usage like: import { debug } from "build-config!". |
| 61 | + */ |
| 62 | + rollupConfig: { |
| 63 | + debug: !isProduction |
| 64 | + }, |
| 65 | + |
21 | 66 | /* a list of themes inside this project */ |
22 | | - themes: [/*"sample-theme"*/], |
| 67 | + themes: [], |
23 | 68 | /* state that the custom theme will be dependant from map.apps everlasting theme that provides the base styles */ |
24 | | - hasBaseThemes: true, |
| 69 | + hasBaseThemes: false, |
25 | 70 | /* state that we want to support vuetify components and therefore need the vuetify core styles*/ |
26 | | - hasVuetify: true |
| 71 | + hasVuetify: false, |
27 | 72 | /*themeChangeTargets: { |
28 | 73 | "vuetify": [ |
29 | | - "sample_theme" |
| 74 | + "theme-custom" |
30 | 75 | ] |
31 | | - }*/ |
32 | | -}); |
| 76 | + },*/ |
| 77 | + /* A list oft target browser versions. This should be streamlined with Esri JS API requirements. */ |
| 78 | + transpileTargets: { |
| 79 | + firefox: 102, |
| 80 | + edge: 104, |
| 81 | + chrome: 104, |
| 82 | + safari: 15 |
| 83 | + }, |
| 84 | + runBrowserTests, |
| 85 | + watchFinishedReceiver() { |
| 86 | + if (localOverrides?.autoReload ?? true) { |
| 87 | + mapappsBrowserSync.state.reload(); |
| 88 | + } |
| 89 | + } |
| 90 | +}, gulp); |
33 | 91 |
|
34 | | -gulp.task("default", |
| 92 | +mapappsBrowserSync.registerTask({ |
| 93 | + // on which port to listen |
| 94 | + port: localOverrides?.port ?? 9090, |
| 95 | + // activate https protocol, generates a self signed certificate for "localhost" |
| 96 | + // https://browsersync.io/docs/options#option-https |
| 97 | + https: localOverrides?.https ?? false, |
| 98 | + |
| 99 | + // to prevent auto open of browser, set this to false |
| 100 | + urlToOpen: localOverrides?.openBrowser ?? true, |
| 101 | + properties: { |
| 102 | + paths: [ |
| 103 | + // Ensure @@key@@ expressions filtered in tests files |
| 104 | + /^\/js\/tests\/(runTests.html|test-init.js|init-packs.js)$/ |
| 105 | + ] |
| 106 | + }, |
| 107 | + jsreg: { |
| 108 | + //npmDir : __dirname + "/node_modules/", |
| 109 | + npmModules: [ |
| 110 | + "mocha", |
| 111 | + "chai", |
| 112 | + "@conterra/mapapps-mocha-runner" |
| 113 | + ] |
| 114 | + }, |
| 115 | + // prevent reload by browser sync (reload triggered on watch end) |
| 116 | + externalReloadTrigger: true |
| 117 | +}, gulp); |
| 118 | + |
| 119 | +gulp.task("build", |
35 | 120 | gulp.series( |
36 | 121 | "copy-resources", |
37 | 122 | "themes-copy", |
38 | 123 | gulp.parallel( |
39 | | - //"js-lint", |
40 | | - //"style-lint", |
41 | 124 | "js-transpile", |
| 125 | + "rollup-build", |
42 | 126 | "themes-compile" |
43 | 127 | ) |
44 | 128 | ) |
45 | 129 | ); |
46 | 130 |
|
| 131 | +gulp.task("lint", |
| 132 | + gulp.parallel( |
| 133 | + "js-lint" |
| 134 | + /*, comment in to lint .css/.less files |
| 135 | + "style-lint" |
| 136 | + */ |
| 137 | + )); |
| 138 | + |
| 139 | +gulp.task("preview", |
| 140 | + gulp.series( |
| 141 | + "build", |
| 142 | + gulp.parallel( |
| 143 | + "watch", |
| 144 | + "browser-sync" |
| 145 | + ) |
| 146 | + )); |
| 147 | + |
| 148 | +gulp.task("run-tests", |
| 149 | + gulp.series( |
| 150 | + "browser-sync-start", |
| 151 | + function transportTestUrls() { |
| 152 | + // transport test url to run-browser-tests |
| 153 | + // eslint-disable-next-line max-len |
| 154 | + const testsAt = mapappsBrowserSync.state.url + "/resources/jsregistry/root/@conterra/mapapps-mocha-runner/latest/mocha.html?boot=/js/tests/test-init.js&timeout=5000&test=mapapps-github-manager/tests/all&reporter=tap"; |
| 155 | + runBrowserTests.push(testsAt); |
| 156 | + return Promise.resolve(); |
| 157 | + }, |
| 158 | + "run-browser-tests", |
| 159 | + "browser-sync-stop" |
| 160 | + )); |
| 161 | + |
| 162 | +gulp.task("test", |
| 163 | + gulp.series( |
| 164 | + "build", |
| 165 | + "lint", |
| 166 | + "run-tests" |
| 167 | + )); |
| 168 | + |
47 | 169 | gulp.task("compress", |
48 | 170 | gulp.series( |
49 | | - "default", |
50 | | - "themes-compress" |
| 171 | + "build", |
| 172 | + "themes-compress", |
| 173 | + "lint" |
51 | 174 | ) |
52 | 175 | ); |
| 176 | + |
| 177 | +gulp.task("default", |
| 178 | + gulp.series( |
| 179 | + "build", |
| 180 | + "lint" |
| 181 | + )); |
0 commit comments