| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- var fs = require('fs-extra');
- var os = require('os');
- var path = require("path");
- var host = require("./Host");
- var atomicRoot = host.atomicRoot;
- var glob = require('glob');
- var Tslint = require("tslint");
- namespace('build', function() {
- // Linting task
- task('lint_typescript', {
- async: true
- }, function(fileMask, failOnError) {
- console.log("TSLINT: Linting files in " + fileMask);
- var lintConfig = JSON.parse(fs.readFileSync("./Script/tslint.json"));
- var options = {
- configuration: lintConfig,
- formatter: "prose"
- };
- // lint
- // Since TSLint does not yet support recursively searching for files, then we need to
- // create a command per file. The main issue with this is that it will abort on the first error instead
- // of listing out all lint errors
- glob(fileMask, function(err, results) {
- var lintErrors = [];
- results.forEach(function(filename) {
- var contents = fs.readFileSync(filename, "utf8");
- var ll = new Tslint(filename, contents, options);
- var result = ll.lint();
- if (result.failureCount > 0) {
- lintErrors.push(result.output);
- }
- });
- if (lintErrors.length > 0) {
- console.warn("TSLINT: WARNING - Lint errors detected");
- console.warn(lintErrors.join(''));
- if (failOnError) {
- fail("TSLint errors detected");
- }
- }
- complete();
- });
- });
- // precreate script bindgs so they can be picked up by CMake
- task('precreateScriptBindings', {
- async: true
- }, function(platform, clean) {
- if (clean === undefined) {
- clean = true;
- }
- console.log("Precreating script bindings for platorm: " + platform);
- if (clean) {
- common.cleanCreateDir(common.getGenScriptRootDir(platform))
- }
- common.createGenScriptFiles(platform);
- complete();
- });
- function fileExists(filePath)
- {
- try
- {
- return fs.statSync(filePath).isFile();
- }
- catch (err)
- {
- return false;
- }
- }
- task('genscripts', {
- async: true
- }, function(platform, force) {
- if (force === undefined) {
- force = true;
- }
- var anyZero = false;
- if (!force) {
- var filenames = common.getGenScriptFilenames(platform);
- for (var i in filenames) {
- if (!fileExists(filenames[i]))
- {
- console.log("genscripts: file missing, regenerating script bindings: " + filenames[i]);
- anyZero = true;
- break;
- }
- var stats = fs.statSync(filenames[i]);
- if (stats["size"] == 0) {
- console.log("genscripts: file zero size, regenerating script bindings: " + filenames[i]);
- anyZero = true;
- break;
- }
- }
- if (!anyZero)
- return;
- }
- process.chdir(atomicRoot);
- var modules = host.getScriptModules(platform);
- var bindCmd = host.atomicTool + " bind \"" + atomicRoot + "\" ";
- var node;
- var tsc = "./Build/node_modules/typescript/lib/tsc";
- var tslint = "./Build/node_modules/tslint/lib/tslint-cli";
- var dtsGenerator = "./Build/node_modules/dts-generator/bin/dts-generator";
- switch(os.platform()) {
- case "win32":
- node = "Build\\Windows\\node\\node.exe";
- break;
- case "darwin":
- node = "Build/Mac/node/node";
- break;
- case "linux":
- node = "Build/Linux/node/node";
- break;
- }
- var cmds = [];
- for (var pkgName in modules) {
- cmds.push(bindCmd + "Script/Packages/" + pkgName + "/ " + platform);
- }
- if (node) {
- // compile
- cmds.push(node + " " + tsc + " -p ./Script");
- cmds.push(node + " " + tsc + " -p ./Script/AtomicWebViewEditor");
- // generate combined atomic.d.ts
- cmds.push(node + " " + dtsGenerator + " --name Atomic --project ./Script/TypeScript --out ./Script/TypeScript/dist/Atomic.d.ts");
- var lintTask = jake.Task['build:lint_typescript'];
- lintTask.addListener('complete', function () {
- console.log("\n\nLint: Typescript linting complete.\n\n");
- jake.exec(cmds, function() {
- // copy some external dependencies into the editor modules directory
- var editorModulesDir = "./Artifacts/Build/Resources/EditorData/AtomicEditor/EditorScripts/AtomicEditor/modules";
- var webeditorModulesDir = "./Data/AtomicEditor/CodeEditor/source/editorCore/modules";
- var nodeModulesDir = "./Build/node_modules";
- fs.mkdirsSync(editorModulesDir);
- // TypeScript
- fs.copySync(nodeModulesDir + "/typescript/lib/typescript.js", webeditorModulesDir + "/typescript.js")
- // copy lib.core.d.ts into the tool data directory
- fs.mkdirsSync("./Artifacts/Build/Resources/EditorData/AtomicEditor/EditorScripts/AtomicEditor/TypeScriptSupport");
- fs.copySync("./Build/node_modules/typescript/lib/lib.core.d.ts","./Data/AtomicEditor/TypeScriptSupport/lib.core.d.ts")
- // copy the combined Atomic.d.ts to the tool data directory
- fs.copySync("./Script/TypeScript/dist/Atomic.d.ts","./Data/AtomicEditor/TypeScriptSupport/Atomic.d.ts")
- complete();
- }, {
- printStdout: true
- });
- });
- lintTask.invoke("{./Script/AtomicEditor/**/*.ts,./Script/AtomicWebViewEditor/**/*.ts}", false);
- } else {
- throw new Error("Node not configured for this platform: " + os.platform());
- }
- });
- }); // end of build namespace
|