-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(client): check in bundled client code into version control (#3524)
New script will take care about building assets and also checking that bundled assets are up-to-date as part of CI. This provides some improvements over the previous approach from f5521df#commitcomment-38967493: 1. It is possible to install `karma` from GitHub branch without the assumption that `browserify` is installed in user's project. 1. Karma contributors no longer need to run `npm run build` unless they want to change client code. 1. Simplifies runtime code.
- Loading branch information
Showing
12 changed files
with
5,558 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
node_modules | ||
npm-debug.log | ||
static/context.js | ||
static/karma.js | ||
.idea/* | ||
*.iml | ||
docs/_build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ install: | |
- npm run init:windows | ||
|
||
test_script: | ||
- npm run appveyor | ||
- npm run test:appveyor | ||
|
||
build: off | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const browserify = require('browserify') | ||
const fs = require('fs') | ||
const { readFile } = require('fs').promises | ||
|
||
const bundleResourceToFile = (inPath, outPath) => { | ||
return new Promise((resolve, reject) => { | ||
browserify(inPath).bundle() | ||
.pipe(fs.createWriteStream(outPath)) | ||
.once('finish', () => resolve()) | ||
.once('error', (e) => reject(e)) | ||
}) | ||
} | ||
|
||
const bundleResource = (inPath) => { | ||
return new Promise((resolve, reject) => { | ||
browserify(inPath).bundle((err, buffer) => { | ||
if (err != null) { | ||
reject(err) | ||
return | ||
} | ||
|
||
resolve(buffer) | ||
}) | ||
}) | ||
} | ||
|
||
const main = async () => { | ||
if (process.argv[2] === 'build') { | ||
await bundleResourceToFile('client/main.js', 'static/karma.js') | ||
await bundleResourceToFile('context/main.js', 'static/context.js') | ||
} else if (process.argv[2] === 'check') { | ||
const expectedClient = await bundleResource('client/main.js') | ||
const expectedContext = await bundleResource('context/main.js') | ||
|
||
const actualClient = await readFile('static/karma.js') | ||
const actualContext = await readFile('static/context.js') | ||
|
||
if (Buffer.compare(expectedClient, actualClient) !== 0 || Buffer.compare(expectedContext, actualContext) !== 0) { | ||
// eslint-disable-next-line no-throw-literal | ||
throw 'Bundled client assets are outdated. Forgot to run "npm run build"?' | ||
} | ||
} else { | ||
// eslint-disable-next-line no-throw-literal | ||
throw `Unknown command: ${process.argv[2]}` | ||
} | ||
} | ||
|
||
main().catch((err) => { | ||
console.error(err) | ||
process.exit(1) | ||
}) |
Oops, something went wrong.