Simplify the pcoess of creating js code
This commit is contained in:
parent
61627c2a6a
commit
25683a35fc
3 changed files with 67 additions and 82 deletions
135
gulpfile.ts
135
gulpfile.ts
|
@ -11,7 +11,6 @@ import sass = require("gulp-sass");
|
||||||
import terser = require("gulp-terser");
|
import terser = require("gulp-terser");
|
||||||
import merge = require("merge-stream");
|
import merge = require("merge-stream");
|
||||||
import minimist = require("minimist");
|
import minimist = require("minimist");
|
||||||
import PromiseQueue = require("promise-queue");
|
|
||||||
import { parseArgsStringToArgv } from "string-argv";
|
import { parseArgsStringToArgv } from "string-argv";
|
||||||
import Path = require("upath");
|
import Path = require("upath");
|
||||||
import buffer = require("vinyl-buffer");
|
import buffer = require("vinyl-buffer");
|
||||||
|
@ -237,10 +236,11 @@ export async function Build(): Promise<void>
|
||||||
* @returns
|
* @returns
|
||||||
* The pipeline to execute.
|
* The pipeline to execute.
|
||||||
*/
|
*/
|
||||||
export async function Library(): Promise<NodeJS.ReadWriteStream>
|
export function Library(): NodeJS.ReadWriteStream
|
||||||
{
|
{
|
||||||
let streams: Array<Promise<NodeJS.ReadWriteStream>> = [];
|
let errorMessages: string[] = [];
|
||||||
let queue = new PromiseQueue();
|
let streams: NodeJS.ReadWriteStream[] = [];
|
||||||
|
let queue: NodeJS.ReadWriteStream[] = [];
|
||||||
let tsConfigFile = settings.TypeScriptProjectRoot("tsconfig.json");
|
let tsConfigFile = settings.TypeScriptProjectRoot("tsconfig.json");
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
let tsConfig = require(tsConfigFile);
|
let tsConfig = require(tsConfigFile);
|
||||||
|
@ -252,13 +252,15 @@ export async function Library(): Promise<NodeJS.ReadWriteStream>
|
||||||
debug: settings.Debug
|
debug: settings.Debug
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
let files = (tsConfig.files as string[]).map(
|
||||||
let errorMessages: string[] = [];
|
(file) => Path.relative(settings.TypeScriptSourceRoot(), settings.TypeScriptProjectRoot(file)));
|
||||||
let files = (tsConfig.files as string[]).map(
|
|
||||||
(file) => Path.relative(settings.TypeScriptSourceRoot(), settings.TypeScriptProjectRoot(file)));
|
|
||||||
|
|
||||||
for (let file of files)
|
for (let file of files)
|
||||||
|
{
|
||||||
|
let builder = (): NodeJS.ReadWriteStream =>
|
||||||
{
|
{
|
||||||
|
let stream: NodeJS.ReadWriteStream;
|
||||||
|
|
||||||
let bundler = browserify(
|
let bundler = browserify(
|
||||||
{
|
{
|
||||||
...optionBase,
|
...optionBase,
|
||||||
|
@ -281,84 +283,81 @@ export async function Library(): Promise<NodeJS.ReadWriteStream>
|
||||||
project: tsConfigFile
|
project: tsConfigFile
|
||||||
});
|
});
|
||||||
|
|
||||||
let bundle = async (): Promise<NodeJS.ReadWriteStream> =>
|
stream = bundler.bundle().on(
|
||||||
{
|
"error",
|
||||||
return new Promise<NodeJS.ReadWriteStream>(
|
(error) =>
|
||||||
(resolve) =>
|
{
|
||||||
|
let message: string = error.message;
|
||||||
|
|
||||||
|
if (!errorMessages.includes(message))
|
||||||
{
|
{
|
||||||
let stream = bundler.bundle().on(
|
let result = new RegExp(`^(${error["fileName"]})\\((\\d+|\\d+(,\\d+){1,3})\\): .* TS([\\d]+): (.*)$`).exec(message);
|
||||||
"error",
|
errorMessages.push(message);
|
||||||
(error) =>
|
console.log(`${Path.relative(process.cwd(), result[1])}(${result[2]}): ${result[4]} ${result[5]}`);
|
||||||
{
|
}
|
||||||
let message: string = error.message;
|
}
|
||||||
|
).pipe(
|
||||||
|
vinylSourceStream(Path.changeExt(file, "js"))
|
||||||
|
).pipe(
|
||||||
|
buffer()
|
||||||
|
).pipe(
|
||||||
|
gulpIf(
|
||||||
|
!settings.Debug,
|
||||||
|
terser()
|
||||||
|
)
|
||||||
|
).pipe(
|
||||||
|
gulp.dest(settings.LibraryPath())
|
||||||
|
).on(
|
||||||
|
"end",
|
||||||
|
() =>
|
||||||
|
{
|
||||||
|
if (settings.Watch)
|
||||||
|
{
|
||||||
|
if (queue.includes(stream))
|
||||||
|
{
|
||||||
|
queue.splice(queue.indexOf(stream), 1);
|
||||||
|
}
|
||||||
|
|
||||||
if (!errorMessages.includes(message))
|
if (queue.length === 0)
|
||||||
{
|
{
|
||||||
let result = new RegExp(`^(${error["fileName"]})\\((\\d+|\\d+(,\\d+){1,3})\\): .* TS([\\d]+): (.*)$`).exec(message);
|
log.info(watchFinishMessage(errorMessages.length));
|
||||||
errorMessages.push(message);
|
|
||||||
console.log(`${Path.relative(process.cwd(), result[1])}(${result[2]}): ${result[4]} ${result[5]}`);
|
if (errorMessages.length === 0)
|
||||||
}
|
{
|
||||||
|
syncer.reload("*.js");
|
||||||
}
|
}
|
||||||
).pipe(
|
|
||||||
vinylSourceStream(Path.changeExt(file, "js"))
|
|
||||||
).pipe(
|
|
||||||
buffer()
|
|
||||||
).pipe(
|
|
||||||
gulpIf(
|
|
||||||
!settings.Debug,
|
|
||||||
terser()
|
|
||||||
)
|
|
||||||
).pipe(
|
|
||||||
gulp.dest(settings.LibraryPath())
|
|
||||||
);
|
|
||||||
|
|
||||||
stream.on(
|
errorMessages.splice(0, errorMessages.length);
|
||||||
"end",
|
}
|
||||||
() =>
|
}
|
||||||
{
|
});
|
||||||
if (settings.Watch && ((queue.getQueueLength() + queue.getPendingLength()) === 1))
|
|
||||||
{
|
|
||||||
if (errorMessages.length === 0)
|
|
||||||
{
|
|
||||||
syncer.reload("*.js");
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info(watchFinishMessage(errorMessages.length));
|
|
||||||
}
|
|
||||||
|
|
||||||
errorMessages.splice(0, errorMessages.length);
|
|
||||||
resolve(stream);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
if (settings.Watch)
|
if (settings.Watch)
|
||||||
{
|
{
|
||||||
bundler.on(
|
bundler.once(
|
||||||
"update",
|
"update",
|
||||||
() =>
|
() =>
|
||||||
{
|
{
|
||||||
if ((queue.getQueueLength() + queue.getPendingLength()) === 0)
|
console.log(`Update called for ${file}: ${queue.length}`);
|
||||||
|
|
||||||
|
if (queue.length === 0)
|
||||||
{
|
{
|
||||||
log.info(incrementalMessage);
|
log.info(incrementalMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
queue.add(
|
queue.push(builder());
|
||||||
async () =>
|
|
||||||
{
|
|
||||||
return bundle();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let build = (): Promise<NodeJS.ReadWriteStream> => queue.add(bundle);
|
return stream;
|
||||||
build.displayName = Build.displayName;
|
};
|
||||||
build.description = Build.description;
|
|
||||||
streams.push(build());
|
let stream = builder();
|
||||||
}
|
queue.push(stream);
|
||||||
|
streams.push(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
return merge(await Promise.all(streams)) as NodeJS.ReadWriteStream;
|
return merge(streams);
|
||||||
}
|
}
|
||||||
|
|
||||||
Library.description = "Builds the TypeScript- and JavaScript-library.";
|
Library.description = "Builds the TypeScript- and JavaScript-library.";
|
||||||
|
|
12
package-lock.json
generated
12
package-lock.json
generated
|
@ -793,12 +793,6 @@
|
||||||
"integrity": "sha1-akDsfr0kGO5p7jl+SOQhaSaKEL8=",
|
"integrity": "sha1-akDsfr0kGO5p7jl+SOQhaSaKEL8=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/promise-queue": {
|
|
||||||
"version": "2.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@types/promise-queue/-/promise-queue-2.2.0.tgz",
|
|
||||||
"integrity": "sha512-9QLtid6GxEWqpF+QImxBRG6bSVOHtpAm2kXuIyEvZBbSOupLvqhhJv8uaHbS8kUL8FDjzH3RWcSyC/52WOVtGw==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"@types/serve-static": {
|
"@types/serve-static": {
|
||||||
"version": "1.13.9",
|
"version": "1.13.9",
|
||||||
"resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.9.tgz",
|
"resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.9.tgz",
|
||||||
|
@ -7221,12 +7215,6 @@
|
||||||
"integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==",
|
"integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"promise-queue": {
|
|
||||||
"version": "2.2.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/promise-queue/-/promise-queue-2.2.5.tgz",
|
|
||||||
"integrity": "sha1-L29ffA9tCBCelnZZx5uIqe1ek7Q=",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"pseudomap": {
|
"pseudomap": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
|
||||||
|
|
|
@ -36,7 +36,6 @@
|
||||||
"@types/merge-stream": "^1.1.2",
|
"@types/merge-stream": "^1.1.2",
|
||||||
"@types/minimist": "^1.2.1",
|
"@types/minimist": "^1.2.1",
|
||||||
"@types/node": "^15.0.2",
|
"@types/node": "^15.0.2",
|
||||||
"@types/promise-queue": "^2.2.0",
|
|
||||||
"@types/vinyl-buffer": "^1.0.0",
|
"@types/vinyl-buffer": "^1.0.0",
|
||||||
"@types/vinyl-source-stream": "0.0.30",
|
"@types/vinyl-source-stream": "0.0.30",
|
||||||
"@types/watchify": "^3.11.0",
|
"@types/watchify": "^3.11.0",
|
||||||
|
@ -63,7 +62,6 @@
|
||||||
"minimist": "^1.2.5",
|
"minimist": "^1.2.5",
|
||||||
"node-sass-tilde-importer": "^1.0.2",
|
"node-sass-tilde-importer": "^1.0.2",
|
||||||
"popper.js": "^1.16.0",
|
"popper.js": "^1.16.0",
|
||||||
"promise-queue": "^2.2.5",
|
|
||||||
"string-argv": "^0.3.1",
|
"string-argv": "^0.3.1",
|
||||||
"ts-node": "^9.1.1",
|
"ts-node": "^9.1.1",
|
||||||
"tsify": "^5.0.4",
|
"tsify": "^5.0.4",
|
||||||
|
|
Loading…
Reference in a new issue