зеркало из https://github.com/microsoft/TACO.git
Last design:
packagedDepenencies Bin, src,tools folders under root
This commit is contained in:
Родитель
68fe1d818e
Коммит
0e24cd32be
|
@ -1,55 +0,0 @@
|
|||
/// <reference path="../typings/node/node.d.ts" />
|
||||
/// <reference path="../utility/typescriptUtil.ts" />
|
||||
/// <reference path="../utility/styleCopUtil.ts" />
|
||||
|
||||
var fs = require("fs");
|
||||
var gulp = require("gulp");
|
||||
var path = require("path");
|
||||
var typescriptUtil = require("../utility/typescriptUtil");
|
||||
var styleCopUtil = require("../utility/styleCopUtil");
|
||||
var eventStream = require("event-stream");
|
||||
var concat = require("gulp-concat");
|
||||
var del = require("del");
|
||||
|
||||
var compilerPath = {
|
||||
src: "../../..", // gulp task compiles all source under "taco-cli" source folder
|
||||
bin: "../..",
|
||||
};
|
||||
|
||||
////////////////// to add additional gulp tasks, add gulpfile in folder and reference it below
|
||||
// for example: require('./src/compile/gulpfile');
|
||||
///////////////////////
|
||||
|
||||
/* Project wide tasks below, 1 entry for each gulp task */
|
||||
gulp.task("default", ["compilerDefault", "compilerStyleCop"]);
|
||||
|
||||
/* Default task for compiler - runs clean, compile, combine. */
|
||||
gulp.task("compilerDefault", ["compilerClean", "compilerCompile", "compilerStyleCop"]);
|
||||
|
||||
/* Compiles the typescript files in the project. */
|
||||
gulp.task("compilerCompile", ["compilerClean"], function (cb: Function): void {
|
||||
var tsUtil = new typescriptUtil.CordovaTools.TypescriptServices();
|
||||
console.log("compilerPath.src: " + path.resolve(compilerPath.src));
|
||||
console.log("compilerPath.bin: " + path.resolve(compilerPath.bin));
|
||||
tsUtil.compileDirectory(compilerPath.src, compilerPath.bin, cb);
|
||||
});
|
||||
|
||||
/* Cleans up the bin location. */
|
||||
gulp.task("compilerClean", function (cb: Function): void {
|
||||
del([compilerPath.bin + "**"], cb);
|
||||
});
|
||||
|
||||
/* Runs style cop on the sources. */
|
||||
gulp.task("compilerStyleCop", function (cb: Function): void {
|
||||
var copFile = "../../../../../Internal/TSStyleCop/TSStyleCop.js";
|
||||
if (!fs.existsSync("copFile")) {
|
||||
var styleCop = new styleCopUtil.CordovaTools.StyleCopUtil();
|
||||
styleCop.runCop(compilerPath.src, copFile, cb);
|
||||
}
|
||||
});
|
||||
|
||||
/* Task to generate NPM package */
|
||||
|
||||
/* Test */
|
||||
|
||||
module.exports = gulp;
|
|
@ -1,79 +0,0 @@
|
|||
//boostrap project
|
||||
|
||||
var exec = require("child_process").exec,
|
||||
fs = require("fs");
|
||||
path = require('path');
|
||||
|
||||
console.log("************************************************************");
|
||||
console.log("Preparing taco-cli project for first use.....");
|
||||
console.log("Run 'gulp' in ./bin/taco-cli/taco-cli to build the project.");
|
||||
console.log("************************************************************\n\n");
|
||||
|
||||
//delete folder recursively
|
||||
var deleteFolderRecursive = function (path) {
|
||||
if (fs.existsSync(path)) {
|
||||
fs.readdirSync(path).forEach(function (file, index) {
|
||||
var curPath = path + "/" + file;
|
||||
if (fs.lstatSync(curPath).isDirectory()) { // recurse
|
||||
deleteFolderRecursive(curPath);
|
||||
} else { // delete file
|
||||
fs.unlinkSync(curPath);
|
||||
}
|
||||
});
|
||||
fs.rmdirSync(path);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var run = function () {
|
||||
if (fs.existsSync("bin")) {
|
||||
console.log("---removing bin folder")
|
||||
deleteFolderRecursive("bin")
|
||||
}
|
||||
|
||||
//compile root gulptfile.ts
|
||||
var compileMainGulp = function () {
|
||||
var gulpJS = "./bin/taco-cli/taco-cli/gulpfile.js";
|
||||
exec("tsc gulpfile.ts --outdir bin/taco-cli --module commonjs", { cwd: "." }, function (error, stdout, stderr) {
|
||||
if (fs.existsSync(gulpJS)) {
|
||||
console.log("---compiled " + gulpJS);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var installGlobalPackage = function (packageName) {
|
||||
packageCommand = "npm ls -g " + packageName;
|
||||
var result = exec(packageCommand, function (error, stdout, stderr) {
|
||||
if (stdout.indexOf(packageName) > -1) {
|
||||
console.log("---found '" + packageName + "' installed globally");
|
||||
} else {
|
||||
console.log("---did not find " + packageName + " installed globally, installing.....")
|
||||
exec("npm install -g " + packageName);
|
||||
}
|
||||
|
||||
if (packageName == "typescript") {
|
||||
compileMainGulp();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
//install global packages
|
||||
installGlobalPackage("typescript");
|
||||
|
||||
|
||||
////npm install on relevant folders
|
||||
var foldersToPrep = ["."];
|
||||
|
||||
foldersToPrep.forEach(function (folder) {
|
||||
console.log("---NPM install on folder: " + path.resolve(folder));
|
||||
var npmProcess = exec("npm install", { cwd: folder }, function (error, stdout, stderr) { compileMainGulp() });
|
||||
});
|
||||
|
||||
|
||||
|
||||
installGlobalPackage("gulp");
|
||||
};
|
||||
|
||||
run();
|
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"a": ""
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
// Type definitions for Apache Cordova
|
||||
// Project: http://cordova.apache.org
|
||||
// Definitions by: Microsoft Open Technologies Inc. <http://msopentech.com>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
//
|
||||
// Copyright (c) Microsoft Open Technologies, Inc.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
/// <reference path="plugins/BatteryStatus.d.ts"/>
|
||||
/// <reference path="plugins/Camera.d.ts"/>
|
||||
/// <reference path="plugins/Contacts.d.ts"/>
|
||||
/// <reference path="plugins/Device.d.ts"/>
|
||||
/// <reference path="plugins/DeviceMotion.d.ts"/>
|
||||
/// <reference path="plugins/DeviceOrientation.d.ts"/>
|
||||
/// <reference path="plugins/Dialogs.d.ts"/>
|
||||
/// <reference path="plugins/FileSystem.d.ts"/>
|
||||
/// <reference path="plugins/FileTransfer.d.ts"/>
|
||||
/// <reference path="plugins/Globalization.d.ts"/>
|
||||
/// <reference path="plugins/InAppBrowser.d.ts"/>
|
||||
/// <reference path="plugins/Media.d.ts"/>
|
||||
/// <reference path="plugins/MediaCapture.d.ts"/>
|
||||
/// <reference path="plugins/NetworkInformation.d.ts"/>
|
||||
/// <reference path="plugins/Push.d.ts"/>
|
||||
/// <reference path="plugins/Splashscreen.d.ts"/>
|
||||
/// <reference path="plugins/Vibration.d.ts"/>
|
||||
/// <reference path="plugins/WebSQL.d.ts"/>
|
||||
|
||||
interface Cordova {
|
||||
/** Invokes native functionality by specifying corresponding service name, action and optional parameters.
|
||||
* @param success A success callback function.
|
||||
* @param fail An error callback function.
|
||||
* @param service The service name to call on the native side (corresponds to a native class).
|
||||
* @param action The action name to call on the native side (generally corresponds to the native class method).
|
||||
* @param args An array of arguments to pass into the native environment.
|
||||
*/
|
||||
exec(success: () => any, fail: () => any, service: string, action: string, args?: string[]): void;
|
||||
/** Gets the operating system name. */
|
||||
platformId: string;
|
||||
/** Gets Cordova framework version */
|
||||
version: string;
|
||||
/** Defines custom logic as a Cordova module. Other modules can later access it using module name provided. */
|
||||
define(moduleName: string, factory: (require: any, exports: any, module: any) => any): void;
|
||||
/** Access a Cordova module by name. */
|
||||
require(moduleName: string): any;
|
||||
}
|
||||
|
||||
interface Document {
|
||||
addEventListener(type: "deviceready", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "pause", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "resume", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "backbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "menubutton", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "searchbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "startcallbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "endcallbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "volumedownbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "volumeupbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
|
||||
removeEventListener(type: "deviceready", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
removeEventListener(type: "pause", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
removeEventListener(type: "resume", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
removeEventListener(type: "backbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
removeEventListener(type: "menubutton", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
removeEventListener(type: "searchbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
removeEventListener(type: "startcallbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
removeEventListener(type: "endcallbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
removeEventListener(type: "volumedownbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
removeEventListener(type: "volumeupbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
|
||||
addEventListener(type: string, listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
removeEventListener(type: string, listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
}
|
||||
|
||||
// cordova/argscheck module
|
||||
interface ArgsCheck {
|
||||
checkArgs(argsSpec: string, functionName: string, args: any[], callee?: any): void;
|
||||
getValue(value?: any, defaultValue?: any): any;
|
||||
enableChecks: boolean;
|
||||
}
|
||||
|
||||
// cordova/urlutil module
|
||||
interface UrlUtil {
|
||||
makeAbsolute(url: string): string
|
||||
}
|
||||
|
||||
/** Apache Cordova instance */
|
||||
declare var cordova: Cordova;
|
|
@ -1,168 +0,0 @@
|
|||
/// <reference path="node.d.ts" />
|
||||
|
||||
import assert = require("assert");
|
||||
import fs = require("fs");
|
||||
import events = require("events");
|
||||
import zlib = require("zlib");
|
||||
import url = require('url');
|
||||
import util = require("util");
|
||||
import crypto = require("crypto");
|
||||
import http = require("http");
|
||||
import net = require("net");
|
||||
import dgram = require("dgram");
|
||||
|
||||
assert(1 + 1 - 2 === 0, "The universe isn't how it should.");
|
||||
|
||||
assert.deepEqual({ x: { y: 3 } }, { x: { y: 3 } }, "DEEP WENT DERP");
|
||||
|
||||
assert.equal(3, "3", "uses == comparator");
|
||||
|
||||
assert.notStrictEqual(2, "2", "uses === comparator");
|
||||
|
||||
assert.throws(() => { throw "a hammer at your face"; }, undefined, "DODGED IT");
|
||||
|
||||
assert.doesNotThrow(() => {
|
||||
if (false) { throw "a hammer at your face"; }
|
||||
}, undefined, "What the...*crunch*");
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
/// File system tests : http://nodejs.org/api/fs.html
|
||||
////////////////////////////////////////////////////
|
||||
fs.writeFile("thebible.txt",
|
||||
"Do unto others as you would have them do unto you.",
|
||||
assert.ifError);
|
||||
|
||||
fs.writeFile("Harry Potter",
|
||||
"\"You be wizzing, Harry,\" jived Dumbledore.",
|
||||
{
|
||||
encoding: "ascii"
|
||||
},
|
||||
assert.ifError);
|
||||
|
||||
var content: string,
|
||||
buffer: Buffer;
|
||||
|
||||
content = fs.readFileSync('testfile', 'utf8');
|
||||
content = fs.readFileSync('testfile', {encoding : 'utf8'});
|
||||
buffer = fs.readFileSync('testfile');
|
||||
buffer = fs.readFileSync('testfile', {flag : 'r'});
|
||||
fs.readFile('testfile', 'utf8', (err, data) => content = data);
|
||||
fs.readFile('testfile', {encoding : 'utf8'}, (err, data) => content = data);
|
||||
fs.readFile('testfile', (err, data) => buffer = data);
|
||||
fs.readFile('testfile', {flag : 'r'}, (err, data) => buffer = data);
|
||||
|
||||
class Networker extends events.EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.emit("mingling");
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
/// Url tests : http://nodejs.org/api/url.html
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
url.format(url.parse('http://www.example.com/xyz'));
|
||||
|
||||
// https://google.com/search?q=you're%20a%20lizard%2C%20gary
|
||||
url.format({
|
||||
protocol: 'https',
|
||||
host: "google.com",
|
||||
pathname: 'search',
|
||||
query: { q: "you're a lizard, gary" }
|
||||
});
|
||||
|
||||
var helloUrl = url.parse('http://example.com/?hello=world', true)
|
||||
assert.equal(helloUrl.query.hello, 'world');
|
||||
|
||||
|
||||
// Old and new util.inspect APIs
|
||||
util.inspect(["This is nice"], false, 5);
|
||||
util.inspect(["This is nice"], { colors: true, depth: 5, customInspect: false });
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
/// Stream tests : http://nodejs.org/api/stream.html
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
// http://nodejs.org/api/stream.html#stream_readable_pipe_destination_options
|
||||
function stream_readable_pipe_test() {
|
||||
var r = fs.createReadStream('file.txt');
|
||||
var z = zlib.createGzip();
|
||||
var w = fs.createWriteStream('file.txt.gz');
|
||||
r.pipe(z).pipe(w);
|
||||
r.close();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
/// Crypto tests : http://nodejs.org/api/crypto.html
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
var hmacResult: string = crypto.createHmac('md5', 'hello').update('world').digest('hex');
|
||||
|
||||
function crypto_cipher_decipher_string_test() {
|
||||
var key:Buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7]);
|
||||
var clearText:string = "This is the clear text.";
|
||||
var cipher:crypto.Cipher = crypto.createCipher("aes-128-ecb", key);
|
||||
var cipherText:string = cipher.update(clearText, "utf8", "hex");
|
||||
cipherText += cipher.final("hex");
|
||||
|
||||
var decipher:crypto.Decipher = crypto.createDecipher("aes-128-ecb", key);
|
||||
var clearText2:string = decipher.update(cipherText, "hex", "utf8");
|
||||
clearText2 += decipher.final("utf8");
|
||||
|
||||
assert.equal(clearText2, clearText);
|
||||
}
|
||||
|
||||
function crypto_cipher_decipher_buffer_test() {
|
||||
var key:Buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7]);
|
||||
var clearText:Buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4]);
|
||||
var cipher:crypto.Cipher = crypto.createCipher("aes-128-ecb", key);
|
||||
var cipherBuffers:Buffer[] = [];
|
||||
cipherBuffers.push(cipher.update(clearText));
|
||||
cipherBuffers.push(cipher.final());
|
||||
|
||||
var cipherText:Buffer = Buffer.concat(cipherBuffers);
|
||||
|
||||
var decipher:crypto.Decipher = crypto.createDecipher("aes-128-ecb", key);
|
||||
var decipherBuffers:Buffer[] = [];
|
||||
decipherBuffers.push(decipher.update(cipherText));
|
||||
decipherBuffers.push(decipher.final());
|
||||
|
||||
var clearText2:Buffer = Buffer.concat(decipherBuffers);
|
||||
|
||||
assert.deepEqual(clearText2, clearText);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
// Make sure .listen() and .close() retuern a Server instance
|
||||
http.createServer().listen(0).close().address();
|
||||
net.createServer().listen(0).close().address();
|
||||
|
||||
var request = http.request('http://0.0.0.0');
|
||||
request.once('error', function () {});
|
||||
request.setNoDelay(true);
|
||||
request.abort();
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
/// Http tests : http://nodejs.org/api/http.html
|
||||
////////////////////////////////////////////////////
|
||||
module http_tests {
|
||||
// Status codes
|
||||
var code = 100;
|
||||
var codeMessage = http.STATUS_CODES['400'];
|
||||
var codeMessage = http.STATUS_CODES[400];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
/// Dgram tests : http://nodejs.org/api/dgram.html
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
var ds: dgram.Socket = dgram.createSocket("udp4", (msg: Buffer, rinfo: dgram.RemoteInfo): void => {
|
||||
});
|
||||
var ai: dgram.AddressInfo = ds.address();
|
||||
ds.send(new Buffer("hello"), 0, 5, 5000, "127.0.0.1", (error: Error, bytes: number): void => {
|
||||
});
|
||||
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
"use strict";
|
||||
import fs = require ("fs");
|
||||
import path = require ("path");
|
||||
|
||||
var resources = null;
|
||||
var defaultLanguage: string = "en";
|
||||
|
||||
export function init(language: string, resourcesDir?: string): void {
|
||||
if (!resourcesDir) {
|
||||
resourcesDir = path.join(__dirname, "..", "resources");
|
||||
}
|
||||
|
||||
var lang = bestLanguageMatchOrDefault(language, resourcesDir);
|
||||
resources = loadLanguage(lang, resourcesDir);
|
||||
}
|
||||
|
||||
export function getString(id: string, ...optionalArgs: any[]): string {
|
||||
if (!resources) {
|
||||
throw new Error("Resources have not been loaded");
|
||||
}
|
||||
|
||||
var s = resources[id];
|
||||
if (!s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
var args = getOptionalArgsArrayFromFunctionCall(arguments, 1);
|
||||
if (args) {
|
||||
for (var i: number = 0; i < args.length; i++) {
|
||||
s = s.replace("{" + i + "}", args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
function bestLanguageMatchOrDefault(language: string, resourcesDir: string): string {
|
||||
if (!language) {
|
||||
return defaultLanguage;
|
||||
}
|
||||
|
||||
var supportedLanguages: string[] = [];
|
||||
fs.readdirSync(resourcesDir).filter(function (c: string): boolean {
|
||||
return fs.existsSync(path.join(resourcesDir, c, "resources.json"));
|
||||
}).forEach(function (l: string): void {
|
||||
supportedLanguages.push(l.toLowerCase());
|
||||
});
|
||||
|
||||
// TODO: remove assumption of case insensitive file system, so this can work on non-windows systems.
|
||||
var lang = language.toLowerCase();
|
||||
if (supportedLanguages.indexOf(lang) !== -1) {
|
||||
// exact match on language, which could include the region (e.g. it-CH), return the match
|
||||
return lang;
|
||||
}
|
||||
|
||||
var primaryLang = lang.split("-")[0];
|
||||
if (supportedLanguages.indexOf(primaryLang) !== -1) {
|
||||
// match on primary language (e.g. it from it-CH).
|
||||
return primaryLang;
|
||||
}
|
||||
|
||||
return defaultLanguage;
|
||||
}
|
||||
|
||||
function loadLanguage(language: string, resourcesDir: string): any {
|
||||
var resourcesPath = path.join(resourcesDir, language, "resources.json");
|
||||
return require(resourcesPath);
|
||||
}
|
||||
|
||||
function getOptionalArgsArrayFromFunctionCall(functionArguments: IArguments, startFrom: number): any[] {
|
||||
if (functionArguments.length <= startFrom) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (Array.isArray(functionArguments[startFrom])) {
|
||||
return functionArguments[startFrom];
|
||||
}
|
||||
|
||||
return Array.prototype.slice.apply(functionArguments, [startFrom]);
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/// <reference path="typings/node.d.ts" />
|
||||
|
||||
var fs = require("fs");
|
||||
var gulp = require("gulp");
|
||||
var path = require("path");
|
||||
var exec = require("child_process").exec;
|
||||
import typescriptUtil = require("../tools/typescript-util");
|
||||
import styleCopUtil = require("../tools/stylecop-util");
|
||||
var del = require("del");
|
||||
|
||||
var compilerPath = {
|
||||
src: "../../src", // gulp task compiles all source under "taco-cli" source folder
|
||||
bin: "../../bin",
|
||||
};
|
||||
|
||||
////////////////// to add additional gulp tasks, add gulpfile in folder and reference it below
|
||||
// for example: require('./src/compile/gulpfile');
|
||||
///////////////////////
|
||||
|
||||
/* Default task for compiler - runs clean, compile, combine. */
|
||||
gulp.task("default", ["installBinDependencies", "styleCop"]);
|
||||
|
||||
/* Compiles the typescript files in the project. */
|
||||
gulp.task("fast-compile", function (cb: Function): void {
|
||||
var tsUtil = new typescriptUtil.TacoUtils.TypescriptServices();
|
||||
console.log("compilerPath.src: " + path.resolve(compilerPath.src));
|
||||
console.log("compilerPath.bin: " + path.resolve(compilerPath.bin));
|
||||
tsUtil.compileDirectory(compilerPath.src, compilerPath.bin, cb);
|
||||
});
|
||||
|
||||
gulp.task("compile", ["clean"], function (cb: Function): void {
|
||||
var tsUtil = new typescriptUtil.TacoUtils.TypescriptServices();
|
||||
console.log("compilerPath.src: " + path.resolve(compilerPath.src));
|
||||
console.log("compilerPath.bin: " + path.resolve(compilerPath.bin));
|
||||
tsUtil.compileDirectory(compilerPath.src, compilerPath.bin, cb);
|
||||
});
|
||||
|
||||
/* Runs style cop on the sources. */
|
||||
gulp.task("styleCop", function (cb: Function): void {
|
||||
var copFile = "../../tools/TSStyleCop/TSStyleCop.js";
|
||||
if (fs.existsSync("copFile")) {
|
||||
var styleCop = new styleCopUtil.TacoUtils.StyleCopUtil();
|
||||
styleCop.runCop(compilerPath.src, copFile, cb);
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
});
|
||||
|
||||
/* Cleans up the bin location. */
|
||||
gulp.task("clean", function (cb: Function): void {
|
||||
del([compilerPath.bin + "**"], { force: true }, cb);
|
||||
});
|
||||
|
||||
/* copy package.json files from source to bin */
|
||||
gulp.task("copyPackageJSON", ["compile"], function (cb: Function): void {
|
||||
var cliPath: string = "/taco-cli/package.json";
|
||||
var utilPath: string = "/taco-utility/package.json";
|
||||
fs.writeFileSync("../../bin" + cliPath, fs.readFileSync("../../src" + cliPath));
|
||||
fs.writeFileSync("../../bin" + utilPath, fs.readFileSync("../../src" + utilPath));
|
||||
cb();
|
||||
});
|
||||
|
||||
gulp.task("installBinDependencies", ["copyPackageJSON"], function (cb: Function): void {
|
||||
exec("npm install", { cwd: "../../bin/taco-cli" }, cb);
|
||||
});
|
||||
|
||||
/* Task to generate NPM package */
|
||||
|
||||
/* Test */
|
||||
|
||||
module.exports = gulp;
|
|
@ -0,0 +1,39 @@
|
|||
var exec = require("child_process").exec,
|
||||
fs = require("fs"),
|
||||
path = require('path'),
|
||||
gulp = require("gulp");
|
||||
|
||||
/*default task*/
|
||||
gulp.task("default", ["runCompiledGulp"], function (cb) {
|
||||
console.log("************************************************************");
|
||||
console.log("Prepared taco-cli project for first use.....");
|
||||
console.log("Run 'gulp' in current folder or 'gulp --gulpfile gulp-compile.js' in ../build/src for subsequent builds");
|
||||
console.log("************************************************************\n\n");
|
||||
});
|
||||
|
||||
/* Runs style cop on the sources. */
|
||||
gulp.task("runCompiledGulp", ["compileTSGulpFiles"], function (cb) {
|
||||
exec("gulp --gulpfile gulp-compile.js", { cwd: "../build/src" }, cb);
|
||||
});
|
||||
|
||||
/* Runs style cop on the sources. */
|
||||
gulp.task("compileTSGulpFiles", ["installRootFolderGulp", "installRootFolderTypeScript", "installRootFolderDel"], function (cb) {
|
||||
exec("tsc gulp-compile.ts --outdir ../build --module commonjs", { cwd: "." }, cb);
|
||||
});
|
||||
|
||||
/* install gulp in root folder */
|
||||
gulp.task("installRootFolderGulp", function (cb) {
|
||||
exec("npm install gulp", { cwd: ".." }, cb);
|
||||
});
|
||||
|
||||
/* install typescript in root folder */
|
||||
gulp.task("installRootFolderTypeScript", function (cb) {
|
||||
exec("npm install typescript", { cwd: ".." }, cb);
|
||||
});
|
||||
|
||||
/* install typescript in root folder */
|
||||
gulp.task("installRootFolderDel", function (cb) {
|
||||
exec("npm install del", { cwd: ".." }, cb);
|
||||
});
|
||||
|
||||
module.exports = gulp;
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"name": "taco-root",
|
||||
"author": {
|
||||
"name": "Microsoft Corp."
|
||||
},
|
||||
"description": "dependencies needed for initial Gulp use",
|
||||
"homepage": "",
|
||||
"version": "0.0.1",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://xxxxxxxxxxgithub.com/Microsoft/taco-cli.git"
|
||||
},
|
||||
"keywords": [
|
||||
"Cordova",
|
||||
"Microsoft",
|
||||
"taco",
|
||||
"Apache",
|
||||
"cross-platform"
|
||||
],
|
||||
"main": "utility.js",
|
||||
"dependencies": {
|
||||
"cordova": "^4.2.0",
|
||||
"nconf": "^0.7.1",
|
||||
"nopt": "^3.0.1",
|
||||
"q": "^1.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": ">=1.4.1",
|
||||
"del": "^1.0.0",
|
||||
"event-stream": "^3.1.7",
|
||||
"gulp": "^3.8.10",
|
||||
"gulp-concat": "^2.4.2",
|
||||
"jake": "latest",
|
||||
"mocha": "latest"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
///<reference path="../../typings/taco-utility.d.ts"/>
|
||||
///<reference path="../../typings/node.d.ts"/>
|
||||
///<reference path="../../typings/nopt.d.ts"/>
|
||||
|
||||
import tacoUtility = require("taco-utility");
|
||||
import nopt = require("nopt");
|
||||
import path = require("path");
|
||||
|
||||
|
||||
class Taco {
|
||||
tacoResources: tacoUtility.Resources;
|
||||
constructor() {
|
||||
this.tacoResources = new tacoUtility.Resources("abc");
|
||||
}
|
||||
run(): void {
|
||||
console.log(this.tacoResources.getString("usage"));
|
||||
var knownOpts =
|
||||
{
|
||||
'verbose': Boolean
|
||||
, 'version': Boolean
|
||||
, 'help': Boolean
|
||||
, 'silent': Boolean
|
||||
, 'experimental': Boolean
|
||||
, 'noregistry': Boolean
|
||||
, 'shrinkwrap': Boolean
|
||||
, 'usegit': Boolean
|
||||
, 'copy-from': String
|
||||
, 'link-to': path
|
||||
, 'searchpath': String
|
||||
, 'variable': Array
|
||||
// Flags to be passed to `cordova build/run/emulate`
|
||||
, 'debug': Boolean
|
||||
, 'release': Boolean
|
||||
, 'archs': String
|
||||
, 'device': Boolean
|
||||
, 'emulator': Boolean
|
||||
, 'target': String
|
||||
, 'browserify': Boolean
|
||||
, 'nobuild': Boolean
|
||||
};
|
||||
|
||||
var shortHands =
|
||||
{
|
||||
'd': '--verbose'
|
||||
, 'v': '--version'
|
||||
, 'h': '--help'
|
||||
, 'src': '--copy-from'
|
||||
};
|
||||
|
||||
// If no inputArgs given, use process.argv.
|
||||
var inputArguments: string[] = process.argv;
|
||||
|
||||
var args = nopt.nopt(knownOpts, shortHands, inputArguments);
|
||||
console.info(args);
|
||||
|
||||
console.info("Number of command-line arguments - " + args.argv.remain.length);
|
||||
|
||||
for (var i = 0; i < args.argv.remain.length; ++i) {
|
||||
console.info(args.argv.remain[i]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var taco = new Taco();
|
||||
taco.run();
|
|
@ -38,8 +38,10 @@
|
|||
"cordova": "^4.2.0",
|
||||
"nconf": "^0.7.1",
|
||||
"nopt": "^3.0.1",
|
||||
"q": "^1.1.2"
|
||||
"q": "^1.1.2",
|
||||
"taco-utility": "file:../taco-utility"
|
||||
},
|
||||
"bundledDependencies": ["taco-utility"],
|
||||
"devDependencies": {
|
||||
"typescript": ">=1.4.1",
|
||||
"del": "^1.0.0",
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"Usage": "Usage: taco-cli command args",
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "taco-utility",
|
||||
"author": {
|
||||
"name": "Microsoft Corp."
|
||||
},
|
||||
"description": "strictly internal use to enable require in utility folder",
|
||||
"homepage": "",
|
||||
"version": "0.0.1",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://xxxxxxxxxxgithub.com/Microsoft/taco-cli.git"
|
||||
},
|
||||
"keywords": [
|
||||
"Cordova",
|
||||
"Microsoft",
|
||||
"taco",
|
||||
"Apache",
|
||||
"cross-platform"
|
||||
],
|
||||
"main": "taco-utility.js",
|
||||
"dependencies" : {
|
||||
"typescript": ">=1.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
///<reference path="../typings/node.d.ts"/>
|
||||
"use strict";
|
||||
|
||||
import fs = require("fs");
|
||||
import path = require("path");
|
||||
|
||||
module TacoUtility {
|
||||
|
||||
//put more classes here, known limitation that classes in external modules CANNOT span multiple files
|
||||
export class Remote {
|
||||
resources: any = null;
|
||||
defaultLanguage: string = "en";
|
||||
|
||||
constructor(language: string, resourcesDir?: string) {
|
||||
if (!resourcesDir) {
|
||||
resourcesDir = path.join(__dirname, "..", "resources");
|
||||
}
|
||||
|
||||
var lang = this.bestLanguageMatchOrDefault(language, resourcesDir);
|
||||
this.resources = this.loadLanguage(lang, resourcesDir);
|
||||
}
|
||||
|
||||
getString(id: string, ...optionalArgs: any[]): string {
|
||||
if (!this.resources) {
|
||||
throw new Error("Resources have not been loaded");
|
||||
}
|
||||
|
||||
var s = this.resources[id];
|
||||
if (!s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
var args = this.getOptionalArgsArrayFromFunctionCall(arguments, 1);
|
||||
if (args) {
|
||||
for (var i: number = 0; i < args.length; i++) {
|
||||
s = s.replace("{" + i + "}", args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bestLanguageMatchOrDefault(language: string, resourcesDir: string): string {
|
||||
if (!language) {
|
||||
return this.defaultLanguage;
|
||||
}
|
||||
|
||||
var supportedLanguages: string[] = [];
|
||||
fs.readdirSync(resourcesDir).filter(function (c: string): boolean {
|
||||
return fs.existsSync(path.join(resourcesDir, c, "resources.json"));
|
||||
}).forEach(function (l: string): void {
|
||||
supportedLanguages.push(l.toLowerCase());
|
||||
});
|
||||
|
||||
// TODO: remove assumption of case insensitive file system, so this can work on non-windows systems.
|
||||
var lang = language.toLowerCase();
|
||||
if (supportedLanguages.indexOf(lang) !== -1) {
|
||||
// exact match on language, which could include the region (e.g. it-CH), return the match
|
||||
return lang;
|
||||
}
|
||||
|
||||
var primaryLang = lang.split("-")[0];
|
||||
if (supportedLanguages.indexOf(primaryLang) !== -1) {
|
||||
// match on primary language (e.g. it from it-CH).
|
||||
return primaryLang;
|
||||
}
|
||||
|
||||
return this.defaultLanguage;
|
||||
}
|
||||
|
||||
loadLanguage(language: string, resourcesDir: string): any {
|
||||
var resourcesPath = path.join(resourcesDir, language, "resources.json");
|
||||
return require(resourcesPath);
|
||||
}
|
||||
|
||||
getOptionalArgsArrayFromFunctionCall(functionArguments: IArguments, startFrom: number): any[] {
|
||||
if (functionArguments.length <= startFrom) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (Array.isArray(functionArguments[startFrom])) {
|
||||
return functionArguments[startFrom];
|
||||
}
|
||||
|
||||
return Array.prototype.slice.apply(functionArguments, [startFrom]);
|
||||
}
|
||||
}
|
||||
export class Resources {
|
||||
resources: any = null;
|
||||
defaultLanguage: string = "en";
|
||||
|
||||
constructor(language: string, resourcesDir?: string) {
|
||||
if (!resourcesDir) {
|
||||
resourcesDir = path.join(__dirname, "..", "resources");
|
||||
}
|
||||
|
||||
var lang = this.bestLanguageMatchOrDefault(language, resourcesDir);
|
||||
this.resources = this.loadLanguage(lang, resourcesDir);
|
||||
}
|
||||
|
||||
getString(id: string, ...optionalArgs: any[]): string {
|
||||
if (!this.resources) {
|
||||
throw new Error("Resources have not been loaded");
|
||||
}
|
||||
|
||||
var s = this.resources[id];
|
||||
if (!s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
var args = this.getOptionalArgsArrayFromFunctionCall(arguments, 1);
|
||||
if (args) {
|
||||
for (var i: number = 0; i < args.length; i++) {
|
||||
s = s.replace("{" + i + "}", args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bestLanguageMatchOrDefault(language: string, resourcesDir: string): string {
|
||||
if (!language) {
|
||||
return this.defaultLanguage;
|
||||
}
|
||||
|
||||
var supportedLanguages: string[] = [];
|
||||
fs.readdirSync(resourcesDir).filter(function (c: string): boolean {
|
||||
return fs.existsSync(path.join(resourcesDir, c, "resources.json"));
|
||||
}).forEach(function (l: string): void {
|
||||
supportedLanguages.push(l.toLowerCase());
|
||||
});
|
||||
|
||||
// TODO: remove assumption of case insensitive file system, so this can work on non-windows systems.
|
||||
var lang = language.toLowerCase();
|
||||
if (supportedLanguages.indexOf(lang) !== -1) {
|
||||
// exact match on language, which could include the region (e.g. it-CH), return the match
|
||||
return lang;
|
||||
}
|
||||
|
||||
var primaryLang = lang.split("-")[0];
|
||||
if (supportedLanguages.indexOf(primaryLang) !== -1) {
|
||||
// match on primary language (e.g. it from it-CH).
|
||||
return primaryLang;
|
||||
}
|
||||
|
||||
return this.defaultLanguage;
|
||||
}
|
||||
|
||||
loadLanguage(language: string, resourcesDir: string): any {
|
||||
var resourcesPath = path.join(resourcesDir, language, "resources.json");
|
||||
return require(resourcesPath);
|
||||
}
|
||||
|
||||
getOptionalArgsArrayFromFunctionCall(functionArguments: IArguments, startFrom: number): any[] {
|
||||
if (functionArguments.length <= startFrom) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (Array.isArray(functionArguments[startFrom])) {
|
||||
return functionArguments[startFrom];
|
||||
}
|
||||
|
||||
return Array.prototype.slice.apply(functionArguments, [startFrom]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export = TacoUtility;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
// Definitions by: Drew Noakes <https://drewnoakes.com>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
/// <reference path="node.d.ts" />
|
||||
|
||||
declare module gulp {
|
||||
|
|
@ -1,7 +1,11 @@
|
|||
// Type definitions for nopt
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
declare module 'nopt' {
|
||||
/// <reference path="node.d.ts" />
|
||||
declare module Nopt {
|
||||
export function nopt(types: any, shorthands: any, args: any, slice?: any): any;
|
||||
export function clean(data: any, types: any, typeDefs: any[]): any;
|
||||
}
|
||||
|
||||
declare module "nopt" {
|
||||
export = Nopt;
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/// <reference path="../typings/node.d.ts" />
|
||||
//declare module TacoUtility {
|
||||
// //put more classes definitions here, known limitation that classes definitions in external modules CANNOT span multiple files
|
||||
// export class Resources {
|
||||
// resources: any;
|
||||
// defaultLanguage: string;
|
||||
// constructor(language: string, resourcesDir?: string);
|
||||
// getString(id: string, ...optionalArgs: any[]): string;
|
||||
// bestLanguageMatchOrDefault(language: string, resourcesDir: string): string;
|
||||
// loadLanguage(language: string, resourcesDir: string): any;
|
||||
// getOptionalArgsArrayFromFunctionCall(functionArguments: IArguments, startFrom: number): any[];
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
//declare module "taco-utility" {
|
||||
// module TacoUtility {
|
||||
// class Resources {
|
||||
// resources: any;
|
||||
// defaultLanguage: string;
|
||||
// constructor(language: string, resourcesDir?: string);
|
||||
// getString(id: string, ...optionalArgs: any[]): string;
|
||||
// bestLanguageMatchOrDefault(language: string, resourcesDir: string): string;
|
||||
// loadLanguage(language: string, resourcesDir: string): any;
|
||||
// getOptionalArgsArrayFromFunctionCall(functionArguments: IArguments, startFrom: number): any[];
|
||||
// }
|
||||
// }
|
||||
// export = TacoUtility;
|
||||
//}
|
||||
|
||||
|
||||
/// <reference path="../typings/node.d.ts" />
|
||||
declare module TacoUtility {
|
||||
class Remote {
|
||||
resources: any;
|
||||
defaultLanguage: string;
|
||||
constructor(language: string, resourcesDir?: string);
|
||||
getString(id: string, ...optionalArgs: any[]): string;
|
||||
bestLanguageMatchOrDefault(language: string, resourcesDir: string): string;
|
||||
loadLanguage(language: string, resourcesDir: string): any;
|
||||
getOptionalArgsArrayFromFunctionCall(functionArguments: IArguments, startFrom: number): any[];
|
||||
}
|
||||
class Resources {
|
||||
resources: any;
|
||||
defaultLanguage: string;
|
||||
constructor(language: string, resourcesDir?: string);
|
||||
getString(id: string, ...optionalArgs: any[]): string;
|
||||
bestLanguageMatchOrDefault(language: string, resourcesDir: string): string;
|
||||
loadLanguage(language: string, resourcesDir: string): any;
|
||||
getOptionalArgsArrayFromFunctionCall(functionArguments: IArguments, startFrom: number): any[];
|
||||
}
|
||||
}
|
||||
|
||||
declare module "taco-utility" {
|
||||
export = TacoUtility;
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
import fs = require ("fs");
|
||||
import path = require ("path");
|
||||
|
||||
export module CordovaTools {
|
||||
export module TacoUtils {
|
||||
/**
|
||||
* Utility for launching TS style cop as a child process.
|
||||
*/
|
|
@ -1,10 +1,10 @@
|
|||
/// <reference path="../typings/typescript/typescript.d.ts" />
|
||||
/// <reference path="../src/typings/typescript.d.ts" />
|
||||
|
||||
import ts = require ("typescript");
|
||||
import fs = require ("fs");
|
||||
import path = require ("path");
|
||||
|
||||
export module CordovaTools {
|
||||
export module TacoUtils {
|
||||
export class TypescriptServices {
|
||||
private static FailureMessage = "Typescript compilation failed.";
|
||||
|
||||
|
@ -46,7 +46,8 @@ export module CordovaTools {
|
|||
/* push the typescript files */
|
||||
if (path.extname(currentPath) === ".ts" &&
|
||||
!currentPath.match("d.ts$") &&
|
||||
!currentPath.match("gulpfile.ts")) {
|
||||
!currentPath.match("gulpfile.ts") &&
|
||||
!currentPath.match("gulp-compile.ts")) {
|
||||
result.push(currentPath);
|
||||
}
|
||||
} else {
|
||||
|
@ -62,7 +63,7 @@ export module CordovaTools {
|
|||
/**
|
||||
* Compiles a diectory using the default settings, and the given source and destination location.
|
||||
*/
|
||||
public compileDirectory(sourceDirectory: string, outputDirectory: string, cb: Function): void {
|
||||
public compileDirectory(sourceDirectory: string, outputDirectory: string, cb: Function): void {
|
||||
var sourceFiles = this.getProjectTypescriptFiles(sourceDirectory, []);
|
||||
|
||||
this.compileTypescript({
|
Загрузка…
Ссылка в новой задаче