mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 15:12:12 +00:00
Also bundle definition files with asc
This commit is contained in:
parent
118cf95d25
commit
9678ce839e
26
bin/asc.js
26
bin/asc.js
@ -22,15 +22,15 @@ try {
|
||||
|
||||
// Common constants
|
||||
|
||||
const VERSION = typeof BUNDLE_VERSION === "string" ? BUNDLE_VERSION : require("../package.json").version + (isDev ? "-dev" : "");
|
||||
const OPTIONS = require("./asc.json");
|
||||
const isBundle = typeof BUNDLE_VERSION === "string";
|
||||
const VERSION = exports.version = isBundle ? BUNDLE_VERSION : require("../package.json").version + (isDev ? "-dev" : "");
|
||||
const OPTIONS = exports.options = require("./asc.json");
|
||||
const SOURCEMAP_ROOT = "assemblyscript:///";
|
||||
const LIBRARY_PREFIX = assemblyscript.LIBRARY_PREFIX;
|
||||
const DEFAULT_OPTIMIZE_LEVEL = 2;
|
||||
const DEFAULT_SHRINK_LEVEL = 1;
|
||||
const LIBRARY = typeof BUNDLE_LIBRARY !== "undefined" ? BUNDLE_LIBRARY : {};
|
||||
|
||||
exports.VERSION = VERSION;
|
||||
const DEFAULT_OPTIMIZE_LEVEL = exports.defaultOptimizeLevel = 2;
|
||||
const DEFAULT_SHRINK_LEVEL = exports.defaultShrinkLevel = 1;
|
||||
const LIBRARY_FILES = exports.libraryFiles = isBundle ? BUNDLE_LIBRARY : {};
|
||||
const DEFINITION_FILES = exports.definitionFiles = isBundle ? BUNDLE_DEFINITIONS : {};
|
||||
|
||||
function main(argv, options, callback) {
|
||||
if (typeof options === "function") {
|
||||
@ -151,8 +151,8 @@ function main(argv, options, callback) {
|
||||
// Load library file if explicitly requested
|
||||
if (sourcePath.startsWith(LIBRARY_PREFIX)) {
|
||||
for (let i = 0, k = libDirs.length; i < k; ++i) {
|
||||
if (LIBRARY.hasOwnProperty(sourcePath))
|
||||
sourceText = LIBRARY[sourcePath];
|
||||
if (LIBRARY_FILES.hasOwnProperty(sourcePath))
|
||||
sourceText = LIBRARY_FILES[sourcePath];
|
||||
else {
|
||||
sourceText = readFile(path.join(libDirs[i], sourcePath.substring(LIBRARY_PREFIX.length) + ".ts"));
|
||||
if (sourceText !== null) {
|
||||
@ -169,8 +169,8 @@ function main(argv, options, callback) {
|
||||
sourceText = readFile(path.join(baseDir, sourcePath, "index.ts"));
|
||||
if (sourceText === null) {
|
||||
for (let i = 0, k = libDirs.length; i < k; ++i) {
|
||||
if (LIBRARY.hasOwnProperty(LIBRARY_PREFIX + sourcePath))
|
||||
sourceText = LIBRARY[LIBRARY_PREFIX + sourcePath];
|
||||
if (LIBRARY_FILES.hasOwnProperty(LIBRARY_PREFIX + sourcePath))
|
||||
sourceText = LIBRARY_FILES[LIBRARY_PREFIX + sourcePath];
|
||||
else {
|
||||
sourceText = readFile(path.join(libDirs[i], sourcePath + ".ts"));
|
||||
if (sourceText !== null) {
|
||||
@ -196,10 +196,10 @@ function main(argv, options, callback) {
|
||||
// Include (other) library components
|
||||
var hasBundledLibrary = false;
|
||||
if (!args.noLib)
|
||||
Object.keys(LIBRARY).forEach(libPath => {
|
||||
Object.keys(LIBRARY_FILES).forEach(libPath => {
|
||||
if (libPath.lastIndexOf("/") >= LIBRARY_PREFIX.length) return;
|
||||
stats.parseCount++;
|
||||
stats.parseTime += measure(() => { parser = assemblyscript.parseFile(LIBRARY[libPath], libPath + ".ts", parser, false); });
|
||||
stats.parseTime += measure(() => { parser = assemblyscript.parseFile(LIBRARY_FILES[libPath], libPath + ".ts", parser, false); });
|
||||
hasBundledLibrary = true;
|
||||
});
|
||||
for (let i = 0, k = libDirs.length; i < k; ++i) {
|
||||
|
4
dist/asc.js
vendored
4
dist/asc.js
vendored
File diff suppressed because one or more lines are too long
2
dist/assemblyscript.js.map
vendored
2
dist/assemblyscript.js.map
vendored
File diff suppressed because one or more lines are too long
@ -1,5 +1,7 @@
|
||||
var asc = require("../dist/asc.js");
|
||||
|
||||
console.log(Object.keys(asc));
|
||||
|
||||
var stdout = asc.createMemoryStream();
|
||||
var stderr = asc.createMemoryStream();
|
||||
var stats = asc.createStats();
|
||||
|
@ -71,13 +71,13 @@ const bin = {
|
||||
const libDir = path.join(__dirname, "std", "assembly");
|
||||
const libFiles = require("glob").sync("**/*.ts", { cwd: libDir });
|
||||
const lib = {};
|
||||
libFiles.forEach(file => {
|
||||
// console.log("bundling '(lib)/" + file + "'");
|
||||
var source = fs.readFileSync(path.join(libDir, file), { encoding: "utf8" });
|
||||
lib["(lib)/" + file.replace(/\.ts$/, "")] = JSON.stringify(source);
|
||||
});
|
||||
libFiles.forEach(file => lib["(lib)/" + file.replace(/\.ts$/, "")] = bundleFile(path.join(libDir, file)));
|
||||
return lib;
|
||||
})(),
|
||||
BUNDLE_DEFINITIONS: {
|
||||
"assembly": bundleFile(path.join(__dirname, "std", "assembly.d.ts")),
|
||||
"portable": bundleFile(path.join(__dirname, "std", "portable.d.ts"))
|
||||
},
|
||||
__dirname: JSON.stringify(".")
|
||||
}),
|
||||
new webpack.IgnorePlugin(/\.\/src|package\.json|^(ts\-node|glob|source\-map\-support)$/),
|
||||
@ -91,4 +91,8 @@ const bin = {
|
||||
]
|
||||
};
|
||||
|
||||
function bundleFile(filename) {
|
||||
return JSON.stringify(fs.readFileSync(filename, { encoding: "utf8" }).replace(/\r\n/g, "\n"));
|
||||
}
|
||||
|
||||
module.exports = [ lib, bin ];
|
||||
|
Loading…
x
Reference in New Issue
Block a user