js-build-tools 2.2.12 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -36,6 +36,9 @@ module.exports = {
36
36
  // The paths for directories to delete before build.
37
37
  cleanPaths: ['dist', 'browser'],
38
38
 
39
+ // The destination path for where generated CSS (from SASS files) should go
40
+ cssPath: 'browser/css',
41
+
39
42
  // The name of entry the distribution file.
40
43
  distMain: 'dist/main',
41
44
 
@@ -66,6 +69,12 @@ module.exports = {
66
69
  // Base directory of the project.
67
70
  rootPath: './',
68
71
 
72
+ // The directory were sass files will be stored
73
+ sassPath: 'sass',
74
+
75
+ // The pattern for finding all sass files
76
+ sassSearch: 'sass/**/*.+(scss|sass)',
77
+
69
78
  // The directory where your source files are stored (the files you manually created).
70
79
  srcPath: 'src',
71
80
 
@@ -81,6 +90,9 @@ module.exports = {
81
90
 
82
91
  // Pattern for finding the TypeScript files
83
92
  tsSearch: 'src/**/*.ts',
93
+
94
+ // Toggle SASS to CSS process on
95
+ useSass: false,
84
96
 
85
97
  // The path the tsconfig file for running typescript or false if no ts file given.
86
98
  useTsConfig: false,
@@ -102,6 +114,7 @@ const {
102
114
  defaultCmd,
103
115
  partials,
104
116
  readme,
117
+ sass,
105
118
  testFull,
106
119
  testQuick,
107
120
  typescript,
@@ -115,6 +128,7 @@ const {
115
128
  exports.build = build
116
129
  exports.default = defaultCmd
117
130
  exports.readme = readme
131
+ exports.sass = sass
118
132
  exports.testFull = testFull
119
133
  exports.testQuick = testQuick
120
134
  exports.watchFull = watchFull
@@ -136,6 +150,48 @@ const babelConfig = require('js-build-tools/babel.config')
136
150
  module.exports = babelConfig
137
151
  ```
138
152
 
153
+ ### Configure HTML JS Documentation (optional)
154
+
155
+ It may be desirable to generate HTML documentation for your JS files.
156
+
157
+ Create a `.jsdoc.conf.js` file and add the following:
158
+
159
+ ```js
160
+ const jsDocBase = require('js-build-tools/jsdoc.base')
161
+ /* You will get a jsdoc config object with the following:
162
+ * {
163
+ * plugins: ['plugins/markdown'],
164
+ * source: {
165
+ * include: [your configured distPath],
166
+ * includePattern: '.+\\.js(doc|x)?$',
167
+ * excludePattern: '((^|\\/|\\\\)_|.+\\.test\\..*)'
168
+ * }
169
+ * }
170
+ * You can manipulate the properties before returning in module.exports.
171
+ * This searches the defined 'distPath' for building the HTML JS Documentation
172
+ */
173
+ module.exports = jsDocBase
174
+ ```
175
+
176
+ ### Configure SASS (optional)
177
+
178
+ SASS support is built-in, this enables conversion of SASS files to CSS for web projects.
179
+
180
+ Add the following to the exports in your `build-tools.config.js`:
181
+
182
+ ```js
183
+ module.exports = {
184
+ // Output directory for your compiled css files, recommend css directory within your browser output directory
185
+ css: 'browser/css',
186
+ // Optional but nice to add (future support), add the directory where your sass files exist
187
+ sassPath: 'sass',
188
+ // Search pattern to find your SASS files (the below would be files ending in .scss or .sass in a directory called 'sass')
189
+ sassSearch: 'sass/**/*.+(scss|sass)',
190
+ // Enable SASS process
191
+ useSass: true,
192
+ }
193
+ ```
194
+
139
195
  ### Configure TypeScript (optional)
140
196
 
141
197
  Create a `tsconfig.json` file in your project root with the following:
@@ -188,7 +244,9 @@ In your `package.json` file, add the following scripts:
188
244
  "scripts": {
189
245
  "build": "gulp build",
190
246
  "dev": "gulp",
247
+ "htmldocs": "jsdoc -R MAIN.md -c ./.jsdoc.conf.js -d docs",
191
248
  "readme": "gulp readme",
249
+ "sass": "gulp sass",
192
250
  "test": "gulp testFull",
193
251
  "test:quick": "gulp testQuick",
194
252
  "watch": "gulp watchFull",
@@ -612,6 +670,7 @@ Micro-functions used as components for the main gulp functions.
612
670
 
613
671
  * [partials](#module_partials)
614
672
  * [.tsFor([srcPath], [distPath])](#module_partials.tsFor) ⇒ <code>function</code>
673
+ * [.sassFor([srcSearch], [cssPath])](#module_partials.sassFor) ⇒ <code>stream.Stream</code>
615
674
  * [.runOnChange(path)](#module_partials.runOnChange) ⇒ <code>stream.Stream</code>
616
675
  * [~pathRegex](#module_partials.runOnChange..pathRegex)
617
676
  * [.removeDirectory(dirPath)](#module_partials.removeDirectory) ⇒ <code>Promise.&lt;\*&gt;</code>
@@ -637,6 +696,18 @@ Starting at the source directory, find all the ts files and convert them into th
637
696
  | [srcPath] | <code>string</code> \| <code>array</code> | <code>&quot;&#x27;&#x27;&quot;</code> |
638
697
  | [distPath] | <code>string</code> | <code>&quot;&#x27;&#x27;&quot;</code> |
639
698
 
699
+ <a name="module_partials.sassFor"></a>
700
+
701
+ ### partials.sassFor([srcSearch], [cssPath]) ⇒ <code>stream.Stream</code>
702
+ Build the CSS for a given source pattern.
703
+
704
+ **Kind**: static method of [<code>partials</code>](#module_partials)
705
+
706
+ | Param | Type | Default |
707
+ | --- | --- | --- |
708
+ | [srcSearch] | <code>string</code> \| <code>array</code> | <code>&quot;&#x27;src/config/path/sass/for&#x27;&quot;</code> |
709
+ | [cssPath] | <code>string</code> | <code>&quot;&#x27;css/config/path&#x27;&quot;</code> |
710
+
640
711
  <a name="module_partials.runOnChange"></a>
641
712
 
642
713
  ### partials.runOnChange(path) ⇒ <code>stream.Stream</code>
package/dist/build.js CHANGED
@@ -1,48 +1,53 @@
1
- 'use strict'
2
-
3
- const bundle = require('./bundle')
4
- const bundleLint = require('./bundleLint')
5
- const bundleMinify = require('./bundleMinify')
6
- const {
7
- clean,
8
- distSeries
9
- } = require('./partials')
10
- const compileReadme = require('./compileReadme')
11
- const distLint = require('./distLint')
12
- const distMinify = require('./distMinify')
13
- const {
14
- parallel,
15
- series
16
- } = require('gulp')
17
- const gulpConfig = require('../gulp.config.js')
18
- const testFull = require('./testFull')
19
-
1
+ 'use strict'
2
+
3
+ const bundle = require('./bundle')
4
+ const bundleLint = require('./bundleLint')
5
+ const bundleMinify = require('./bundleMinify')
6
+ const {
7
+ clean,
8
+ distSeries
9
+ } = require('./partials')
10
+ const compileReadme = require('./compileReadme')
11
+ const distLint = require('./distLint')
12
+ const distMinify = require('./distMinify')
13
+ const {
14
+ parallel,
15
+ series
16
+ } = require('gulp')
17
+ const gulpConfig = require('../gulp.config.js')
18
+ const sass = require('./sass.js')
19
+ const testFull = require('./testFull')
20
+
20
21
  /**
21
22
  * Runs several processes to build and validate the project.
22
23
  * Cleans, distributes (lint and minify), bundles (lint and minify), creates the readme, then runs the tests.
23
24
  * @memberOf module:js-build-tools
24
25
  * @returns {stream.Stream}
25
- */
26
- const build = function () {
27
- const done = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null
28
- const distLintMinify = parallel(distLint, distMinify)
29
- const bundleLintMinify = parallel(bundleLint, bundleMinify)
30
- const buildActions = [clean, distSeries(), distLintMinify]
31
- if (gulpConfig.get('useTsConfig')) {
32
- // For ts usage, we need to run the readme on the dist directly since that is where the .js files are located
33
- buildActions.push(compileReadme)
34
- }
35
- if (!gulpConfig.get('nodeOnly')) {
36
- // If not 'nodeOnly' then we also want to bundle for browser after we complete the dist directory
37
- buildActions.push(bundle)
38
- buildActions.push(bundleLintMinify)
39
- }
40
- const runActions = [series(...buildActions)]
41
- if (!gulpConfig.get('useTsConfig')) {
42
- // Since we didn't run this in series after dist because of typescript, we need to run it now. Potentially faster here.
43
- runActions.push(compileReadme)
44
- }
45
- runActions.push(testFull)
46
- return parallel(...runActions)(done)
47
- }
48
- module.exports = build
26
+ */
27
+ const build = function () {
28
+ const done = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null
29
+ const distLintMinify = parallel(distLint, distMinify)
30
+ const bundleLintMinify = parallel(bundleLint, bundleMinify)
31
+ const buildActions = [clean, distSeries(), distLintMinify]
32
+ if (gulpConfig.get('useTsConfig')) {
33
+ // For ts usage, we need to run the readme on the dist directly since that is where the .js files are located
34
+ buildActions.push(compileReadme)
35
+ }
36
+ if (!gulpConfig.get('nodeOnly')) {
37
+ // If not 'nodeOnly' then we also want to bundle for browser after we complete the dist directory
38
+ buildActions.push(bundle)
39
+ buildActions.push(bundleLintMinify)
40
+ }
41
+ const runActions = [series(...buildActions)]
42
+ if (!gulpConfig.get('useTsConfig')) {
43
+ // Since we didn't run this in series after dist because of typescript, we need to run it now. Potentially faster here.
44
+ runActions.push(compileReadme)
45
+ }
46
+ runActions.push(testFull)
47
+ if (gulpConfig.get('useSass')) {
48
+ // Since we didn't run this in series after dist because of typescript, we need to run it now. Potentially faster here.
49
+ runActions.push(sass)
50
+ }
51
+ return parallel(...runActions)(done)
52
+ }
53
+ module.exports = build
package/dist/build.min.js CHANGED
@@ -1 +1 @@
1
- "use strict";const bundle=require("./bundle"),bundleLint=require("./bundleLint"),bundleMinify=require("./bundleMinify"),{clean:clean,distSeries:distSeries}=require("./partials"),compileReadme=require("./compileReadme"),distLint=require("./distLint"),distMinify=require("./distMinify"),{parallel:parallel,series:series}=require("gulp"),gulpConfig=require("../gulp.config.js"),testFull=require("./testFull"),build=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;const i=parallel(distLint,distMinify),l=parallel(bundleLint,bundleMinify),u=[clean,distSeries(),i];gulpConfig.get("useTsConfig")&&u.push(compileReadme),gulpConfig.get("nodeOnly")||(u.push(bundle),u.push(l));const n=[series(...u)];return gulpConfig.get("useTsConfig")||n.push(compileReadme),n.push(testFull),parallel(...n)(e)};module.exports=build;
1
+ "use strict";const bundle=require("./bundle"),bundleLint=require("./bundleLint"),bundleMinify=require("./bundleMinify"),{clean:clean,distSeries:distSeries}=require("./partials"),compileReadme=require("./compileReadme"),distLint=require("./distLint"),distMinify=require("./distMinify"),{parallel:parallel,series:series}=require("gulp"),gulpConfig=require("../gulp.config.js"),sass=require("./sass.js"),testFull=require("./testFull"),build=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;const i=parallel(distLint,distMinify),l=parallel(bundleLint,bundleMinify),s=[clean,distSeries(),i];gulpConfig.get("useTsConfig")&&s.push(compileReadme),gulpConfig.get("nodeOnly")||(s.push(bundle),s.push(l));const u=[series(...s)];return gulpConfig.get("useTsConfig")||u.push(compileReadme),u.push(testFull),gulpConfig.get("useSass")&&u.push(sass),parallel(...u)(e)};module.exports=build;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ const {
4
+ dest,
5
+ src
6
+ } = require('gulp');
7
+ const gulpConfig = require('../../gulp.config.js');
8
+ const cssnano = require('gulp-cssnano');
9
+ const rename = require('gulp-rename');
10
+ const sass = require('gulp-sass')(require('sass'));
11
+
12
+ /**
13
+ * Build the CSS for a given source pattern.
14
+ * @function
15
+ * @memberOf module:partials
16
+ * @param {string|array} [srcSearch='src/config/path/sass/for']
17
+ * @param {string} [cssPath='css/config/path']
18
+ * @returns {stream.Stream}
19
+ */
20
+ const sassFor = function () {
21
+ let srcSearch = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : gulpConfig.get('sassSearch');
22
+ let cssPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : gulpConfig.get('cssPath');
23
+ return src(srcSearch).pipe(sass().on('error', sass.logError)) // Passes it through a gulp-sass, log errors to console
24
+ .pipe(dest(cssPath)).pipe(cssnano()).pipe(rename({
25
+ extname: '.min.css'
26
+ })).pipe(dest(cssPath));
27
+ };
28
+ module.exports = sassFor;
package/dist/partials.js CHANGED
@@ -1,5 +1,5 @@
1
- 'use strict'
2
-
1
+ 'use strict'
2
+
3
3
  /**
4
4
  * Micro-functions used as components for the main gulp functions.
5
5
  * @file
@@ -7,29 +7,31 @@
7
7
  * @version 2.0.0
8
8
  * @module partials
9
9
  * @memberOf module:js-build-tools
10
- */
11
-
12
- const addToReadme = require('./partials/addToReadme')
13
- const beginWatcher = require('./partials/beginWatcher')
14
- const clean = require('./partials/clean')
15
- const distFor = require('./partials/distFor')
16
- const distForSrc = require('./partials/distForSrc')
17
- const distSeries = require('./partials/distSeries')
18
- const minifyFor = require('./partials/minifyFor')
19
- const readmeTemplate = require('./partials/readmeTemplate')
20
- const removeDirectory = require('./partials/removeDirectory')
21
- const runOnChange = require('./partials/runOnChange')
22
- const tsFor = require('./partials/tsFor')
23
- module.exports = {
24
- addToReadme,
25
- beginWatcher,
26
- clean,
27
- distFor,
28
- distForSrc,
29
- distSeries,
30
- minifyFor,
31
- readmeTemplate,
32
- removeDirectory,
33
- runOnChange,
34
- tsFor
35
- }
10
+ */
11
+
12
+ const addToReadme = require('./partials/addToReadme')
13
+ const beginWatcher = require('./partials/beginWatcher')
14
+ const clean = require('./partials/clean')
15
+ const distFor = require('./partials/distFor')
16
+ const distForSrc = require('./partials/distForSrc')
17
+ const distSeries = require('./partials/distSeries')
18
+ const minifyFor = require('./partials/minifyFor')
19
+ const readmeTemplate = require('./partials/readmeTemplate')
20
+ const removeDirectory = require('./partials/removeDirectory')
21
+ const runOnChange = require('./partials/runOnChange')
22
+ const sassFor = require('./partials/sassFor')
23
+ const tsFor = require('./partials/tsFor')
24
+ module.exports = {
25
+ addToReadme,
26
+ beginWatcher,
27
+ clean,
28
+ distFor,
29
+ distForSrc,
30
+ distSeries,
31
+ minifyFor,
32
+ readmeTemplate,
33
+ removeDirectory,
34
+ runOnChange,
35
+ sassFor,
36
+ tsFor
37
+ }
@@ -1 +1 @@
1
- "use strict";const addToReadme=require("./partials/addToReadme"),beginWatcher=require("./partials/beginWatcher"),clean=require("./partials/clean"),distFor=require("./partials/distFor"),distForSrc=require("./partials/distForSrc"),distSeries=require("./partials/distSeries"),minifyFor=require("./partials/minifyFor"),readmeTemplate=require("./partials/readmeTemplate"),removeDirectory=require("./partials/removeDirectory"),runOnChange=require("./partials/runOnChange"),tsFor=require("./partials/tsFor");module.exports={addToReadme:addToReadme,beginWatcher:beginWatcher,clean:clean,distFor:distFor,distForSrc:distForSrc,distSeries:distSeries,minifyFor:minifyFor,readmeTemplate:readmeTemplate,removeDirectory:removeDirectory,runOnChange:runOnChange,tsFor:tsFor};
1
+ "use strict";const addToReadme=require("./partials/addToReadme"),beginWatcher=require("./partials/beginWatcher"),clean=require("./partials/clean"),distFor=require("./partials/distFor"),distForSrc=require("./partials/distForSrc"),distSeries=require("./partials/distSeries"),minifyFor=require("./partials/minifyFor"),readmeTemplate=require("./partials/readmeTemplate"),removeDirectory=require("./partials/removeDirectory"),runOnChange=require("./partials/runOnChange"),sassFor=require("./partials/sassFor"),tsFor=require("./partials/tsFor");module.exports={addToReadme:addToReadme,beginWatcher:beginWatcher,clean:clean,distFor:distFor,distForSrc:distForSrc,distSeries:distSeries,minifyFor:minifyFor,readmeTemplate:readmeTemplate,removeDirectory:removeDirectory,runOnChange:runOnChange,sassFor:sassFor,tsFor:tsFor};
package/dist/sass.js ADDED
@@ -0,0 +1,7 @@
1
+ 'use strict'
2
+
3
+ const sassFor = require('./partials/sassFor')
4
+
5
+ // Compile sass into CSS & auto-inject into browsers
6
+ const sass = () => sassFor()
7
+ module.exports = sass
@@ -0,0 +1 @@
1
+ "use strict";const sassFor=require("./partials/sassFor"),sass=()=>sassFor();module.exports=sass;
@@ -1,73 +1,77 @@
1
- "use strict";
2
-
3
- const fs = require('fs');
4
- // Import the configurations and override some of them in order to direct to the temp directory.
5
- const gulpConfig = require('../../gulp.config.js');
6
- const {
7
- removeDirectory
8
- } = require('../partials');
9
- let tempDir = 'test-temp/';
10
- let srcPath = `${tempDir}src`;
11
-
1
+ "use strict";
2
+
3
+ const fs = require('fs');
4
+ // Import the configurations and override some of them in order to direct to the temp directory.
5
+ const gulpConfig = require('../../gulp.config.js');
6
+ const {
7
+ removeDirectory
8
+ } = require('../partials');
9
+ let tempDir = 'test-temp/';
10
+ let srcPath = `${tempDir}src`;
11
+
12
12
  /**
13
13
  * Update the gulp configurations with the test data. Set the test directory where temp files will be created for testing.
14
14
  * @function
15
15
  * @memberOf module:testHelpers
16
16
  * @param {string} testDir
17
- */
18
- const setDefaults = function () {
19
- let testDir = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'test-temp';
20
- tempDir = `${testDir}/`;
21
- srcPath = `${tempDir}src`;
22
- const distPath = `${tempDir}dist`;
23
- const browserPath = `${tempDir}browser`;
24
- gulpConfig.set('browserPath', browserPath);
25
- gulpConfig.set('cleanPaths', [distPath, browserPath]);
26
- gulpConfig.set('distMain', `${distPath}/main`);
27
- gulpConfig.set('distPath', distPath);
28
- gulpConfig.set('distSearch', `${distPath}/**/*.js`);
29
- gulpConfig.set('readmeTemplate', `${tempDir}MAIN.md`);
30
- gulpConfig.set('readmePath', tempDir);
31
- gulpConfig.set('readmeSearch', `${srcPath}/**/!(*.test).js`);
32
- gulpConfig.set('rootPath', tempDir);
33
- gulpConfig.set('srcPath', srcPath);
34
- gulpConfig.set('srcSearch', `${srcPath}/**/!(*.test).js`);
35
- gulpConfig.set('tsSearch', `${srcPath}/**/*.ts`);
36
- gulpConfig.set('watchSearch', `${srcPath}/**/*.js`);
37
- };
38
- exports.setDefaults = setDefaults;
39
- exports.gulpConfig = gulpConfig;
40
-
17
+ */
18
+ const setDefaults = function () {
19
+ let testDir = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'test-temp';
20
+ tempDir = `${testDir}/`;
21
+ srcPath = `${tempDir}src`;
22
+ const distPath = `${tempDir}dist`;
23
+ const browserPath = `${tempDir}browser`;
24
+ const sassPath = `${tempDir}sass`;
25
+ gulpConfig.set('browserPath', browserPath);
26
+ gulpConfig.set('cleanPaths', [distPath, browserPath]);
27
+ gulpConfig.set('cssPath', `${browserPath}/css`);
28
+ gulpConfig.set('distMain', `${distPath}/main`);
29
+ gulpConfig.set('distPath', distPath);
30
+ gulpConfig.set('distSearch', `${distPath}/**/*.js`);
31
+ gulpConfig.set('readmeTemplate', `${tempDir}MAIN.md`);
32
+ gulpConfig.set('readmePath', tempDir);
33
+ gulpConfig.set('readmeSearch', `${srcPath}/**/!(*.test).js`);
34
+ gulpConfig.set('rootPath', tempDir);
35
+ gulpConfig.set('sassPath', sassPath);
36
+ gulpConfig.set('sassSearch', `${sassPath}/**/*.+(scss|sass)`);
37
+ gulpConfig.set('srcPath', srcPath);
38
+ gulpConfig.set('srcSearch', `${srcPath}/**/!(*.test).js`);
39
+ gulpConfig.set('tsSearch', `${srcPath}/**/*.ts`);
40
+ gulpConfig.set('watchSearch', `${srcPath}/**/*.js`);
41
+ };
42
+ exports.setDefaults = setDefaults;
43
+ exports.gulpConfig = gulpConfig;
44
+
41
45
  /**
42
46
  * Ensure that the del has completed, recursively attempt to delete and recreate
43
47
  * @function
44
48
  * @memberOf module:testHelpers
45
49
  * @param {boolean} [exists=true]
46
50
  * @returns {Promise<*|void>}
47
- */
48
- const createTempDir = async function () {
49
- let exists = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
50
- if (exists) {
51
- return removeDirectory(tempDir).then(removedDir => createTempDir(fs.existsSync(removedDir))).catch(error => console.error('Error: ', error));
52
- }
53
- return fs.mkdirSync(srcPath, {
54
- recursive: true
55
- });
56
- };
57
- exports.createTempDir = createTempDir;
58
-
51
+ */
52
+ const createTempDir = async function () {
53
+ let exists = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
54
+ if (exists) {
55
+ return removeDirectory(tempDir).then(removedDir => createTempDir(fs.existsSync(removedDir))).catch(error => console.error('Error: ', error));
56
+ }
57
+ return fs.mkdirSync(srcPath, {
58
+ recursive: true
59
+ });
60
+ };
61
+ exports.createTempDir = createTempDir;
62
+
59
63
  /**
60
64
  * In the Jest.beforeEach function call this one to set up the temp directory.
61
65
  * @function
62
66
  * @memberOf module:testHelpers
63
67
  * @returns {Promise<*|void>}
64
- */
65
- exports.beforeEach = () => createTempDir();
66
-
68
+ */
69
+ exports.beforeEach = () => createTempDir();
70
+
67
71
  /**
68
72
  * In the Jest.afterEach function call this one to clean up and remove the temp directory.
69
73
  * @function
70
74
  * @memberOf module:testHelpers
71
75
  * @returns {Promise<*>}
72
- */
76
+ */
73
77
  exports.afterEach = () => removeDirectory(tempDir);
@@ -7,6 +7,7 @@ const distLint = require('./distLint')
7
7
  const distMinify = require('./distMinify')
8
8
  const { parallel, series } = require('gulp')
9
9
  const gulpConfig = require('../gulp.config.js')
10
+ const sass = require('./sass.js')
10
11
  const testFull = require('./testFull')
11
12
 
12
13
  /**
@@ -36,6 +37,10 @@ const build = (done = null) => {
36
37
  runActions.push(compileReadme)
37
38
  }
38
39
  runActions.push(testFull)
40
+ if (gulpConfig.get('useSass')) {
41
+ // Since we didn't run this in series after dist because of typescript, we need to run it now. Potentially faster here.
42
+ runActions.push(sass)
43
+ }
39
44
  return parallel(
40
45
  ...runActions
41
46
  )(done)
@@ -4,6 +4,7 @@ setUp.setDefaults('test-build')
4
4
  const gulpConfig = setUp.gulpConfig
5
5
  const build = require('./build')
6
6
  const clean = require('./partials/clean')
7
+ const sass = require('./sass')
7
8
  const testFull = require('./testFull')
8
9
  const { countMatches } = require('./testHelpers')
9
10
 
@@ -78,6 +79,27 @@ const tsConfigContents = '{\n' +
78
79
  ' }\n' +
79
80
  '}'
80
81
 
82
+ const sassContents = 'html\n' +
83
+ ' font-size: 62.5%\n' +
84
+ ' color: #444\n' +
85
+ ' font-size: 1em\n' +
86
+ ' line-height: 1.4\n' +
87
+ ' background-color: #fff\n' +
88
+ '\n' +
89
+ 'html, body\n' +
90
+ ' width: 100%\n' +
91
+ ' height: 100%\n' +
92
+ ' margin: 0\n' +
93
+ ' padding: 0\n' +
94
+ ' position: absolute\n' +
95
+ ' text-align: center\n' +
96
+ '\n' +
97
+ 'a\n' +
98
+ ' outline: none\n' +
99
+ ' text-decoration: none'
100
+
101
+ const sassPath = gulpConfig.get('sassPath')
102
+
81
103
  beforeEach(
82
104
  () => setUp.beforeEach()
83
105
  .then(
@@ -86,6 +108,7 @@ beforeEach(
86
108
  const readmePath = gulpConfig.get('readmePath')
87
109
  const sourcesPath = `${srcPath}/sources`
88
110
  await fs.mkdirSync(sourcesPath)
111
+ await fs.mkdirSync(sassPath, { recursive: true })
89
112
  return fs.writeFileSync(`${readmePath}/MAIN.md`, mainMd)
90
113
  }
91
114
  )
@@ -189,6 +212,66 @@ describe('build', () => {
189
212
  })
190
213
  }, 30000)
191
214
 
215
+ test('when nodeOnly false and useSass true: calls clean, distSeries, distLint, distMinify, bundle, bundleLint, bundleMinify, compileReadme, testFull, sass', done => {
216
+ const srcPath = gulpConfig.get('srcPath')
217
+ const sourcesPath = `${srcPath}/sources`
218
+ const distPath = gulpConfig.get('distPath')
219
+ const browserFile = gulpConfig.get('browserName')
220
+ const browserPath = gulpConfig.get('browserPath')
221
+ const bundledFile = `${browserPath}/${browserFile}.js`
222
+ const readmePath = gulpConfig.get('readmePath')
223
+ const readmeFile = gulpConfig.get('readmeFile')
224
+ const sassFile = `${sassPath}/sassFor.sass`
225
+ fs.writeFileSync(sassFile, sassContents)
226
+ fs.writeFileSync(`${sourcesPath}/file1.js`, file1Contents)
227
+ fs.writeFileSync(`${sourcesPath}/file2.js`, file2Contents)
228
+ fs.writeFileSync(`${srcPath}/main.js`, mainFileContents)
229
+ gulpConfig.set('nodeOnly', false)
230
+ gulpConfig.set('useSass', true)
231
+ expect.assertions(16)
232
+ build(() => {
233
+ // Called 'clean'
234
+ expect(clean).toHaveBeenCalled()
235
+
236
+ // Created dist directory (distSeries)
237
+ expect(fs.existsSync(distPath)).toBeTruthy()
238
+
239
+ // Minify the dist files (distMinify)
240
+ expect(fs.existsSync(`${distPath}/main.min.js`)).toBeTruthy()
241
+ const babelifiedMain = fs.readFileSync(`${distPath}/main.js`).toString()
242
+ // Used single quotes because of distLint
243
+ expect(countMatches(babelifiedMain, '\'use strict\'')).toEqual(1)
244
+
245
+ // Created browser directory (bundle)
246
+ expect(fs.existsSync(browserPath)).toBeTruthy()
247
+
248
+ // Minify the browser files (bundleMinify)
249
+ expect(fs.existsSync(`${browserPath}/${browserFile}.min.js`)).toBeTruthy()
250
+ const bundledContents = fs.readFileSync(bundledFile).toString()
251
+ expect(countMatches(bundledContents, 'file1')).toEqual(7)
252
+ expect(countMatches(bundledContents, 'file2')).toEqual(7)
253
+
254
+ // Generated README.md (compileReadme)
255
+ const readmeContents = fs.readFileSync(`${readmePath}/${readmeFile}`).toString()
256
+ expect(countMatches(readmeContents, mainMd)).toEqual(1)
257
+ expect(countMatches(readmeContents, 'test-build')).toEqual(4)
258
+ expect(countMatches(readmeContents, 'file1')).toEqual(4)
259
+ expect(countMatches(readmeContents, 'file2')).toEqual(4)
260
+
261
+ // Ran 'testFull'
262
+ expect(testFull).toHaveBeenCalled()
263
+
264
+ // Ran 'sass'
265
+ const cssPath = gulpConfig.get('cssPath')
266
+ const cssContents = fs.readFileSync(`${cssPath}/sassFor.css`).toString()
267
+ expect(countMatches(cssContents, ';')).toEqual(13)
268
+ expect(countMatches(cssContents, '{')).toEqual(3)
269
+ expect(countMatches(cssContents, '}')).toEqual(3)
270
+
271
+ done()
272
+ })
273
+ }, 30000)
274
+
192
275
  test('when nodeOnly true and useTsConfig set: calls clean, tsFor, distFor, distLint, distMinify, compileReadme, testFull', done => {
193
276
  const srcPath = gulpConfig.get('srcPath')
194
277
  const rootPath = gulpConfig.get('rootPath')
@@ -0,0 +1,22 @@
1
+ const { dest, src } = require('gulp')
2
+ const gulpConfig = require('../../gulp.config.js')
3
+ const cssnano = require('gulp-cssnano')
4
+ const rename = require('gulp-rename')
5
+ const sass = require('gulp-sass')(require('sass'))
6
+
7
+ /**
8
+ * Build the CSS for a given source pattern.
9
+ * @function
10
+ * @memberOf module:partials
11
+ * @param {string|array} [srcSearch='src/config/path/sass/for']
12
+ * @param {string} [cssPath='css/config/path']
13
+ * @returns {stream.Stream}
14
+ */
15
+ const sassFor = (srcSearch = gulpConfig.get('sassSearch'), cssPath = gulpConfig.get('cssPath')) => src(srcSearch)
16
+ .pipe(sass().on('error', sass.logError)) // Passes it through a gulp-sass, log errors to console
17
+ .pipe(dest(cssPath))
18
+ .pipe(cssnano())
19
+ .pipe(rename({ extname: '.min.css' }))
20
+ .pipe(dest(cssPath))
21
+
22
+ module.exports = sassFor
@@ -0,0 +1,62 @@
1
+ const fs = require('fs')
2
+ const setUp = require('../test-helpers/setUp')
3
+ setUp.setDefaults('test-sass-for')
4
+ const gulpConfig = setUp.gulpConfig
5
+ const sassFor = require('./sassFor')
6
+ const { countMatches, logObject } = require('../testHelpers')
7
+
8
+ const sassContents = 'html\n' +
9
+ ' font-size: 62.5%\n' +
10
+ ' color: #444\n' +
11
+ ' font-size: 1em\n' +
12
+ ' line-height: 1.4\n' +
13
+ ' background-color: #fff\n' +
14
+ '\n' +
15
+ 'html, body\n' +
16
+ ' width: 100%\n' +
17
+ ' height: 100%\n' +
18
+ ' margin: 0\n' +
19
+ ' padding: 0\n' +
20
+ ' position: absolute\n' +
21
+ ' text-align: center\n' +
22
+ '\n' +
23
+ 'a\n' +
24
+ ' outline: none\n' +
25
+ ' text-decoration: none'
26
+
27
+ const sassPath = gulpConfig.get('sassPath')
28
+
29
+ beforeEach(() => {
30
+ setUp.beforeEach()
31
+ return fs.mkdirSync(sassPath, { recursive: true })
32
+ })
33
+
34
+ afterEach(setUp.afterEach)
35
+
36
+ describe('sassFor', () => {
37
+ test('copies the sass directory and converts it into css output', done => {
38
+ const sassFile = `${sassPath}/sassFor.sass`
39
+ fs.writeFileSync(sassFile, sassContents)
40
+ expect.assertions(7)
41
+ const oldContents = fs.readFileSync(sassFile).toString()
42
+ expect(countMatches(oldContents, ';')).toEqual(0)
43
+ expect(countMatches(oldContents, ' {')).toEqual(0)
44
+ expect(countMatches(oldContents, '\n' +
45
+ ' }')).toEqual(0)
46
+ const cssPath = gulpConfig.get('cssPath')
47
+ sassFor(sassFile)
48
+ .on('finish', () => {
49
+ expect(fs.existsSync(cssPath)).toBeTruthy()
50
+ const cssContents = fs.readFileSync(`${cssPath}/sassFor.css`).toString()
51
+ // Will add braces and semicolons
52
+ expect(countMatches(cssContents, ';')).toEqual(13)
53
+ expect(countMatches(cssContents, '{')).toEqual(3)
54
+ expect(countMatches(cssContents, '}')).toEqual(3)
55
+ done()
56
+ })
57
+ .on('error', error => {
58
+ console.error('Encountered error', error)
59
+ done()
60
+ })
61
+ })
62
+ })
@@ -17,6 +17,7 @@ const minifyFor = require('./partials/minifyFor')
17
17
  const readmeTemplate = require('./partials/readmeTemplate')
18
18
  const removeDirectory = require('./partials/removeDirectory')
19
19
  const runOnChange = require('./partials/runOnChange')
20
+ const sassFor = require('./partials/sassFor')
20
21
  const tsFor = require('./partials/tsFor')
21
22
 
22
23
  module.exports = {
@@ -30,5 +31,6 @@ module.exports = {
30
31
  readmeTemplate,
31
32
  removeDirectory,
32
33
  runOnChange,
34
+ sassFor,
33
35
  tsFor,
34
36
  }
@@ -2,6 +2,6 @@ const partials = require('./partials')
2
2
 
3
3
  describe('partials', () => {
4
4
  test('is object with all partial exports', () => {
5
- expect(Object.keys(partials).length).toBe(11)
5
+ expect(Object.keys(partials).length).toBe(12)
6
6
  })
7
7
  })
@@ -0,0 +1,6 @@
1
+ const sassFor = require('./partials/sassFor')
2
+
3
+ // Compile sass into CSS & auto-inject into browsers
4
+ const sass = () => sassFor()
5
+
6
+ module.exports = sass
@@ -0,0 +1,30 @@
1
+ const fs = require('fs')
2
+ const setUp = require('./test-helpers/setUp')
3
+ setUp.setDefaults('test-sass')
4
+ const gulpConfig = setUp.gulpConfig
5
+ const sass = require('./sass')
6
+
7
+ beforeEach(() => setUp.beforeEach().then(
8
+ () => {
9
+ const sassPath = gulpConfig.get('sassPath')
10
+ return fs.mkdirSync(sassPath, { recursive: true })
11
+ }
12
+ ))
13
+
14
+ afterEach(setUp.afterEach)
15
+
16
+ describe('sass', () => {
17
+ test('uses the configured paths', done => {
18
+ const sassPath = gulpConfig.get('sassPath')
19
+ expect.assertions(1)
20
+ sass()
21
+ .on('finish', () => {
22
+ expect(fs.existsSync(sassPath)).toBeTruthy()
23
+ done()
24
+ })
25
+ .on('error', error => {
26
+ console.error('Encountered error', error)
27
+ done()
28
+ })
29
+ }, 10000)
30
+ })
@@ -17,8 +17,10 @@ const setDefaults = (testDir = 'test-temp') => {
17
17
  srcPath = `${tempDir}src`
18
18
  const distPath = `${tempDir}dist`
19
19
  const browserPath = `${tempDir}browser`
20
+ const sassPath = `${tempDir}sass`
20
21
  gulpConfig.set('browserPath', browserPath)
21
22
  gulpConfig.set('cleanPaths', [distPath, browserPath])
23
+ gulpConfig.set('cssPath', `${browserPath}/css`)
22
24
  gulpConfig.set('distMain', `${distPath}/main`)
23
25
  gulpConfig.set('distPath', distPath)
24
26
  gulpConfig.set('distSearch', `${distPath}/**/*.js`)
@@ -26,6 +28,8 @@ const setDefaults = (testDir = 'test-temp') => {
26
28
  gulpConfig.set('readmePath', tempDir)
27
29
  gulpConfig.set('readmeSearch', `${srcPath}/**/!(*.test).js`)
28
30
  gulpConfig.set('rootPath', tempDir)
31
+ gulpConfig.set('sassPath', sassPath)
32
+ gulpConfig.set('sassSearch', `${sassPath}/**/*.+(scss|sass)`)
29
33
  gulpConfig.set('srcPath', srcPath)
30
34
  gulpConfig.set('srcSearch', `${srcPath}/**/!(*.test).js`)
31
35
  gulpConfig.set('tsSearch', `${srcPath}/**/*.ts`)
package/gulp.config.js CHANGED
@@ -113,6 +113,7 @@ const setDefaults = {
113
113
  browserName: 'default',
114
114
  browserPath: 'browser',
115
115
  cleanPaths: ['dist', 'browser'],
116
+ cssPath: 'browser/css',
116
117
  distMain: 'dist/main',
117
118
  distPath: 'dist',
118
119
  distSearch: 'dist/**/*.js',
@@ -123,6 +124,8 @@ const setDefaults = {
123
124
  readmePath: './',
124
125
  readmeSearch: 'src/**/!(*.test).js',
125
126
  rootPath: './',
127
+ sassPath: 'sass',
128
+ sassSearch: 'sass/**/*.+(scss|sass)',
126
129
  srcPath: 'src',
127
130
  srcSearch: 'src/**/!(*.test).js',
128
131
  testOptions: {
@@ -138,6 +141,7 @@ const setDefaults = {
138
141
  },
139
142
  testPath: ['src'],
140
143
  tsSearch: 'src/**/*.ts',
144
+ useSass: false,
141
145
  useTsConfig: false,
142
146
  watchSearch: 'src/**/*.js'
143
147
  }
package/gulpfile.base.js CHANGED
@@ -17,6 +17,7 @@ const distLint = require('./functions/distLint.js')
17
17
  const distMinify = require('./functions/distMinify.js')
18
18
  const gulpConfig = require('./gulp.config.js')
19
19
  const partials = require('./functions/partials.js')
20
+ const sass = require('./functions/sass.js')
20
21
  const testFull = require('./functions/testFull.js')
21
22
  const testHelpers = require('./functions/testHelpers.js')
22
23
  const testQuick = require('./functions/testQuick.js')
@@ -36,6 +37,7 @@ module.exports = {
36
37
  gulpConfig,
37
38
  partials,
38
39
  readme: compileReadme,
40
+ sass,
39
41
  testFull,
40
42
  testHelpers,
41
43
  testQuick,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-build-tools",
3
- "version": "2.2.12",
3
+ "version": "2.3.0",
4
4
  "description": "Standardised build process with gulp.",
5
5
  "main": "gulpfile.base.js",
6
6
  "scripts": {
@@ -45,7 +45,9 @@
45
45
  "glob": "^10.3.10",
46
46
  "gulp": "^4.0.2",
47
47
  "gulp-babel": "^8.0.0",
48
+ "gulp-cssnano": "^2.1.3",
48
49
  "gulp-rename": "^2.0.0",
50
+ "gulp-sass": "^5.1.0",
49
51
  "gulp-standard": "^14.0.0",
50
52
  "gulp-typescript": "^6.0.0-alpha.1",
51
53
  "gulp-uglify-es": "^3.0.0",
@@ -53,6 +55,7 @@
53
55
  "jest-environment-jsdom": "^29.7.0",
54
56
  "jsdoc-to-markdown": "^8.0.0",
55
57
  "regenerator-runtime": "^0.14.1",
58
+ "sass": "^1.69.7",
56
59
  "vinyl-source-stream": "^2.0.0"
57
60
  },
58
61
  "files": [