2015-02-04 04:27:00 +03:00
|
|
|
/**
|
|
|
|
* Instructions for updating this file.
|
|
|
|
* - this file must be updated everytime a new cross-folder dependency is added
|
|
|
|
* into any of the [refs.ts] file. For instance, if suddenly you add a
|
2015-02-05 04:38:49 +03:00
|
|
|
* reference to [../storage/whatever.ts] in [build/libwinRT.ts], then you must
|
|
|
|
* update the dependencies of the [build/libwinRT.d.ts] task.
|
2015-02-04 04:27:00 +03:00
|
|
|
**/
|
2015-02-05 03:47:33 +03:00
|
|
|
var assert = require('assert');
|
2015-02-04 04:27:00 +03:00
|
|
|
var child_process = require("child_process");
|
|
|
|
var fs = require("fs");
|
|
|
|
|
2015-02-05 04:38:49 +03:00
|
|
|
jake.addListener("start", function () {
|
|
|
|
if (!fs.existsSync("build"))
|
|
|
|
fs.mkdirSync("build");
|
|
|
|
});
|
2015-02-04 04:27:00 +03:00
|
|
|
|
|
|
|
// The list of files generated by the build.
|
2015-02-05 02:13:44 +03:00
|
|
|
var generated = [
|
|
|
|
'shell/npm/package.json',
|
|
|
|
'touchdevelop.tgz',
|
|
|
|
'results.html',
|
|
|
|
'results.json',
|
|
|
|
'browser.js',
|
|
|
|
'shell/npm/bin/touchdevelop.js',
|
|
|
|
];
|
2015-02-04 04:27:00 +03:00
|
|
|
|
2015-02-05 04:38:49 +03:00
|
|
|
// This function tries to be "smart" about the target.
|
|
|
|
// - if the target is of the form "build/foobar.ts", the output is bundled with
|
|
|
|
// [--out] into "build/foobar.js", and "build/foobar.d.ts" is also generated;
|
|
|
|
// - otherwise, the file is just compiled as a single file into the "build/"
|
|
|
|
// directory
|
|
|
|
function mkSimpleTask(production, dependencies, target) {
|
|
|
|
var tscCall = [
|
|
|
|
"node node_modules/typescript/bin/tsc",
|
|
|
|
"--noEmitOnError",
|
|
|
|
"--target ES5",
|
|
|
|
"--module commonjs",
|
|
|
|
"--declaration", // not always strictly needed, but better be safe than sorry
|
|
|
|
];
|
|
|
|
var match = target.match(/(\w+)\/refs.ts/);
|
|
|
|
if (match) {
|
|
|
|
tscCall.push("--out build/"+match[1]+".js");
|
|
|
|
} else {
|
|
|
|
tscCall.push("--outDir build/");
|
|
|
|
}
|
|
|
|
tscCall.push(target);
|
2015-02-04 04:27:00 +03:00
|
|
|
return file(production, dependencies, { async: true }, function () {
|
|
|
|
console.log("[B] "+production);
|
2015-02-05 04:38:49 +03:00
|
|
|
jake.exec(tscCall.join(" "), { printStdout: true }, function () {
|
2015-02-04 04:27:00 +03:00
|
|
|
complete();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// A series of compile-and-run rules that generate various files for the build
|
|
|
|
// system. They currently have to run from the [build] directory but this is
|
|
|
|
// FIXME
|
|
|
|
|
|
|
|
function runInBuildAndComplete(cmds) {
|
|
|
|
process.chdir("build");
|
|
|
|
jake.exec(cmds, {}, function() {
|
|
|
|
process.chdir("..");
|
|
|
|
complete();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-02-05 04:38:49 +03:00
|
|
|
mkSimpleTask('build/genmeta.js', [ 'tools', ], "tools/genmeta.ts");
|
|
|
|
file('build/api.js', [ "build/genmeta.js" ], { async: true }, function () {
|
2015-02-04 04:27:00 +03:00
|
|
|
console.log("[P] generating build/api.js, localization.json and topiclist.json");
|
|
|
|
runInBuildAndComplete([
|
2015-02-05 04:38:49 +03:00
|
|
|
"node genmeta.js",
|
2015-02-04 04:27:00 +03:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2015-02-05 04:38:49 +03:00
|
|
|
mkSimpleTask('build/addCssPrefixes.js', [ 'tools' ], "tools/addCssPrefixes.ts");
|
|
|
|
task('css-prefixes', [ "build/addCssPrefixes.js" ], { async: true }, function () {
|
2015-02-04 04:27:00 +03:00
|
|
|
console.log("[P] modifying in-place all css files");
|
|
|
|
runInBuildAndComplete([
|
2015-02-05 04:38:49 +03:00
|
|
|
"node addCssPrefixes.js"
|
2015-02-04 04:27:00 +03:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2015-02-05 04:38:49 +03:00
|
|
|
mkSimpleTask('build/shell.js', [ 'shell/shell.ts' ], "shell/shell.ts");
|
|
|
|
mkSimpleTask('build/package.js', [ 'shell/package.ts', 'build/shell.js' ], "shell/package.ts");
|
|
|
|
file('build/pkgshell.js', [ 'build/package.js' ], { async: true }, function () {
|
2015-02-04 04:27:00 +03:00
|
|
|
console.log("[P] generating build/pkgshell.js and packaging");
|
|
|
|
runInBuildAndComplete([
|
2015-02-05 04:38:49 +03:00
|
|
|
"node package.js"
|
2015-02-04 04:27:00 +03:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// These dependencies have been hand-crafted by reading the various [refs.ts]
|
|
|
|
// files. The dependencies inside the same folder are coarse-grained: for
|
2015-02-05 04:38:49 +03:00
|
|
|
// instance, anytime something changes in [editor/], [build/editor.d.ts] gets
|
2015-02-04 04:27:00 +03:00
|
|
|
// rebuilt. This amounts to assuming that for all [foo/bar.ts], [bar.ts] appears
|
2015-02-05 04:38:49 +03:00
|
|
|
// in [build/foo.ts].
|
|
|
|
mkSimpleTask('build/browser.d.ts', [
|
2015-02-04 04:27:00 +03:00
|
|
|
'browser/browser.ts'
|
2015-02-05 04:38:49 +03:00
|
|
|
], "browser/browser.ts");
|
|
|
|
mkSimpleTask('build/rt.d.ts', [
|
|
|
|
'build/browser.d.ts',
|
2015-02-04 04:27:00 +03:00
|
|
|
'rt',
|
|
|
|
'lib'
|
2015-02-05 04:38:49 +03:00
|
|
|
], "rt/refs.ts");
|
|
|
|
mkSimpleTask('build/storage.d.ts', [
|
|
|
|
'build/rt.d.ts',
|
2015-02-04 04:27:00 +03:00
|
|
|
'rt/typings.d.ts',
|
2015-02-05 04:38:49 +03:00
|
|
|
'build/browser.d.ts',
|
2015-02-04 04:27:00 +03:00
|
|
|
'storage'
|
2015-02-05 04:38:49 +03:00
|
|
|
], "storage/refs.ts");
|
|
|
|
mkSimpleTask('build/ast.d.ts', [
|
|
|
|
'build/rt.d.ts',
|
2015-02-04 04:27:00 +03:00
|
|
|
'ast'
|
2015-02-05 04:38:49 +03:00
|
|
|
], "ast/refs.ts");
|
|
|
|
mkSimpleTask('build/libwinRT.d.ts', [
|
|
|
|
'build/rt.d.ts',
|
|
|
|
'build/browser.d.ts',
|
2015-02-04 04:27:00 +03:00
|
|
|
'libwinRT'
|
2015-02-05 04:38:49 +03:00
|
|
|
], "libwinRT/refs.ts");
|
|
|
|
mkSimpleTask('build/libwab.d.ts', [
|
|
|
|
'build/rt.d.ts',
|
2015-02-04 04:27:00 +03:00
|
|
|
'rt/typings.d.ts',
|
2015-02-05 04:38:49 +03:00
|
|
|
'build/browser.d.ts',
|
2015-02-04 04:27:00 +03:00
|
|
|
'libwab'
|
2015-02-05 04:38:49 +03:00
|
|
|
], "libwab/refs.ts");
|
|
|
|
mkSimpleTask('build/libnode.d.ts', [
|
|
|
|
'build/rt.d.ts',
|
2015-02-04 04:27:00 +03:00
|
|
|
'rt/typings.d.ts',
|
|
|
|
'libnode'
|
2015-02-05 04:38:49 +03:00
|
|
|
], "libnode/refs.ts");
|
|
|
|
mkSimpleTask('build/libcordova.d.ts', [
|
|
|
|
'build/rt.d.ts',
|
2015-02-04 04:27:00 +03:00
|
|
|
'rt/typings.d.ts',
|
2015-02-05 04:38:49 +03:00
|
|
|
'build/browser.d.ts',
|
2015-02-04 04:27:00 +03:00
|
|
|
'libcordova'
|
2015-02-05 04:38:49 +03:00
|
|
|
], "libcordova/refs.ts");
|
|
|
|
mkSimpleTask('build/editor.d.ts', [
|
2015-02-04 04:27:00 +03:00
|
|
|
'rt/typings.d.ts',
|
2015-02-05 04:38:49 +03:00
|
|
|
'build/browser.d.ts',
|
|
|
|
'build/rt.d.ts',
|
|
|
|
'build/ast.d.ts',
|
|
|
|
'build/storage.d.ts',
|
|
|
|
'build/libwinRT.d.ts',
|
|
|
|
'build/libwab.d.ts',
|
|
|
|
'build/libcordova.d.ts',
|
2015-02-04 04:27:00 +03:00
|
|
|
'intellitrain',
|
|
|
|
'editor'
|
2015-02-05 04:38:49 +03:00
|
|
|
], "editor/refs.ts");
|
|
|
|
mkSimpleTask('build/officemix.d.ts', [
|
2015-02-04 04:27:00 +03:00
|
|
|
'officemix'
|
2015-02-05 04:38:49 +03:00
|
|
|
], "officemix/officemix.ts");
|
|
|
|
mkSimpleTask('build/jsonapi.d.ts', [], "noderunner/jsonapi.ts");
|
|
|
|
mkSimpleTask('build/client.js', [
|
2015-02-04 04:27:00 +03:00
|
|
|
'rt/typings.d.ts',
|
2015-02-05 04:38:49 +03:00
|
|
|
'build/jsonapi.d.ts'
|
|
|
|
], "nodeclient/client.ts");
|
2015-02-04 04:27:00 +03:00
|
|
|
// XXX coarse-grained dependencies here over the whole 'noderunner' directory
|
2015-02-05 04:38:49 +03:00
|
|
|
mkSimpleTask('build/runner.js', [
|
|
|
|
'build/browser.d.ts',
|
2015-02-04 04:27:00 +03:00
|
|
|
'rt/typings.d.ts',
|
2015-02-05 04:38:49 +03:00
|
|
|
'build/rt.d.ts',
|
|
|
|
'build/ast.d.ts',
|
|
|
|
'build/libnode.d.ts',
|
2015-02-04 04:27:00 +03:00
|
|
|
'noderunner'
|
2015-02-05 04:38:49 +03:00
|
|
|
], "noderunner/runner.ts");
|
2015-02-04 04:27:00 +03:00
|
|
|
// XXX same here
|
2015-02-05 04:38:49 +03:00
|
|
|
mkSimpleTask('build/runner.d.ts', [
|
|
|
|
'build/browser.d.ts',
|
2015-02-04 04:27:00 +03:00
|
|
|
'rt/typings.d.ts',
|
2015-02-05 04:38:49 +03:00
|
|
|
'build/rt.d.ts',
|
|
|
|
'build/storage.d.ts',
|
|
|
|
'build/libwinRT.d.ts',
|
|
|
|
'build/libwab.d.ts',
|
|
|
|
'build/libnode.d.ts',
|
|
|
|
'build/libcordova.d.ts',
|
2015-02-04 04:27:00 +03:00
|
|
|
'runner'
|
2015-02-05 04:38:49 +03:00
|
|
|
], "runner/refs.ts");
|
2015-02-04 04:27:00 +03:00
|
|
|
// XXX same here
|
2015-02-05 04:38:49 +03:00
|
|
|
mkSimpleTask('build/mc.d.ts', [
|
|
|
|
'build/browser.d.ts',
|
2015-02-04 04:27:00 +03:00
|
|
|
'rt/typings.d.ts',
|
2015-02-05 04:38:49 +03:00
|
|
|
'build/rt.d.ts',
|
|
|
|
'build/storage.d.ts',
|
2015-02-04 04:27:00 +03:00
|
|
|
'mc'
|
2015-02-05 04:38:49 +03:00
|
|
|
], "mc/refs.ts");
|
2015-02-04 04:27:00 +03:00
|
|
|
|
|
|
|
|
|
|
|
// Now come the rules for files that are obtained by concatenating multiple
|
2015-02-04 20:27:14 +03:00
|
|
|
// _js_ files into another one. The sequence exactly reproduces what happened
|
|
|
|
// previously, as there are ordering issues with initialization of global variables
|
|
|
|
// (unsurprisingly). Here's the semantics of these entries:
|
|
|
|
// - files ending with ".js" end up as dependencies (either as rule names, or as
|
|
|
|
// statically-checked-in files in the repo, such as [langs.js]), and are
|
|
|
|
// concatenated in the final file
|
|
|
|
// - files without an extension generate a dependency on the ".d.ts" rule and
|
|
|
|
// the ".js" compiled file ends up in the concatenation
|
2015-02-04 04:27:00 +03:00
|
|
|
var concatMap = {
|
2015-02-04 20:27:14 +03:00
|
|
|
"mcrunner.js": [
|
2015-02-05 04:38:49 +03:00
|
|
|
"build/rt",
|
|
|
|
"build/storage",
|
|
|
|
"build/mc",
|
2015-02-04 20:27:14 +03:00
|
|
|
],
|
|
|
|
"noderunner.js": [
|
2015-02-05 04:38:49 +03:00
|
|
|
"build/browser",
|
|
|
|
"build/rt",
|
|
|
|
"build/ast",
|
2015-02-04 20:27:14 +03:00
|
|
|
"build/api.js",
|
2015-02-05 04:38:49 +03:00
|
|
|
"generated/langs.js",
|
|
|
|
"build/libnode",
|
2015-02-04 20:27:14 +03:00
|
|
|
"build/pkgshell.js",
|
2015-02-05 04:38:49 +03:00
|
|
|
"build/runner.js",
|
2015-02-04 20:27:14 +03:00
|
|
|
],
|
|
|
|
"runtime.js": [
|
2015-02-05 04:38:49 +03:00
|
|
|
"build/rt",
|
|
|
|
"build/storage",
|
|
|
|
"build/libwinRT",
|
|
|
|
"build/libwab",
|
|
|
|
"build/libnode",
|
|
|
|
"build/libcordova",
|
|
|
|
"build/runner",
|
2015-02-04 20:27:14 +03:00
|
|
|
],
|
|
|
|
"main.js": [
|
2015-02-05 04:38:49 +03:00
|
|
|
"build/rt",
|
|
|
|
"build/ast",
|
2015-02-04 20:27:14 +03:00
|
|
|
"build/api.js",
|
2015-02-05 04:38:49 +03:00
|
|
|
"generated/langs.js",
|
|
|
|
"build/storage",
|
|
|
|
"build/libwinRT",
|
|
|
|
"build/libwab",
|
|
|
|
"build/libcordova",
|
2015-02-04 20:27:14 +03:00
|
|
|
"build/pkgshell.js",
|
2015-02-05 04:38:49 +03:00
|
|
|
"build/editor" ,
|
2015-02-04 20:27:14 +03:00
|
|
|
],
|
2015-02-04 04:27:00 +03:00
|
|
|
};
|
|
|
|
|
2015-02-05 04:38:49 +03:00
|
|
|
generated = generated.concat(Object.keys(concatMap));
|
2015-02-05 02:13:44 +03:00
|
|
|
|
2015-02-04 20:09:17 +03:00
|
|
|
// Apparently our node scripts can't run without this line.
|
|
|
|
var nodePrelude = "var window = {};\n";
|
|
|
|
|
2015-02-04 04:27:00 +03:00
|
|
|
Object.keys(concatMap).forEach(function (f) {
|
2015-02-04 20:27:14 +03:00
|
|
|
var isJs = function (s) { return s.substr(s.length - 3, 3) == ".js"; };
|
|
|
|
var buildDeps = concatMap[f].map(function (x) { if (isJs(x)) return x; else return x + ".d.ts"; });
|
|
|
|
var toConcat = concatMap[f].map(function (x) { if (isJs(x)) return x; else return x + ".js"; });
|
|
|
|
file(f, buildDeps, function () {
|
2015-02-04 04:27:00 +03:00
|
|
|
console.log("[C]", f);
|
2015-02-04 20:09:17 +03:00
|
|
|
var bufs = [];
|
|
|
|
bufs.push(new Buffer(nodePrelude));
|
2015-02-04 04:27:00 +03:00
|
|
|
toConcat.forEach(function (f) {
|
2015-02-04 20:09:17 +03:00
|
|
|
bufs.push(fs.readFileSync(f));
|
2015-02-04 04:27:00 +03:00
|
|
|
});
|
2015-02-04 20:09:17 +03:00
|
|
|
fs.writeFileSync(f, Buffer.concat(bufs));
|
2015-02-04 04:27:00 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Our targets are the concatenated files, which are the final result of the
|
|
|
|
// compilation. We also re-run the CSS prefixes thingy everytime.
|
|
|
|
task('default', [ 'css-prefixes' ].concat(Object.keys(concatMap)), function () {
|
2015-02-04 22:38:08 +03:00
|
|
|
console.log("[I] build completed.");
|
2015-02-04 04:27:00 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
task('clean', [], function () {
|
|
|
|
// XXX do this in a single call? check out https://github.com/mde/utilities/blob/master/lib/file.js
|
|
|
|
generated.forEach(function (f) { jake.rmRf(f); });
|
2015-02-05 04:38:49 +03:00
|
|
|
jake.rmRf('build');
|
2015-02-04 04:27:00 +03:00
|
|
|
});
|
|
|
|
|
2015-02-04 22:48:06 +03:00
|
|
|
task('test', [ 'nodeclient/client.js', 'default' ], { async: true }, function () {
|
2015-02-05 03:47:33 +03:00
|
|
|
console.log("[I] running tests")
|
2015-02-05 03:31:57 +03:00
|
|
|
jake.exec([ 'node nodeclient/client.js buildtest' ],
|
|
|
|
{ printStdout: true, printStderr: true },
|
|
|
|
function() { complete(); });
|
2015-02-04 04:27:00 +03:00
|
|
|
});
|
|
|
|
|
2015-02-05 03:31:57 +03:00
|
|
|
task('ci', [], { async : true }, function() {
|
|
|
|
if (!process.env.TRAVIS) {
|
2015-02-05 04:09:31 +03:00
|
|
|
console.log("[I] not in travis, skipping upload");
|
2015-02-05 03:31:57 +03:00
|
|
|
complete();
|
|
|
|
} else {
|
2015-02-05 04:09:31 +03:00
|
|
|
assert(process.env.TRAVIS_BUILD_NUMBER, "missing travis build number");
|
|
|
|
assert(process.env.TD_UPLOAD_KEY, "missing touchdevelop upload key");
|
2015-02-05 03:31:57 +03:00
|
|
|
var buildVersion = 80000 + parseInt(process.env.TRAVIS_BUILD_NUMBER);
|
|
|
|
console.log("[I] uploading v" + buildVersion)
|
|
|
|
// TODO: upload data
|
|
|
|
complete();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-02-05 02:44:47 +03:00
|
|
|
task('run', [ 'default' ], { async: true }, function (port) {
|
|
|
|
port = port || 80;
|
2015-02-04 22:38:08 +03:00
|
|
|
// XXX fix this too
|
2015-02-05 04:38:49 +03:00
|
|
|
console.log("[F] copying build/browser.js to browser.js");
|
2015-02-04 22:38:08 +03:00
|
|
|
if (fs.exists("browser.js"))
|
|
|
|
fs.unlink("browser.js");
|
2015-02-05 04:38:49 +03:00
|
|
|
fs.writeFileSync("browser.js", fs.readFileSync("build/browser.js"));
|
2015-02-04 20:09:17 +03:00
|
|
|
jake.exec(
|
2015-02-05 02:44:47 +03:00
|
|
|
[ 'node noderunner '+port+' silent ' ],
|
2015-02-04 20:09:17 +03:00
|
|
|
{ printStdout: true, printStderr: true },
|
|
|
|
function() { complete(); }
|
|
|
|
);
|
2015-02-04 04:27:00 +03:00
|
|
|
});
|
2015-02-04 22:31:42 +03:00
|
|
|
|
2015-02-05 02:49:22 +03:00
|
|
|
task('local', [ 'default' ], { async: true }, function() {
|
2015-02-04 22:31:42 +03:00
|
|
|
jake.exec(
|
|
|
|
[ 'node shell/shell.js TD_ALLOW_EDITOR=true TD_LOCAL_EDITOR_PATH=.' ],
|
|
|
|
{ printStdout: true, printStderr: true },
|
|
|
|
function() { complete(); }
|
|
|
|
)
|
|
|
|
})
|
2015-02-05 02:49:22 +03:00
|
|
|
|
|
|
|
task('update-docs', [ 'nodeclient/client.js', 'default' ], { async: true }, function() {
|
|
|
|
jake.exec(
|
|
|
|
[ 'node nodeclient/client.js updatehelp',
|
|
|
|
'node nodeclient/client.js updatelang' ],
|
|
|
|
{ printStdout: true, printStderr: true },
|
|
|
|
function() { complete(); }
|
|
|
|
)
|
|
|
|
})
|
2015-02-05 04:26:19 +03:00
|
|
|
|
|
|
|
|
2015-02-05 04:24:12 +03:00
|
|
|
// vim: ft=javascript
|