mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-26 15:32:16 +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
|
// Common constants
|
||||||
|
|
||||||
const VERSION = typeof BUNDLE_VERSION === "string" ? BUNDLE_VERSION : require("../package.json").version + (isDev ? "-dev" : "");
|
const isBundle = typeof BUNDLE_VERSION === "string";
|
||||||
const OPTIONS = require("./asc.json");
|
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 SOURCEMAP_ROOT = "assemblyscript:///";
|
||||||
const LIBRARY_PREFIX = assemblyscript.LIBRARY_PREFIX;
|
const LIBRARY_PREFIX = assemblyscript.LIBRARY_PREFIX;
|
||||||
const DEFAULT_OPTIMIZE_LEVEL = 2;
|
const DEFAULT_OPTIMIZE_LEVEL = exports.defaultOptimizeLevel = 2;
|
||||||
const DEFAULT_SHRINK_LEVEL = 1;
|
const DEFAULT_SHRINK_LEVEL = exports.defaultShrinkLevel = 1;
|
||||||
const LIBRARY = typeof BUNDLE_LIBRARY !== "undefined" ? BUNDLE_LIBRARY : {};
|
const LIBRARY_FILES = exports.libraryFiles = isBundle ? BUNDLE_LIBRARY : {};
|
||||||
|
const DEFINITION_FILES = exports.definitionFiles = isBundle ? BUNDLE_DEFINITIONS : {};
|
||||||
exports.VERSION = VERSION;
|
|
||||||
|
|
||||||
function main(argv, options, callback) {
|
function main(argv, options, callback) {
|
||||||
if (typeof options === "function") {
|
if (typeof options === "function") {
|
||||||
@ -151,8 +151,8 @@ function main(argv, options, callback) {
|
|||||||
// Load library file if explicitly requested
|
// Load library file if explicitly requested
|
||||||
if (sourcePath.startsWith(LIBRARY_PREFIX)) {
|
if (sourcePath.startsWith(LIBRARY_PREFIX)) {
|
||||||
for (let i = 0, k = libDirs.length; i < k; ++i) {
|
for (let i = 0, k = libDirs.length; i < k; ++i) {
|
||||||
if (LIBRARY.hasOwnProperty(sourcePath))
|
if (LIBRARY_FILES.hasOwnProperty(sourcePath))
|
||||||
sourceText = LIBRARY[sourcePath];
|
sourceText = LIBRARY_FILES[sourcePath];
|
||||||
else {
|
else {
|
||||||
sourceText = readFile(path.join(libDirs[i], sourcePath.substring(LIBRARY_PREFIX.length) + ".ts"));
|
sourceText = readFile(path.join(libDirs[i], sourcePath.substring(LIBRARY_PREFIX.length) + ".ts"));
|
||||||
if (sourceText !== null) {
|
if (sourceText !== null) {
|
||||||
@ -169,8 +169,8 @@ function main(argv, options, callback) {
|
|||||||
sourceText = readFile(path.join(baseDir, sourcePath, "index.ts"));
|
sourceText = readFile(path.join(baseDir, sourcePath, "index.ts"));
|
||||||
if (sourceText === null) {
|
if (sourceText === null) {
|
||||||
for (let i = 0, k = libDirs.length; i < k; ++i) {
|
for (let i = 0, k = libDirs.length; i < k; ++i) {
|
||||||
if (LIBRARY.hasOwnProperty(LIBRARY_PREFIX + sourcePath))
|
if (LIBRARY_FILES.hasOwnProperty(LIBRARY_PREFIX + sourcePath))
|
||||||
sourceText = LIBRARY[LIBRARY_PREFIX + sourcePath];
|
sourceText = LIBRARY_FILES[LIBRARY_PREFIX + sourcePath];
|
||||||
else {
|
else {
|
||||||
sourceText = readFile(path.join(libDirs[i], sourcePath + ".ts"));
|
sourceText = readFile(path.join(libDirs[i], sourcePath + ".ts"));
|
||||||
if (sourceText !== null) {
|
if (sourceText !== null) {
|
||||||
@ -196,10 +196,10 @@ function main(argv, options, callback) {
|
|||||||
// Include (other) library components
|
// Include (other) library components
|
||||||
var hasBundledLibrary = false;
|
var hasBundledLibrary = false;
|
||||||
if (!args.noLib)
|
if (!args.noLib)
|
||||||
Object.keys(LIBRARY).forEach(libPath => {
|
Object.keys(LIBRARY_FILES).forEach(libPath => {
|
||||||
if (libPath.lastIndexOf("/") >= LIBRARY_PREFIX.length) return;
|
if (libPath.lastIndexOf("/") >= LIBRARY_PREFIX.length) return;
|
||||||
stats.parseCount++;
|
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;
|
hasBundledLibrary = true;
|
||||||
});
|
});
|
||||||
for (let i = 0, k = libDirs.length; i < k; ++i) {
|
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");
|
var asc = require("../dist/asc.js");
|
||||||
|
|
||||||
|
console.log(Object.keys(asc));
|
||||||
|
|
||||||
var stdout = asc.createMemoryStream();
|
var stdout = asc.createMemoryStream();
|
||||||
var stderr = asc.createMemoryStream();
|
var stderr = asc.createMemoryStream();
|
||||||
var stats = asc.createStats();
|
var stats = asc.createStats();
|
||||||
|
@ -71,13 +71,13 @@ const bin = {
|
|||||||
const libDir = path.join(__dirname, "std", "assembly");
|
const libDir = path.join(__dirname, "std", "assembly");
|
||||||
const libFiles = require("glob").sync("**/*.ts", { cwd: libDir });
|
const libFiles = require("glob").sync("**/*.ts", { cwd: libDir });
|
||||||
const lib = {};
|
const lib = {};
|
||||||
libFiles.forEach(file => {
|
libFiles.forEach(file => lib["(lib)/" + file.replace(/\.ts$/, "")] = bundleFile(path.join(libDir, file)));
|
||||||
// console.log("bundling '(lib)/" + file + "'");
|
|
||||||
var source = fs.readFileSync(path.join(libDir, file), { encoding: "utf8" });
|
|
||||||
lib["(lib)/" + file.replace(/\.ts$/, "")] = JSON.stringify(source);
|
|
||||||
});
|
|
||||||
return lib;
|
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(".")
|
__dirname: JSON.stringify(".")
|
||||||
}),
|
}),
|
||||||
new webpack.IgnorePlugin(/\.\/src|package\.json|^(ts\-node|glob|source\-map\-support)$/),
|
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 ];
|
module.exports = [ lib, bin ];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user