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 merge = require("merge-stream");
|
||||
import minimist = require("minimist");
|
||||
import PromiseQueue = require("promise-queue");
|
||||
import { parseArgsStringToArgv } from "string-argv";
|
||||
import Path = require("upath");
|
||||
import buffer = require("vinyl-buffer");
|
||||
|
@ -237,10 +236,11 @@ export async function Build(): Promise<void>
|
|||
* @returns
|
||||
* The pipeline to execute.
|
||||
*/
|
||||
export async function Library(): Promise<NodeJS.ReadWriteStream>
|
||||
export function Library(): NodeJS.ReadWriteStream
|
||||
{
|
||||
let streams: Array<Promise<NodeJS.ReadWriteStream>> = [];
|
||||
let queue = new PromiseQueue();
|
||||
let errorMessages: string[] = [];
|
||||
let streams: NodeJS.ReadWriteStream[] = [];
|
||||
let queue: NodeJS.ReadWriteStream[] = [];
|
||||
let tsConfigFile = settings.TypeScriptProjectRoot("tsconfig.json");
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
let tsConfig = require(tsConfigFile);
|
||||
|
@ -252,13 +252,15 @@ export async function Library(): Promise<NodeJS.ReadWriteStream>
|
|||
debug: settings.Debug
|
||||
};
|
||||
|
||||
{
|
||||
let errorMessages: string[] = [];
|
||||
let files = (tsConfig.files as string[]).map(
|
||||
(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(
|
||||
{
|
||||
...optionBase,
|
||||
|
@ -281,84 +283,81 @@ export async function Library(): Promise<NodeJS.ReadWriteStream>
|
|||
project: tsConfigFile
|
||||
});
|
||||
|
||||
let bundle = async (): Promise<NodeJS.ReadWriteStream> =>
|
||||
{
|
||||
return new Promise<NodeJS.ReadWriteStream>(
|
||||
(resolve) =>
|
||||
stream = bundler.bundle().on(
|
||||
"error",
|
||||
(error) =>
|
||||
{
|
||||
let message: string = error.message;
|
||||
|
||||
if (!errorMessages.includes(message))
|
||||
{
|
||||
let stream = bundler.bundle().on(
|
||||
"error",
|
||||
(error) =>
|
||||
{
|
||||
let message: string = error.message;
|
||||
let result = new RegExp(`^(${error["fileName"]})\\((\\d+|\\d+(,\\d+){1,3})\\): .* TS([\\d]+): (.*)$`).exec(message);
|
||||
errorMessages.push(message);
|
||||
console.log(`${Path.relative(process.cwd(), result[1])}(${result[2]}): ${result[4]} ${result[5]}`);
|
||||
}
|
||||
}
|
||||
).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))
|
||||
{
|
||||
let result = new RegExp(`^(${error["fileName"]})\\((\\d+|\\d+(,\\d+){1,3})\\): .* TS([\\d]+): (.*)$`).exec(message);
|
||||
errorMessages.push(message);
|
||||
console.log(`${Path.relative(process.cwd(), result[1])}(${result[2]}): ${result[4]} ${result[5]}`);
|
||||
}
|
||||
if (queue.length === 0)
|
||||
{
|
||||
log.info(watchFinishMessage(errorMessages.length));
|
||||
|
||||
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(
|
||||
"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);
|
||||
});
|
||||
});
|
||||
};
|
||||
errorMessages.splice(0, errorMessages.length);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (settings.Watch)
|
||||
{
|
||||
bundler.on(
|
||||
bundler.once(
|
||||
"update",
|
||||
() =>
|
||||
{
|
||||
if ((queue.getQueueLength() + queue.getPendingLength()) === 0)
|
||||
console.log(`Update called for ${file}: ${queue.length}`);
|
||||
|
||||
if (queue.length === 0)
|
||||
{
|
||||
log.info(incrementalMessage);
|
||||
}
|
||||
|
||||
queue.add(
|
||||
async () =>
|
||||
{
|
||||
return bundle();
|
||||
});
|
||||
queue.push(builder());
|
||||
});
|
||||
}
|
||||
|
||||
let build = (): Promise<NodeJS.ReadWriteStream> => queue.add(bundle);
|
||||
build.displayName = Build.displayName;
|
||||
build.description = Build.description;
|
||||
streams.push(build());
|
||||
}
|
||||
return stream;
|
||||
};
|
||||
|
||||
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.";
|
||||
|
|
12
package-lock.json
generated
12
package-lock.json
generated
|
@ -793,12 +793,6 @@
|
|||
"integrity": "sha1-akDsfr0kGO5p7jl+SOQhaSaKEL8=",
|
||||
"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": {
|
||||
"version": "1.13.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.9.tgz",
|
||||
|
@ -7221,12 +7215,6 @@
|
|||
"integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==",
|
||||
"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": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
"@types/merge-stream": "^1.1.2",
|
||||
"@types/minimist": "^1.2.1",
|
||||
"@types/node": "^15.0.2",
|
||||
"@types/promise-queue": "^2.2.0",
|
||||
"@types/vinyl-buffer": "^1.0.0",
|
||||
"@types/vinyl-source-stream": "0.0.30",
|
||||
"@types/watchify": "^3.11.0",
|
||||
|
@ -63,7 +62,6 @@
|
|||
"minimist": "^1.2.5",
|
||||
"node-sass-tilde-importer": "^1.0.2",
|
||||
"popper.js": "^1.16.0",
|
||||
"promise-queue": "^2.2.5",
|
||||
"string-argv": "^0.3.1",
|
||||
"ts-node": "^9.1.1",
|
||||
"tsify": "^5.0.4",
|
||||
|
|
Loading…
Reference in a new issue