Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Ignore generated files.
node_modules/
dist/
node_modules/
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Ignore development files.
test/
.github/
test/
.gitattributes
gulpfile.js
34 changes: 23 additions & 11 deletions gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export type Mapper<V, R, F = V[], T = any> =
* @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<V, R, F = V[], I = V, T = any> =
(this: T, accumulator: R | I, current: V, index?: number, object?: F) => R;

Expand Down