forked from ajv-validator/ajv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
browser bundle script (6 tests fail in browser), do not browserify co…
…de in schema tests
- Loading branch information
1 parent
6939f90
commit 888029f
Showing
12 changed files
with
60 additions
and
253 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
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 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
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 |
---|---|---|
@@ -1,69 +1,46 @@ | ||
"use strict" | ||
|
||
var fs = require("fs"), | ||
path = require("path"), | ||
browserify = require("browserify"), | ||
uglify = require("uglify-js") | ||
|
||
var pkg = process.argv[2], | ||
standalone = process.argv[3], | ||
compress = process.argv[4] | ||
|
||
var packageDir = path.join(__dirname, "..") | ||
if (pkg !== ".") packageDir = path.join(packageDir, "node_modules", pkg) | ||
|
||
var json = require(path.join(packageDir, "package.json")) | ||
|
||
var distDir = path.join(__dirname, "..", "dist") | ||
if (!fs.existsSync(distDir)) fs.mkdirSync(distDir) | ||
|
||
var bOpts = {} | ||
if (standalone) bOpts.standalone = standalone | ||
|
||
browserify(bOpts) | ||
.require(path.join(packageDir, json.main), {expose: json.name}) | ||
.bundle((err, buf) => { | ||
if (err) { | ||
console.error("browserify error:", err) | ||
process.exit(1) | ||
} | ||
|
||
var outputFile = path.join(distDir, json.name) | ||
var uglifyOpts = { | ||
warnings: true, | ||
compress: {}, | ||
output: { | ||
preamble: | ||
"/* " + | ||
json.name + | ||
" " + | ||
json.version + | ||
": " + | ||
json.description + | ||
" */", | ||
}, | ||
} | ||
if (compress) { | ||
var compressOpts = compress.split(",") | ||
for (var i = 0, il = compressOpts.length; i < il; ++i) { | ||
var pair = compressOpts[i].split("=") | ||
uglifyOpts.compress[pair[0]] = pair.length < 1 || pair[1] !== "false" | ||
} | ||
} | ||
if (standalone) { | ||
uglifyOpts.sourceMap = { | ||
filename: json.name + ".min.js", | ||
url: json.name + ".min.js.map", | ||
} | ||
} | ||
|
||
var result = uglify.minify(buf.toString(), uglifyOpts) | ||
fs.writeFileSync(outputFile + ".min.js", result.code) | ||
if (result.map) fs.writeFileSync(outputFile + ".min.js.map", result.map) | ||
if (standalone) fs.writeFileSync(outputFile + ".bundle.js", buf) | ||
if (result.warnings) { | ||
for (var j = 0, jl = result.warnings.length; j < jl; ++j) { | ||
console.warn("UglifyJS warning:", result.warnings[j]) | ||
} | ||
} | ||
}) | ||
const fs = require("fs") | ||
const path = require("path") | ||
const browserify = require("browserify") | ||
const {minify} = require("terser") | ||
|
||
const json = require(path.join(__dirname, "..", "package.json")) | ||
const bundleDir = path.join(__dirname, "..", "bundle") | ||
if (!fs.existsSync(bundleDir)) fs.mkdirSync(bundleDir) | ||
|
||
browserify({standalone: "Ajv"}) | ||
.require(path.join(__dirname, "..", json.main), {expose: json.name}) | ||
.bundle(saveAndMinify) | ||
|
||
async function saveAndMinify(err, buf) { | ||
if (err) { | ||
console.error("browserify error:", err) | ||
process.exit(1) | ||
} | ||
|
||
const bundlePath = path.join(bundleDir, json.name) | ||
const opts = { | ||
ecma: 2018, | ||
warnings: true, | ||
compress: { | ||
pure_getters: true, | ||
keep_infinity: true, | ||
unsafe_methods: true, | ||
}, | ||
format: { | ||
preamble: `/* ${json.name} ${json.version}: ${json.description} */`, | ||
}, | ||
sourceMap: { | ||
filename: json.name + ".min.js", | ||
url: json.name + ".min.js.map", | ||
}, | ||
} | ||
|
||
const result = await minify(buf.toString(), opts) | ||
|
||
fs.writeFileSync(bundlePath + ".bundle.js", buf) | ||
fs.writeFileSync(bundlePath + ".min.js", result.code) | ||
fs.writeFileSync(bundlePath + ".min.js.map", result.map) | ||
if (result.warnings) result.warnings.forEach((msg) => console.warn("terser.minify warning:", msg)) | ||
} |
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
Oops, something went wrong.