js-build-tools 5.0.0 → 5.1.1
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/babel.config.js +18 -1
- package/dist/partials/addToReadme.js +17 -17
- package/dist/partials/beginWatcher.js +12 -12
- package/dist/partials/clean.js +14 -14
- package/dist/partials/distFor.js +21 -21
- package/dist/partials/distForSrc.js +11 -11
- package/dist/partials/distSeries.js +19 -19
- package/dist/partials/minifyFor.js +16 -16
- package/dist/partials/readmeTemplate.js +14 -14
- package/dist/partials/runOnChange.js +28 -28
- package/dist/partials/sassFor.js +28 -28
- package/dist/partials/tsFor.js +89 -67
- package/dist/test-helpers/setUp.js +89 -89
- package/dist/utilities/dotGet.js +46 -46
- package/dist/utilities/dotNotate.js +46 -46
- package/dist/utilities/dotSet.js +37 -37
- package/dist/utilities/isObject.js +8 -8
- package/dist/utilities/strAfter.js +11 -11
- package/dist/utilities/strBefore.js +11 -11
- package/functions/partials/tsFor.mjs +25 -3
- package/functions/partials/tsFor.test.mjs +11 -1
- package/package.json +6 -2
package/dist/partials/tsFor.js
CHANGED
|
@@ -1,37 +1,58 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.tsFor = void 0;
|
|
8
|
-
var _gulp = require("gulp");
|
|
9
|
-
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
10
|
-
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
11
|
-
var
|
|
12
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
-
// gulp-ts-compile ships ESM-only (no CJS build - see its own package.json) since it's meant to be consumed by
|
|
15
|
-
// gulpfiles running under a real ESM loader, same as this project's own gulpfile.mjs does. This project also
|
|
16
|
-
// compiles itself to a CommonJS build (dist/*.js, this file's own compiled counterpart) for consumers using
|
|
17
|
-
// require() though, and even a dynamic `import()` gets downleveled by babel's CommonJS transform into a
|
|
18
|
-
// require() call - which can't load a real ES module. Hiding the import() call inside a Function constructor is
|
|
19
|
-
// the standard escape hatch: babel can't see (and so can't rewrite) an import expression that only exists as a
|
|
20
|
-
// runtime-evaluated string, so it survives as a genuine dynamic import, capable of loading gulp-ts-compile from
|
|
21
|
-
// either build.
|
|
22
|
-
const importGulpTsCompile = new Function('return import(\'gulp-ts-compile\')');
|
|
23
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.tsFor = exports.loadTypescript = void 0;
|
|
8
|
+
var _gulp = require("gulp");
|
|
9
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
10
|
+
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
11
|
+
var _nodeModule = require("node:module");
|
|
12
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
// gulp-ts-compile ships ESM-only (no CJS build - see its own package.json) since it's meant to be consumed by
|
|
15
|
+
// gulpfiles running under a real ESM loader, same as this project's own gulpfile.mjs does. This project also
|
|
16
|
+
// compiles itself to a CommonJS build (dist/*.js, this file's own compiled counterpart) for consumers using
|
|
17
|
+
// require() though, and even a dynamic `import()` gets downleveled by babel's CommonJS transform into a
|
|
18
|
+
// require() call - which can't load a real ES module. Hiding the import() call inside a Function constructor is
|
|
19
|
+
// the standard escape hatch: babel can't see (and so can't rewrite) an import expression that only exists as a
|
|
20
|
+
// runtime-evaluated string, so it survives as a genuine dynamic import, capable of loading gulp-ts-compile from
|
|
21
|
+
// either build.
|
|
22
|
+
const importGulpTsCompile = new Function('return import(\'gulp-ts-compile\')');
|
|
23
|
+
|
|
24
24
|
/**
|
|
25
25
|
* Wrap a stream in a promise that resolves once it finishes writing.
|
|
26
26
|
* @memberOf module:partials
|
|
27
27
|
* @param {import('node:stream').Stream} stream
|
|
28
28
|
* @returns {Promise<void>}
|
|
29
|
-
*/
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
*/
|
|
30
|
+
const installHint = 'Install it in your project with: npm install --save-dev typescript';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Load the project's own copy of TypeScript (an optional peer dependency, only needed when the typescript task is
|
|
34
|
+
* enabled) from the project being built, so projects which do not use TypeScript never need it installed.
|
|
35
|
+
* @memberOf module:partials
|
|
36
|
+
* @param {string} [projectPath=process.cwd()] The folder of the project (which has the package.json) being built.
|
|
37
|
+
* @returns {Object} The TypeScript compiler API module.
|
|
38
|
+
* @throws {Error} With install instructions when typescript is not installed.
|
|
39
|
+
*/
|
|
40
|
+
const loadTypescript = (projectPath = process.cwd()) => {
|
|
41
|
+
try {
|
|
42
|
+
return (0, _nodeModule.createRequire)(_nodePath.default.join(projectPath, 'package.json'))('typescript');
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (error.code === 'MODULE_NOT_FOUND' && /Cannot find module 'typescript'/.test(error.message)) {
|
|
45
|
+
throw new Error(`The typescript task needs the optional peer dependency typescript, which is not installed. ${installHint}`);
|
|
46
|
+
}
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
exports.loadTypescript = loadTypescript;
|
|
51
|
+
const streamToPromise = stream => new Promise((resolve, reject) => {
|
|
52
|
+
stream.on('finish', resolve);
|
|
53
|
+
stream.on('error', reject);
|
|
54
|
+
});
|
|
55
|
+
|
|
35
56
|
/**
|
|
36
57
|
* Read a tsconfig.json file into real typescript.CompilerOptions values, using only TypeScript's stable, current,
|
|
37
58
|
* public config-reading API (the same one `tsc --project` itself uses internally) - never
|
|
@@ -40,13 +61,13 @@ const streamToPromise = stream => new Promise((resolve, reject) => {
|
|
|
40
61
|
* @memberOf module:partials
|
|
41
62
|
* @param {string} configPath - Path to a tsconfig.json file.
|
|
42
63
|
* @returns {import('typescript').CompilerOptions}
|
|
43
|
-
*/
|
|
44
|
-
const readCompilerOptions = configPath => {
|
|
45
|
-
const configFile =
|
|
46
|
-
const parsedConfig =
|
|
47
|
-
return parsedConfig.options;
|
|
48
|
-
};
|
|
49
|
-
|
|
64
|
+
*/
|
|
65
|
+
const readCompilerOptions = (ts, configPath) => {
|
|
66
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
67
|
+
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, _nodePath.default.dirname(configPath));
|
|
68
|
+
return parsedConfig.options;
|
|
69
|
+
};
|
|
70
|
+
|
|
50
71
|
/**
|
|
51
72
|
* Starting at the source directory, find all the ts files and convert them into the distribution directory.
|
|
52
73
|
* @memberOf module:partials
|
|
@@ -59,35 +80,36 @@ const readCompilerOptions = configPath => {
|
|
|
59
80
|
* suite already covers real TypeScript-compile correctness - this function's own tests only need to verify its
|
|
60
81
|
* config resolution and stream wiring.
|
|
61
82
|
* @returns {Function}
|
|
62
|
-
*/
|
|
63
|
-
const tsFor = (srcPath = gulpConfig.get('typescript.from'), distPath = gulpConfig.get('typescript.to'), loadTsCompile = () => importGulpTsCompile().then(({
|
|
64
|
-
default: tsCompile
|
|
65
|
-
}) => tsCompile)) => {
|
|
66
|
-
if (gulpConfig.get('typescript.enabled') === false) {
|
|
67
|
-
return () => {};
|
|
68
|
-
}
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
};
|
|
83
|
+
*/
|
|
84
|
+
const tsFor = (srcPath = gulpConfig.get('typescript.from'), distPath = gulpConfig.get('typescript.to'), loadTsCompile = () => importGulpTsCompile().then(({
|
|
85
|
+
default: tsCompile
|
|
86
|
+
}) => tsCompile)) => {
|
|
87
|
+
if (gulpConfig.get('typescript.enabled') === false) {
|
|
88
|
+
return () => {};
|
|
89
|
+
}
|
|
90
|
+
const ts = loadTypescript();
|
|
91
|
+
const configPath = gulpConfig.get('typescript.config');
|
|
92
|
+
// When no tsconfig.json is configured, target/module are pinned explicitly rather than left for TypeScript's
|
|
93
|
+
// own compiler defaults - those defaults have already shifted once across a TypeScript version bump in this
|
|
94
|
+
// project's own history (silently changing whether output keeps `const`/`let` or downlevels to `var`), and
|
|
95
|
+
// pinning them keeps this task's output stable across future TypeScript upgrades too. ES5/CommonJS matches
|
|
96
|
+
// what the downstream babel/browserify bundling pipeline has always assumed it receives.
|
|
97
|
+
const compilerOptions = configPath ? readCompilerOptions(ts, configPath) : {
|
|
98
|
+
declaration: true,
|
|
99
|
+
target: ts.ScriptTarget.ES5,
|
|
100
|
+
module: ts.ModuleKind.CommonJS,
|
|
101
|
+
esModuleInterop: false
|
|
102
|
+
};
|
|
103
|
+
// Accepts gulp's own callback-style task convention (an optional `done`, called once finished) rather than
|
|
104
|
+
// just returning a Promise, since callers may invoke the returned function directly with a callback instead
|
|
105
|
+
// of relying on gulp's own runner to observe a returned Promise.
|
|
106
|
+
return done => {
|
|
107
|
+
const compile = async () => {
|
|
108
|
+
const tsCompile = await loadTsCompile();
|
|
109
|
+
const tsResult = (0, _gulp.src)(srcPath).pipe(tsCompile(compilerOptions));
|
|
110
|
+
await Promise.all([streamToPromise(tsResult.dts.pipe((0, _gulp.dest)(distPath))), streamToPromise(tsResult.js.pipe((0, _gulp.dest)(distPath)))]);
|
|
111
|
+
};
|
|
112
|
+
return typeof done === 'function' ? compile().then(() => done(), done) : compile();
|
|
113
|
+
};
|
|
114
|
+
};
|
|
93
115
|
exports.tsFor = tsFor;
|
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
Object.defineProperty(exports, "afterEach", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return _testFilesystem.afterEach;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
Object.defineProperty(exports, "beforeEach", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () {
|
|
16
|
-
return _testFilesystem.beforeEach;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports, "countMatches", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function () {
|
|
22
|
-
return _testFilesystem.countMatches;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
Object.defineProperty(exports, "createTempDir", {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function () {
|
|
28
|
-
return _testFilesystem.createTempDir;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
Object.defineProperty(exports, "fileExists", {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
get: function () {
|
|
34
|
-
return _testFilesystem.fileExists;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
exports.gulpConfig = void 0;
|
|
38
|
-
Object.defineProperty(exports, "logObject", {
|
|
39
|
-
enumerable: true,
|
|
40
|
-
get: function () {
|
|
41
|
-
return _testFilesystem.logObject;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
Object.defineProperty(exports, "removeDirectory", {
|
|
45
|
-
enumerable: true,
|
|
46
|
-
get: function () {
|
|
47
|
-
return _testFilesystem.removeDirectory;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
exports.setDefaults = void 0;
|
|
51
|
-
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
52
|
-
exports.gulpConfig = gulpConfig;
|
|
53
|
-
var _testFilesystem = require("test-filesystem");
|
|
54
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
55
|
-
// Import the configurations and override some of them to direct to the temp directory.
|
|
56
|
-
|
|
57
|
-
let tempDir = 'test-temp/';
|
|
58
|
-
let srcPath = `${tempDir}src`;
|
|
59
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "afterEach", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _testFilesystem.afterEach;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "beforeEach", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _testFilesystem.beforeEach;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "countMatches", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _testFilesystem.countMatches;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "createTempDir", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _testFilesystem.createTempDir;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "fileExists", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () {
|
|
34
|
+
return _testFilesystem.fileExists;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
exports.gulpConfig = void 0;
|
|
38
|
+
Object.defineProperty(exports, "logObject", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return _testFilesystem.logObject;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(exports, "removeDirectory", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function () {
|
|
47
|
+
return _testFilesystem.removeDirectory;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
exports.setDefaults = void 0;
|
|
51
|
+
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
52
|
+
exports.gulpConfig = gulpConfig;
|
|
53
|
+
var _testFilesystem = require("test-filesystem");
|
|
54
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
55
|
+
// Import the configurations and override some of them to direct to the temp directory.
|
|
56
|
+
|
|
57
|
+
let tempDir = 'test-temp/';
|
|
58
|
+
let srcPath = `${tempDir}src`;
|
|
59
|
+
|
|
60
60
|
/**
|
|
61
61
|
* Update the gulp configurations with the test data. Set the test directory where temp files will be created for testing.
|
|
62
62
|
* @memberOf module:testHelpers
|
|
63
63
|
* @param {string} testDir
|
|
64
|
-
*/
|
|
65
|
-
const setDefaults = (testDir = 'test-temp') => {
|
|
66
|
-
tempDir = `${testDir}/`;
|
|
67
|
-
srcPath = `${tempDir}src`;
|
|
68
|
-
_testFilesystem.setUp.setDefaults(tempDir);
|
|
69
|
-
const distPath = `${tempDir}dist`;
|
|
70
|
-
const browserPath = `${tempDir}browser`;
|
|
71
|
-
const sassPath = `${tempDir}sass`;
|
|
72
|
-
gulpConfig.set('browser.from', `${distPath}/**/*.js`);
|
|
73
|
-
gulpConfig.set('browser.to', browserPath);
|
|
74
|
-
gulpConfig.set('cleanPaths', [distPath, browserPath]);
|
|
75
|
-
gulpConfig.set('dist.from', `${srcPath}/**/!(*.test).js`);
|
|
76
|
-
gulpConfig.set('dist.main', `${distPath}/main`);
|
|
77
|
-
gulpConfig.set('dist.to', distPath);
|
|
78
|
-
gulpConfig.set('fonts.from', `${srcPath}/fonts/**/*`);
|
|
79
|
-
gulpConfig.set('fonts.to', `${browserPath}/fonts`);
|
|
80
|
-
gulpConfig.set('images.from', `${srcPath}/img/**/*.+(png|jpg|jpeg|gif|svg)`);
|
|
81
|
-
gulpConfig.set('images.to', `${browserPath}/img`);
|
|
82
|
-
gulpConfig.set('readme.template', `${tempDir}MAIN.md`);
|
|
83
|
-
gulpConfig.set('readme.to', tempDir);
|
|
84
|
-
gulpConfig.set('readme.from', `${srcPath}/**/!(*.test).js`);
|
|
85
|
-
gulpConfig.set('rootPath', tempDir);
|
|
86
|
-
gulpConfig.set('sass.from', `${sassPath}/**/*.+(scss|sass)`);
|
|
87
|
-
gulpConfig.set('sass.path', sassPath);
|
|
88
|
-
gulpConfig.set('sass.to', `${browserPath}/css`);
|
|
89
|
-
gulpConfig.set('srcPath', srcPath);
|
|
90
|
-
gulpConfig.set('typescript.from', `${srcPath}/**/*.ts`);
|
|
91
|
-
gulpConfig.set('typescript.to', distPath);
|
|
92
|
-
gulpConfig.set('test.watch', `${srcPath}/**/*.js`);
|
|
93
|
-
};
|
|
64
|
+
*/
|
|
65
|
+
const setDefaults = (testDir = 'test-temp') => {
|
|
66
|
+
tempDir = `${testDir}/`;
|
|
67
|
+
srcPath = `${tempDir}src`;
|
|
68
|
+
_testFilesystem.setUp.setDefaults(tempDir);
|
|
69
|
+
const distPath = `${tempDir}dist`;
|
|
70
|
+
const browserPath = `${tempDir}browser`;
|
|
71
|
+
const sassPath = `${tempDir}sass`;
|
|
72
|
+
gulpConfig.set('browser.from', `${distPath}/**/*.js`);
|
|
73
|
+
gulpConfig.set('browser.to', browserPath);
|
|
74
|
+
gulpConfig.set('cleanPaths', [distPath, browserPath]);
|
|
75
|
+
gulpConfig.set('dist.from', `${srcPath}/**/!(*.test).js`);
|
|
76
|
+
gulpConfig.set('dist.main', `${distPath}/main`);
|
|
77
|
+
gulpConfig.set('dist.to', distPath);
|
|
78
|
+
gulpConfig.set('fonts.from', `${srcPath}/fonts/**/*`);
|
|
79
|
+
gulpConfig.set('fonts.to', `${browserPath}/fonts`);
|
|
80
|
+
gulpConfig.set('images.from', `${srcPath}/img/**/*.+(png|jpg|jpeg|gif|svg)`);
|
|
81
|
+
gulpConfig.set('images.to', `${browserPath}/img`);
|
|
82
|
+
gulpConfig.set('readme.template', `${tempDir}MAIN.md`);
|
|
83
|
+
gulpConfig.set('readme.to', tempDir);
|
|
84
|
+
gulpConfig.set('readme.from', `${srcPath}/**/!(*.test).js`);
|
|
85
|
+
gulpConfig.set('rootPath', tempDir);
|
|
86
|
+
gulpConfig.set('sass.from', `${sassPath}/**/*.+(scss|sass)`);
|
|
87
|
+
gulpConfig.set('sass.path', sassPath);
|
|
88
|
+
gulpConfig.set('sass.to', `${browserPath}/css`);
|
|
89
|
+
gulpConfig.set('srcPath', srcPath);
|
|
90
|
+
gulpConfig.set('typescript.from', `${srcPath}/**/*.ts`);
|
|
91
|
+
gulpConfig.set('typescript.to', distPath);
|
|
92
|
+
gulpConfig.set('test.watch', `${srcPath}/**/*.js`);
|
|
93
|
+
};
|
|
94
94
|
exports.setDefaults = setDefaults;
|
package/dist/utilities/dotGet.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.dotGet = void 0;
|
|
7
|
-
var _isObject = require("./isObject.js");
|
|
8
|
-
var _strAfter = require("./strAfter.js");
|
|
9
|
-
var _strBefore = require("./strBefore.js");
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.dotGet = void 0;
|
|
7
|
+
var _isObject = require("./isObject.js");
|
|
8
|
+
var _strAfter = require("./strAfter.js");
|
|
9
|
+
var _strBefore = require("./strBefore.js");
|
|
10
10
|
/**
|
|
11
11
|
* Get a nested property value from an object.
|
|
12
12
|
* Original source concepts from {@link https://github.com/jheagle/si-funciona/blob/main/src/helpers/objects/dotGet.ts Sí, funciona}
|
|
@@ -14,41 +14,41 @@ var _strBefore = require("./strBefore.js");
|
|
|
14
14
|
* @param {string} [dotNotation=''] - The path to the property
|
|
15
15
|
* @param {string|null} [defaultValue=null] - The default value to return if the property is not found
|
|
16
16
|
* @returns {*} The value of the property
|
|
17
|
-
*/
|
|
18
|
-
const dotGet = (arrayObject = {}, dotNotation = '', defaultValue = null) => {
|
|
19
|
-
if (!dotNotation) {
|
|
20
|
-
return arrayObject;
|
|
21
|
-
}
|
|
22
|
-
let key = (0, _strBefore.strBefore)(dotNotation, '.');
|
|
23
|
-
const lastKey = !key;
|
|
24
|
-
if (lastKey) {
|
|
25
|
-
key = dotNotation;
|
|
26
|
-
}
|
|
27
|
-
if (key === '*') {
|
|
28
|
-
const result = [];
|
|
29
|
-
for (let wildKey in arrayObject) {
|
|
30
|
-
const wildValue = arrayObject[wildKey];
|
|
31
|
-
if (lastKey) {
|
|
32
|
-
result[wildKey] = wildValue;
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
if (!(0, _isObject.isObject)(wildValue)) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
result[wildKey] = dotGet(wildValue, (0, _strAfter.strAfter)(dotNotation, '.'), defaultValue);
|
|
39
|
-
}
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
if (lastKey) {
|
|
43
|
-
return arrayObject[dotNotation] ?? defaultValue;
|
|
44
|
-
}
|
|
45
|
-
if (typeof arrayObject[key] === 'undefined') {
|
|
46
|
-
return defaultValue;
|
|
47
|
-
}
|
|
48
|
-
const next = arrayObject[key];
|
|
49
|
-
if (!(0, _isObject.isObject)(next)) {
|
|
50
|
-
return defaultValue;
|
|
51
|
-
}
|
|
52
|
-
return dotGet(next, (0, _strAfter.strAfter)(dotNotation, '.'), defaultValue);
|
|
53
|
-
};
|
|
17
|
+
*/
|
|
18
|
+
const dotGet = (arrayObject = {}, dotNotation = '', defaultValue = null) => {
|
|
19
|
+
if (!dotNotation) {
|
|
20
|
+
return arrayObject;
|
|
21
|
+
}
|
|
22
|
+
let key = (0, _strBefore.strBefore)(dotNotation, '.');
|
|
23
|
+
const lastKey = !key;
|
|
24
|
+
if (lastKey) {
|
|
25
|
+
key = dotNotation;
|
|
26
|
+
}
|
|
27
|
+
if (key === '*') {
|
|
28
|
+
const result = [];
|
|
29
|
+
for (let wildKey in arrayObject) {
|
|
30
|
+
const wildValue = arrayObject[wildKey];
|
|
31
|
+
if (lastKey) {
|
|
32
|
+
result[wildKey] = wildValue;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (!(0, _isObject.isObject)(wildValue)) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
result[wildKey] = dotGet(wildValue, (0, _strAfter.strAfter)(dotNotation, '.'), defaultValue);
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
if (lastKey) {
|
|
43
|
+
return arrayObject[dotNotation] ?? defaultValue;
|
|
44
|
+
}
|
|
45
|
+
if (typeof arrayObject[key] === 'undefined') {
|
|
46
|
+
return defaultValue;
|
|
47
|
+
}
|
|
48
|
+
const next = arrayObject[key];
|
|
49
|
+
if (!(0, _isObject.isObject)(next)) {
|
|
50
|
+
return defaultValue;
|
|
51
|
+
}
|
|
52
|
+
return dotGet(next, (0, _strAfter.strAfter)(dotNotation, '.'), defaultValue);
|
|
53
|
+
};
|
|
54
54
|
exports.dotGet = dotGet;
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.dotNotate = void 0;
|
|
7
|
-
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
-
require("core-js/modules/esnext.iterator.map.js");
|
|
9
|
-
var _isObject = require("./isObject.js");
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.dotNotate = void 0;
|
|
7
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
+
require("core-js/modules/esnext.iterator.map.js");
|
|
9
|
+
var _isObject = require("./isObject.js");
|
|
10
10
|
/**
|
|
11
11
|
* Convert an array of keys into a regex, return a function to test if incoming keys match.
|
|
12
12
|
* @param {Array.<string>} [retainObjects=[]] - An array of keys to retain as objects
|
|
13
13
|
* @returns {Function} The dot-notated array
|
|
14
|
-
*/
|
|
15
|
-
const handleRetainObjects = (retainObjects = []) => {
|
|
16
|
-
if (!retainObjects.length) {
|
|
14
|
+
*/
|
|
15
|
+
const handleRetainObjects = (retainObjects = []) => {
|
|
16
|
+
if (!retainObjects.length) {
|
|
17
17
|
/**
|
|
18
18
|
* Bypass the test function if there are no retainObjects.
|
|
19
19
|
* @returns {false}
|
|
20
|
-
*/
|
|
21
|
-
return (currentKey, value, results) => false;
|
|
22
|
-
}
|
|
23
|
-
retainObjects = retainObjects.map(key => key.replace('\.', '\\.'));
|
|
24
|
-
const retainRegex = new RegExp(`(${retainObjects.join('|')})$`);
|
|
20
|
+
*/
|
|
21
|
+
return (currentKey, value, results) => false;
|
|
22
|
+
}
|
|
23
|
+
retainObjects = retainObjects.map(key => key.replace('\.', '\\.'));
|
|
24
|
+
const retainRegex = new RegExp(`(${retainObjects.join('|')})$`);
|
|
25
25
|
/**
|
|
26
26
|
* Test if a key should be retained as an object.
|
|
27
27
|
* @param {string} currentKey - The key to test
|
|
28
28
|
* @param {*} value - The value of the key
|
|
29
29
|
* @param {Object} results - The result object to add to
|
|
30
30
|
* @returns {boolean}
|
|
31
|
-
*/
|
|
32
|
-
return (currentKey, value, results) => {
|
|
33
|
-
if (!currentKey.match(retainRegex)) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
results[currentKey] = value;
|
|
37
|
-
return true;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
31
|
+
*/
|
|
32
|
+
return (currentKey, value, results) => {
|
|
33
|
+
if (!currentKey.match(retainRegex)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
results[currentKey] = value;
|
|
37
|
+
return true;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
41
|
/**
|
|
42
42
|
* The underlying logic function for converting arrays to dot-notation.
|
|
43
43
|
* @param {Object} arrayObject - The array or object to dot-notate
|
|
@@ -45,29 +45,29 @@ const handleRetainObjects = (retainObjects = []) => {
|
|
|
45
45
|
* @param {string} [prepend=''] - The path for the property being processed
|
|
46
46
|
* @param {Object<string, *>} [results={}] - The final notated object to return
|
|
47
47
|
* @returns {Object<string, *>} The dot-notated object
|
|
48
|
-
*/
|
|
49
|
-
const performDotNotate = (arrayObject, didRetain, prepend = '', results = {}) => {
|
|
50
|
-
for (let key in arrayObject) {
|
|
51
|
-
const value = arrayObject[key];
|
|
52
|
-
const currentKey = `${prepend}${key}`;
|
|
53
|
-
if (didRetain(currentKey, value, results)) {
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
if ((0, _isObject.isObject)(value)) {
|
|
57
|
-
performDotNotate(value, didRetain, `${currentKey}.`, results);
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
results[currentKey] = value;
|
|
61
|
-
}
|
|
62
|
-
return results;
|
|
63
|
-
};
|
|
64
|
-
|
|
48
|
+
*/
|
|
49
|
+
const performDotNotate = (arrayObject, didRetain, prepend = '', results = {}) => {
|
|
50
|
+
for (let key in arrayObject) {
|
|
51
|
+
const value = arrayObject[key];
|
|
52
|
+
const currentKey = `${prepend}${key}`;
|
|
53
|
+
if (didRetain(currentKey, value, results)) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if ((0, _isObject.isObject)(value)) {
|
|
57
|
+
performDotNotate(value, didRetain, `${currentKey}.`, results);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
results[currentKey] = value;
|
|
61
|
+
}
|
|
62
|
+
return results;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
65
|
/**
|
|
66
66
|
* Convert an array or object to a single dimensional associative array with dot notation.
|
|
67
67
|
* Original source concepts from {@link https://github.com/jheagle/si-funciona/blob/main/src/helpers/objects/dotNotate.ts Sí, funciona}
|
|
68
68
|
* @param {Object} arrayObject - The array or object to dot-notate
|
|
69
69
|
* @param {Array.<string>} [retainObjects=[]] - An array of keys to retain as objects
|
|
70
70
|
* @returns {Object<string, *>} The dot-notated object
|
|
71
|
-
*/
|
|
72
|
-
const dotNotate = (arrayObject, retainObjects = []) => performDotNotate(arrayObject, handleRetainObjects(retainObjects));
|
|
71
|
+
*/
|
|
72
|
+
const dotNotate = (arrayObject, retainObjects = []) => performDotNotate(arrayObject, handleRetainObjects(retainObjects));
|
|
73
73
|
exports.dotNotate = dotNotate;
|