Skip to content

Commit

Permalink
Update template for direct gulp build
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrichina committed Apr 3, 2019
1 parent aaddacb commit d176f9b
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 5 deletions.
92 changes: 92 additions & 0 deletions blank_project/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const gulp = require("gulp");

gulp.task("build:model", callback => {
generateBindings("model.ts", "../out/model.near.ts", callback);
});

gulp.task("build:bindings", ["build:model"], callback => {
generateBindings("main.ts", "../out/main.near.ts", callback);
});

gulp.task("build", ["build:bindings"], callback => {
compile("../out/main.near.ts", "../out/main.wasm", callback);
});

gulp.task("default", ["build"]);

// TODO: Extract all following boilerplate into library

// This task is not required when running the project locally. Its purpose is to set up the
// AssemblyScript compiler when a new project has been loaded in WebAssembly Studio.
gulp.task("project:load", () => {
const utils = require("@wasm/studio-utils");
utils.eval(utils.project.getFile("setup.js").getData(), {
logLn,
project,
monaco,
fileTypeForExtension,
});
});

function generateBindings(inputFile, outputFile, callback) {
const asc = getAsc();
asc.main([
inputFile,
"--baseDir", "assembly",
"--nearFile", outputFile,
"--measure"
], callback);
}

function compile(inputFile, outputFile, callback) {
const asc = getAsc();
asc.main([
inputFile,
"--baseDir", "assembly",
"--binaryFile", outputFile,
"--sourceMap",
"--measure"
], callback);
}

let asc;
function getAsc() {
if (asc) {
return asc;
}

asc = require("assemblyscript/bin/asc");
if (asc.runningInStudio) {
return asc;
}

const fs = require("fs");
const pathModule = require("path");
asc.main = (main => (args, options, fn) => {
if (typeof options === "function") {
fn = options;
options = undefined;
}

return main(args, options || {
stdout: process.stdout,
stderr: process.stderr,
readFile: (filename, baseDir) => {
baseDir = pathModule.relative(process.cwd(), baseDir);
let path = pathModule.join(baseDir, filename);
if (path.startsWith("out/") && path.indexOf(".near.ts") == -1) {
path = path.replace(/^out/, baseDir );
} else if (path.startsWith(baseDir) && path.indexOf(".near.ts") != -1) {
path = path.replace(new RegExp("^" + baseDir), "out");
}
return fs.readFileSync(path).toString("utf8");
},
writeFile: (filename, contents) => {
const name = filename.startsWith("../") ? filename.substring(3) : filename;
fs.writeFileSync(name, contents);
},
listFiles: () => []
}, fn);
})(asc.main);
return asc;
}
16 changes: 11 additions & 5 deletions blank_project/package.json
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
{
"name": "@wasm/hello_world_ts",
"description": "",
"version": "1.0.0",
"version": "0.0.1",
"scripts": {
"build": "node_modules/near-shell/near build",
"test": "jest test --env=./src/local_test_environment.js",
"test-on-devnet": "jest test --env=./src/devnet_test_environment.js"
"build": "mkdir -p out/ && gulp",
"deploy:contract": "near deploy --account_id=near-hello-devnet --node_url=https://studio.nearprotocol.com/devnet",
"deploy:pages": "gh-pages -d src",
"deploy": "npm run build && npm run deploy:contract && npm run deploy:pages",
"prestart": "npm run build && npm run deploy:contract",
"start": "python3 -mhttp.server --directory src",
"test": "npm run build && jest test --env=near-shell/local_test_environment",
"test-on-devnet": "npm run build && jest test --env=near-shell/devnet_test_environment"
},
"devDependencies": {
"assemblyscript": "github:nearprotocol/assemblyscript.git",
"gulp": "^3",
"assemblyscript-json": "github:nearprotocol/assemblyscript-json",
"gh-pages": "^2.0.1",
"gulp": "^3",
"jest": "^22.4.4",
"jest-environment-node": "^24.5.0",
"near-runtime-ts": "github:nearprotocol/near-runtime-ts",
Expand Down

0 comments on commit d176f9b

Please sign in to comment.