diff --git a/.gitignore b/.gitignore index 7050ec3..c9d4843 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ # Ignore generated files. -node_modules/ dist/ +node_modules/ diff --git a/.npmignore b/.npmignore index a72566a..e332cd3 100644 --- a/.npmignore +++ b/.npmignore @@ -1,4 +1,5 @@ # Ignore development files. -test/ .github/ +test/ +.gitattributes gulpfile.js diff --git a/gulpfile.mjs b/gulpfile.mjs index bc74839..b4f312a 100644 --- a/gulpfile.mjs +++ b/gulpfile.mjs @@ -6,28 +6,40 @@ import filter from "gulp-filter"; import merge from "merge-stream"; const {src, dest} = Gulp; -const moduleGoals = {"esmodule": "ESNext", "commonjs": "CommonJS"}; +const moduleGoals = new Map([["esmodule", "ESNext"], ["commonjs", "CommonJS"]]); const optsCompress = {"ext": {"min": "-min.js"}, "preserveComments": "some"}; -function mapObject(object, func) { - return Object.fromEntries(Object.entries(object).map((item, index) => [item[0], func(item, index, object)])); +function mapMap(map, mapper) { + return new Map(Array.from(map).map(function(pair, index) { + const res = mapper(pair, index, map); + return res instanceof Array && res.length == 2 ? res : [pair[0], res]; + })); } -function mapObjectToArray(object, func) { - return Object.entries(object).map((item, index) => func(item, index, object)); +function mapMapToArray(map, mapper) { + return Array.from(map).map((pair, ind) => mapper(pair, ind, map)); } -export function compile() { - const tsProjects = mapObject(moduleGoals, ([key, value]) => +export function actuallyCompile(moduleSystem) { + const tsProjects = mapMap(moduleGoals, ([key, value]) => ts.createProject("tsconfig.json", {"module": value})()); const dtsFilter = filter(["**", "!**/*.d.ts"], {"restore": true}); - const compile = (pipe, mod) => pipe.pipe(tsProjects[mod]).pipe(dtsFilter) + const compile = (pipe, mod) => pipe.pipe(tsProjects.get(mod)).pipe(dtsFilter) .pipe(rename(path => path.basename = mod + "-" + path.basename)); const compress = pipe => pipe.pipe(minify(optsCompress)); - - const source = src("./src/**/*.ts"); - const stage1 = mapObjectToArray(tsProjects, ([key]) => compile(source, key)).flat(); + + const stage1 = [compile(src("./src/**/*.ts"), moduleSystem)]; const stage2 = stage1.map(pipe => compress(pipe)).flat(); const stage3 = [stage2[0].pipe(dtsFilter.restore), stage2.slice(1)]; return merge(...stage3).pipe(dest("./dist/")); } + +export function compile() { + const promisifyStream = stream => new Promise((rs, rj) => { + stream.on("error", rj); + stream.on("end", () => rs(stream)); + }); + + return Array.from(moduleGoals).reduce((prom, [val]) => + prom.then(() => promisifyStream(actuallyCompile(val))), Promise.resolve()); +} diff --git a/package.json b/package.json index 1dc79a8..5dd03e0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "daniis-tools", - "version": "1.0.0", + "version": "1.0.1", "description": "A set of functions, types, better typings and extra methods to improve your coding experience.", "main": "dist/commonjs-tools.js", "types": "dist/tools.d.ts", diff --git a/src/tools.ts b/src/tools.ts index e230098..4d05f3e 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -150,6 +150,7 @@ export type Mapper = * @template I The initial value type. Defaults to `V`. * @template T The type of object this function is ran on. */ +//TODO: Switch F and I type order in 2.0 release. export type Reducer = (this: T, accumulator: R | I, current: V, index?: number, object?: F) => R;