From 9bdcf7fadd107d41c7045e3e820744f550e313fd Mon Sep 17 00:00:00 2001 From: Matt Green Date: Sun, 17 Jan 2016 22:06:10 +0000 Subject: [PATCH] start --- .gitignore | 10 +- .vscode/tasks.json | 11 ++ app/app.js | 26 +++- app/app.ts | 30 ++++ app/main-page.js | 6 - app/main-view-model.js | 21 --- app/pages/startPage.ts | 43 ++++++ app/{main-page.xml => pages/startPage.xml} | 0 gruntfile.js | 137 ++++++++++++++++++ .../nativescript-dev-typescript.js | 1 + .../nativescript-dev-typescript.js | 1 + package.json | 13 +- references.d.ts | 1 + tsconfig.json | 13 ++ 14 files changed, 276 insertions(+), 37 deletions(-) create mode 100644 .vscode/tasks.json create mode 100644 app/app.ts delete mode 100644 app/main-page.js delete mode 100644 app/main-view-model.js create mode 100644 app/pages/startPage.ts rename app/{main-page.xml => pages/startPage.xml} (100%) create mode 100644 gruntfile.js create mode 100644 hooks/before-prepare/nativescript-dev-typescript.js create mode 100644 hooks/before-watch/nativescript-dev-typescript.js create mode 100644 references.d.ts create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index 4796eb8..05a223b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,12 +8,6 @@ pids *.pid *.seed -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt @@ -26,9 +20,13 @@ build/Release # Dependency directory # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git node_modules +app/**/*.js +app/**/*.map +platforms # Optional npm cache directory .npm # Optional REPL history .node_repl_history +*.tgz \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..7e7f57a --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,11 @@ +{ + "version": "0.1.0", + "command": "tsc", + "isShellCommand": true, + // Show the output window only if unrecognized errors occur. + "showOutput": "silent", + "args": [], + // use the standard tsc problem matcher to find compile problems + // in the output. + "problemMatcher": "$tsc" +} \ No newline at end of file diff --git a/app/app.js b/app/app.js index c44f10b..d49909a 100644 --- a/app/app.js +++ b/app/app.js @@ -1,4 +1,26 @@ var application = require("application"); -application.mainModule = "main-page"; -application.cssFile = "./app.css"; +if (application.android) { + application.onLaunch = function (intent) { + console.log("onLaunch"); + application.android.onActivityStarted = function (activity) { + console.log("onStarted"); + var window = activity.getWindow(); + if (window) { + window.setBackgroundDrawable(null); + } + }; + }; +} +if (application.ios) { + application.on("launch", function (args) { + // TODO: It would be nice if this was ios-specific property on the action bar and static property on application.ios. + //UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.UIStatusBarStyleLightContent; + setTimeout(function () { + //UIApplication.sharedApplication().keyWindow.backgroundColor = UIColor.blackColor(); + }, 1); + }); +} +application.mainModule = "pages/startPage"; +// application.mainModule = "profile-main"; application.start(); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiYXBwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLElBQU8sV0FBVyxXQUFXLGFBQWEsQ0FBQyxDQUFDO0FBRTVDLEVBQUUsQ0FBQSxDQUFDLFdBQVcsQ0FBQyxPQUFPLENBQUMsQ0FBQyxDQUFDO0lBQ3JCLFdBQVcsQ0FBQyxRQUFRLEdBQUcsVUFBVSxNQUFNO1FBQ25DLE9BQU8sQ0FBQyxHQUFHLENBQUMsVUFBVSxDQUFDLENBQUM7UUFFeEIsV0FBVyxDQUFDLE9BQU8sQ0FBQyxpQkFBaUIsR0FBRyxVQUFVLFFBQVE7WUFDdEQsT0FBTyxDQUFDLEdBQUcsQ0FBQyxXQUFXLENBQUMsQ0FBQztZQUN6QixJQUFJLE1BQU0sR0FBRyxRQUFRLENBQUMsU0FBUyxFQUFFLENBQUM7WUFDbEMsRUFBRSxDQUFDLENBQUMsTUFBTSxDQUFDLENBQUMsQ0FBQztnQkFDVCxNQUFNLENBQUMscUJBQXFCLENBQUMsSUFBSSxDQUFDLENBQUM7WUFDdkMsQ0FBQztRQUNMLENBQUMsQ0FBQTtJQUNMLENBQUMsQ0FBQTtBQUNMLENBQUM7QUFFRCxFQUFFLENBQUMsQ0FBQyxXQUFXLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQztJQUNsQixXQUFXLENBQUMsRUFBRSxDQUFDLFFBQVEsRUFBRSxVQUFBLElBQUk7UUFDekIscUhBQXFIO1FBQ3JILG1HQUFtRztRQUNuRyxVQUFVLENBQUM7WUFDUixxRkFBcUY7UUFDeEYsQ0FBQyxFQUFFLENBQUMsQ0FBQyxDQUFDO0lBQ1YsQ0FBQyxDQUFDLENBQUM7QUFDUCxDQUFDO0FBRUQsV0FBVyxDQUFDLFVBQVUsR0FBRyxpQkFBaUIsQ0FBQztBQUMzQywyQ0FBMkM7QUFDM0MsV0FBVyxDQUFDLEtBQUssRUFBRSxDQUFDIn0= \ No newline at end of file diff --git a/app/app.ts b/app/app.ts new file mode 100644 index 0000000..cce2bfb --- /dev/null +++ b/app/app.ts @@ -0,0 +1,30 @@ +import frame = require("ui/frame"); +import application = require("application"); + +if(application.android) { + application.onLaunch = function (intent) { + console.log("onLaunch"); + + application.android.onActivityStarted = function (activity) { + console.log("onStarted"); + var window = activity.getWindow(); + if (window) { + window.setBackgroundDrawable(null); + } + } + } +} + +if (application.ios) { + application.on("launch", args => { + // TODO: It would be nice if this was ios-specific property on the action bar and static property on application.ios. + //UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.UIStatusBarStyleLightContent; + setTimeout(() => { + //UIApplication.sharedApplication().keyWindow.backgroundColor = UIColor.blackColor(); + }, 1); + }); +} + +application.mainModule = "pages/startPage"; +// application.mainModule = "profile-main"; +application.start(); \ No newline at end of file diff --git a/app/main-page.js b/app/main-page.js deleted file mode 100644 index 00ed288..0000000 --- a/app/main-page.js +++ /dev/null @@ -1,6 +0,0 @@ -var vmModule = require("./main-view-model"); -function pageLoaded(args) { - var page = args.object; - page.bindingContext = vmModule.mainViewModel; -} -exports.pageLoaded = pageLoaded; diff --git a/app/main-view-model.js b/app/main-view-model.js deleted file mode 100644 index a4b6734..0000000 --- a/app/main-view-model.js +++ /dev/null @@ -1,21 +0,0 @@ -var observable = require("data/observable"); -var HelloWorldModel = (function (_super) { - __extends(HelloWorldModel, _super); - function HelloWorldModel() { - _super.call(this); - this.counter = 42; - this.set("message", this.counter + " taps left"); - } - HelloWorldModel.prototype.tapAction = function () { - this.counter--; - if (this.counter <= 0) { - this.set("message", "Hoorraaay! You unlocked the NativeScript clicker achievement!"); - } - else { - this.set("message", this.counter + " taps left"); - } - }; - return HelloWorldModel; -})(observable.Observable); -exports.HelloWorldModel = HelloWorldModel; -exports.mainViewModel = new HelloWorldModel(); diff --git a/app/pages/startPage.ts b/app/pages/startPage.ts new file mode 100644 index 0000000..724985c --- /dev/null +++ b/app/pages/startPage.ts @@ -0,0 +1,43 @@ +import {Observable} from "data/observable" +// var observable = require("data/observable"); +// var HelloWorldModel = (function (_super) { +// __extends(HelloWorldModel, _super); +// function HelloWorldModel() { +// _super.call(this); +// this.counter = 42; +// this.set("message", this.counter + " taps left"); +// } +// HelloWorldModel.prototype.tapAction = function () { +// this.counter--; +// if (this.counter <= 0) { +// this.set("message", "Hoorraaay! You unlocked the NativeScript clicker achievement!"); +// } +// else { +// this.set("message", this.counter + " taps left"); +// } +// }; +// return HelloWorldModel; +// })(observable.Observable); +// exports.HelloWorldModel = HelloWorldModel; +// exports.mainViewModel = new HelloWorldModel(); + +export class MainPageViewModel extends Observable +{ + constructor() + { + super(); + } + + public tapAction() + { + this.set + } +} + +//var vmModule = require("./main-view-model"); +function pageLoaded(args) { + var page = args.object; + var vm = new MainPageViewModel(); + page.bindingContext =vm; +} +exports.pageLoaded = pageLoaded; diff --git a/app/main-page.xml b/app/pages/startPage.xml similarity index 100% rename from app/main-page.xml rename to app/pages/startPage.xml diff --git a/gruntfile.js b/gruntfile.js new file mode 100644 index 0000000..12847f6 --- /dev/null +++ b/gruntfile.js @@ -0,0 +1,137 @@ +var path = require("path"); +var fs = require("fs"); + +module.exports = function (grunt) { + grunt.loadNpmTasks('grunt-ts'); + grunt.loadNpmTasks('grunt-contrib-copy'); + grunt.loadNpmTasks('grunt-contrib-clean'); + grunt.loadNpmTasks('grunt-shell'); + + var nsDistPath = process.env.NSDIST || './deps/NativeScript/bin/dist'; + + var androidAvd = grunt.option('avd') || "nexus" + var genyDevice = grunt.option('geny') || "nexus7" + var iOSDevice = grunt.option('device') || "iPhone-6" + var androidPlatfrom = "platforms/android/"; + + var hasAndroidPlatform = false; + try { + hasAndroidPlatform = fs.statSync(androidPlatfrom) && fs.statSync(androidPlatfrom).isDirectory(); + } + catch (e) { + // ... + } + + grunt.initConfig({ + ts: { + build: { + tsconfig: './app/tsconfig.json', + options: { + fast: "never", + compiler: "node_modules/typescript/bin/tsc" + }, + }, + }, + copy: { + widgets: { + src: "widgets.jar", + dest: path.join(androidPlatfrom, "libs") + "/", + cwd: "deps/android-widgets", + expand: true + }, + localInstallModules: { + src: "<%= nsPackagePath %>", + dest: "deps/tns-core-modules.tgz" + } + }, + clean: { + app: { + cwd: 'app', + expand: true, + src: [ + '**/*.js', + '**/*.map', + ] + }, + nodeModulesGz: { + // HACK: Work around a {N} CLI bug that prevents you from using + // NPM packages containing *.gz files. + // https://github.com/NativeScript/nativescript-cli/issues/393 + expand: true, + cwd: './node_modules', + src: [ + '**/*.gz', + ] + }, + }, + shell: { + depNSInit: { + command: [ + 'npm install', + 'grunt --no-runtslint', + ].join('&&'), + options: { + execOptions: { + cwd: 'deps/NativeScript', + } + } + }, + localInstallModules: { + command: "npm install 'deps/tns-core-modules.tgz'" + }, + emulateGeny: { + command: "tns emulate android --geny '" + genyDevice + "'" + }, + emulateAndroid: { + command: "tns emulate android --avd '" + androidAvd + "'" + }, + emulateIOS: { + command: "tns emulate ios --device '" + iOSDevice + "'" + }, + removeAndroid: { + command: "tns platform remove android" + }, + addAndroid: { + command: "tns platform add android" + } + } + }); + + grunt.registerTask("updateModules", [ + "getNSPackage", + "copy:localInstallModules", + "shell:localInstallModules", + ]); + + grunt.registerTask("getNSPackage", function () { + var packageFiles = grunt.file.expand({ + cwd: nsDistPath + }, [ + 'tns-core-modules*.tgz' + ]); + var nsPackagePath = path.join(nsDistPath, packageFiles[0]); + grunt.config('nsPackagePath', nsPackagePath); + }); + + grunt.registerTask("app", [ + "ts:build", + ]); + + // Copy custom version of widgets.jar to be up to date + grunt.registerTask("fix-android-widgets", hasAndroidPlatform ? ["copy:widgets"] : []) + grunt.registerTask("prepare", [ + "shell:depNSInit", + "updateModules", + "clean:nodeModulesGz", + "fix-android-widgets" + ]); + + grunt.registerTask("app-full", [ + "clean:app", + "app", + ]); + + grunt.registerTask("refresh-android", ["shell:removeAndroid", "shell:addAndroid", "fix-android-widgets"]) + grunt.registerTask("run-android", ["app", "shell:emulateAndroid"]) + grunt.registerTask("run-ios", ["app", "shell:emulateIOS"]) +} \ No newline at end of file diff --git a/hooks/before-prepare/nativescript-dev-typescript.js b/hooks/before-prepare/nativescript-dev-typescript.js new file mode 100644 index 0000000..7116ebd --- /dev/null +++ b/hooks/before-prepare/nativescript-dev-typescript.js @@ -0,0 +1 @@ +module.exports = require("nativescript-dev-typescript/lib/before-prepare.js"); diff --git a/hooks/before-watch/nativescript-dev-typescript.js b/hooks/before-watch/nativescript-dev-typescript.js new file mode 100644 index 0000000..9a6ef66 --- /dev/null +++ b/hooks/before-watch/nativescript-dev-typescript.js @@ -0,0 +1 @@ +module.exports = require("nativescript-dev-typescript/lib/watch.js"); diff --git a/package.json b/package.json index f18f263..424696c 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,16 @@ }, "dependencies": { "tns-core-modules": "1.5.1", - "nativescript-angular": "~0.0.20", - "nativescript-dev-typescript": "~0.2.3" + "nativescript-angular": "~0.0.20" + }, + "devDependencies": { + "typescript": "^1.7.5", + "grunt": "0.4.5", + "grunt-contrib-clean": "0.6.0", + "grunt-contrib-copy": "0.8.0", + "grunt-shell": "1.1.2", + "grunt-ts": "5.0.0-beta.5", + "nativescript-dev-typescript": "~0.2.3", + "shelljs": "^0.5.3" } } \ No newline at end of file diff --git a/references.d.ts b/references.d.ts new file mode 100644 index 0000000..b14f383 --- /dev/null +++ b/references.d.ts @@ -0,0 +1 @@ +/// Needed for autocompletion and compilation. \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..d26f385 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "inlineSourceMap": true, + "experimentalDecorators": true, + "noEmitHelpers": true + }, + "exclude": [ + "node_modules", + "platforms" + ] +} \ No newline at end of file