Embed version in the JavaScript client (#2229)

This commit is contained in:
Andrew Stanton-Nurse 2018-05-11 12:54:30 -07:00 committed by GitHub
parent e1f7cb4105
commit 76a6cbcd84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 1 deletions

View File

@ -0,0 +1,44 @@
const path = require("path");
const fs = require("fs");
const pkg = require(path.resolve(process.cwd(), "package.json"));
const args = process.argv.slice(2);
let verbose = false;
for (let i = 0; i < args.length; i++) {
switch (args[i]) {
case "-v":
verbose = true;
break;
}
}
function processDirectory(dir) {
if (verbose) {
console.log(`processing ${dir}`);
}
for (const item of fs.readdirSync(dir)) {
const fullPath = path.resolve(dir, item);
const stats = fs.statSync(fullPath);
if (stats.isDirectory()) {
processDirectory(fullPath);
} else if (stats.isFile()) {
processFile(fullPath);
}
}
}
const SEARCH_STRING = "0.0.0-DEV_BUILD";
function processFile(file) {
if (file.endsWith(".js") || file.endsWith(".ts")) {
if (verbose) {
console.log(`processing ${file}`);
}
let content = fs.readFileSync(file);
content = content.toString().replace(SEARCH_STRING, pkg.version);
fs.writeFileSync(file, content);
} else if (verbose) {
console.log(`skipping ${file}`);
}
}
processDirectory(path.resolve(process.cwd(), "dist"));

View File

@ -19,7 +19,10 @@ export default function(rootDir, moduleGlobals) {
format: "umd",
name: pkg.umd_name,
sourcemap: true,
banner: "/* @license\r\n" +
banner: "/** \r\n" +
" * @overview ASP.NET Core SignalR JavaScript Client.\r\n" +
" * @version 0.0.0-DEV_BUILD.\r\n" +
" * @license\r\n" +
" * Copyright (c) .NET Foundation. All rights reserved.\r\n" +
" * Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.\r\n" +
" */",

View File

@ -18,6 +18,7 @@
"build:cjs": "node ../node_modules/typescript/bin/tsc --project ./tsconfig.json --module commonjs --outDir ./dist/cjs",
"build:browser": "node ../node_modules/rollup/bin/rollup -c",
"build:uglify": "node ../node_modules/uglify-js/bin/uglifyjs --source-map \"url='signalr-protocol-msgpack.min.js.map',content='./dist/browser/signalr-protocol-msgpack.js.map'\" --comments -o ./dist/browser/signalr-protocol-msgpack.min.js ./dist/browser/signalr-protocol-msgpack.js",
"prepack": "node ../build/embed-version.js",
"test": "echo \"Run 'npm test' in the 'clients\\ts' folder to test this package\" && exit 1"
},
"keywords": [

View File

@ -1,4 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Version token that will be replaced by the prepack command
/** The version of the SignalR Message Pack protocol library. */
export const VERSION = "0.0.0-DEV_BUILD";
export { MessagePackHubProtocol } from "./MessagePackHubProtocol";

View File

@ -18,6 +18,7 @@
"build:cjs": "node ../node_modules/typescript/bin/tsc --project ./tsconfig.json --module commonjs --outDir ./dist/cjs",
"build:browser": "node ../node_modules/rollup/bin/rollup -c",
"build:uglify": "node ../node_modules/uglify-js/bin/uglifyjs --source-map \"url='signalr.min.js.map',content='./dist/browser/signalr.js.map'\" --comments -o ./dist/browser/signalr.min.js ./dist/browser/signalr.js",
"prepack": "node ../build/embed-version.js",
"test": "echo \"Run 'npm test' in the 'clients\\ts' folder to test this package\" && exit 1"
},
"repository": {

View File

@ -1,6 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Version token that will be replaced by the prepack command
/** The version of the SignalR client. */
export const VERSION: string = "0.0.0-DEV_BUILD";
// Everything that users need to access must be exported here. Including interfaces.
export { AbortSignal } from "./AbortController";
export { HttpError, TimeoutError } from "./Errors";