From ae1cceb5a25a4806fdea5c26cc3ae49d17014acb Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Wed, 20 Jun 2018 14:54:49 +0300 Subject: [PATCH 01/20] fix: resolve appComponents absolute paths on Windows Fix https://github.com/NativeScript/nativescript-dev-webpack/issues/573. --- android-app-components-loader.js | 7 +++++-- projectHelpers.js | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/android-app-components-loader.js b/android-app-components-loader.js index 5e2ecfd3..71d5dd38 100644 --- a/android-app-components-loader.js +++ b/android-app-components-loader.js @@ -1,7 +1,10 @@ -module.exports = function(source) { +const { convertSlashesInPath } = require("./projectHelpers"); + +module.exports = function (source) { this.cacheable(); const { modules } = this.query; - const imports = modules.map(m => `require("${m}");`).join("\n"); + const imports = modules.map(m => convertSlashesInPath(m)) + .map(m => `require("${m}");`).join("\n"); const augmentedSource = ` if (!global["__snapshot"]) { ${imports} diff --git a/projectHelpers.js b/projectHelpers.js index 1e9464f5..bc66ac04 100644 --- a/projectHelpers.js +++ b/projectHelpers.js @@ -66,6 +66,16 @@ function safeGet(object, property, ...args) { value; } +// Convert paths from C:\some\path to C:/some/path in order to be required +function convertSlashesInPath(modulePath) { + if (isWindows) { + modulePath = modulePath.replace(/\\/g, "/"); + } + return modulePath; +} + +const isWindows = process.platform.startsWith("win32"); + module.exports = { getAppPathFromProjectData, getAppResourcesPathFromProjectData, @@ -76,4 +86,5 @@ module.exports = { isAngular, isTypeScript, writePackageJson, + convertSlashesInPath }; From 6e77f4bf91815082cb5cbc26f4486cab1262a706 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Thu, 21 Jun 2018 19:45:11 +0300 Subject: [PATCH 02/20] fix: resolve xml namespaces absolute paths on Windows --- xml-namespace-loader.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/xml-namespace-loader.js b/xml-namespace-loader.js index a0c0d664..aea57f56 100644 --- a/xml-namespace-loader.js +++ b/xml-namespace-loader.js @@ -1,6 +1,7 @@ const { parse, relative, join, basename, extname } = require("path"); +const { convertSlashesInPath } = require("./projectHelpers"); -module.exports = function(source) { +module.exports = function (source) { this.value = source; const { XmlParser } = require("tns-core-modules/xml"); @@ -47,7 +48,7 @@ module.exports = function(source) { namespaces.push({ name: namespace, path: resolvedPath }); namespaces.push({ name: moduleName, path: resolvedPath }); - const { dir, name } = parse(resolvedPath); + const { dir, name } = parse(resolvedPath); const noExtFilename = join(dir, name); const xml = tryResolve(`${noExtFilename}.xml`); @@ -67,6 +68,11 @@ module.exports = function(source) { parser.parse(source); const moduleRegisters = namespaces + .map(function (n) { + let obj = n; + obj.path = convertSlashesInPath(n.path); + return obj; + }) .map(n => `global.registerModule("${n.name}", function() { return require("${n.path}"); });` ) @@ -86,9 +92,8 @@ module.exports = function(source) { function tryResolve(path) { try { return require.resolve(path); - } catch(e) { + } catch (e) { // The path couldn't be resolved return; } } - From 35112fc7fe146e9427284278de50b10630b4eb74 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Fri, 22 Jun 2018 14:59:42 +0300 Subject: [PATCH 03/20] chore(JavaScriptApp): add webpack.config.js file Clean up npm scripts. --- demo/.gitignore | 2 - demo/JavaScriptApp/package.json | 7 - demo/JavaScriptApp/webpack.config.js | 229 +++++++++++++++++++++++++++ 3 files changed, 229 insertions(+), 9 deletions(-) create mode 100644 demo/JavaScriptApp/webpack.config.js diff --git a/demo/.gitignore b/demo/.gitignore index 829954a9..099474f8 100644 --- a/demo/.gitignore +++ b/demo/.gitignore @@ -15,5 +15,3 @@ tsconfig.aot.json vendor.js vendor.ts - -webpack.config.js diff --git a/demo/JavaScriptApp/package.json b/demo/JavaScriptApp/package.json index a492ee07..32543aa0 100644 --- a/demo/JavaScriptApp/package.json +++ b/demo/JavaScriptApp/package.json @@ -33,13 +33,6 @@ "node-sass": "^4.7.1" }, "scripts": { - "ns-bundle": "ns-bundle", - "start-android-bundle": "npm run ns-bundle --android --run-app", - "start-ios-bundle": "npm run ns-bundle --ios --run-app", - "build-android-bundle": "npm run ns-bundle --android --build-app", - "build-ios-bundle": "npm run ns-bundle --ios --build-app", - "publish-ios-bundle": "npm run ns-bundle --ios --publish-app", - "generate-android-snapshot": "generate-android-snapshot --targetArchs arm,arm64,ia32 --install", "e2e": "mocha --opts ../config/mocha.opts --recursive e2e --appiumCapsLocation ../config/appium.capabilities.json" } } diff --git a/demo/JavaScriptApp/webpack.config.js b/demo/JavaScriptApp/webpack.config.js new file mode 100644 index 00000000..1700a92f --- /dev/null +++ b/demo/JavaScriptApp/webpack.config.js @@ -0,0 +1,229 @@ +const { join, relative, resolve, sep } = require("path"); + +const webpack = require("webpack"); +const nsWebpack = require("nativescript-dev-webpack"); +const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); +const CleanWebpackPlugin = require("clean-webpack-plugin"); +const CopyWebpackPlugin = require("copy-webpack-plugin"); +const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); +const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin"); +const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); + +module.exports = env => { + // Add your custom Activities, Services and other android app components here. + const appComponents = [ + "tns-core-modules/ui/frame", + "tns-core-modules/ui/frame/activity", + ]; + + const platform = env && (env.android && "android" || env.ios && "ios"); + if (!platform) { + throw new Error("You need to provide a target platform!"); + } + + const platforms = ["ios", "android"]; + const projectRoot = __dirname; + + // Default destination inside platforms//... + const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); + const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; + + const { + // The 'appPath' and 'appResourcesPath' values are fetched from + // the nsconfig.json configuration file + // when bundling with `tns run android|ios --bundle`. + appPath = "app", + appResourcesPath = "app/App_Resources", + + // You can provide the following flags when running 'tns run android|ios' + snapshot, // --env.snapshot + uglify, // --env.uglify + report, // --env.report + } = env; + + const appFullPath = resolve(projectRoot, appPath); + const appResourcesFullPath = resolve(projectRoot, appResourcesPath); + + const entryModule = nsWebpack.getEntryModule(appFullPath); + const entryPath = `.${sep}${entryModule}.js`; + + const config = { + mode: uglify ? "production" : "development", + context: appFullPath, + watchOptions: { + ignored: [ + appResourcesFullPath, + // Don't watch hidden files + "**/.*", + ] + }, + target: nativescriptTarget, + entry: { + bundle: entryPath, + }, + output: { + pathinfo: false, + path: dist, + libraryTarget: "commonjs2", + filename: "[name].js", + globalObject: "global", + }, + resolve: { + extensions: [".js", ".scss", ".css"], + // Resolve {N} system modules from tns-core-modules + modules: [ + "node_modules/tns-core-modules", + "node_modules", + ], + alias: { + '~': appFullPath + }, + // don't resolve symlinks to symlinked modules + symlinks: false + }, + resolveLoader: { + // don't resolve symlinks to symlinked loaders + symlinks: false + }, + node: { + // Disable node shims that conflict with NativeScript + "http": false, + "timers": false, + "setImmediate": false, + "fs": "empty", + "__dirname": false, + }, + devtool: "none", + optimization: { + splitChunks: { + cacheGroups: { + vendor: { + name: "vendor", + chunks: "all", + test: (module, chunks) => { + const moduleName = module.nameForCondition ? module.nameForCondition() : ''; + return /[\\/]node_modules[\\/]/.test(moduleName) || + appComponents.some(comp => comp === moduleName); + + }, + enforce: true, + }, + } + }, + minimize: !!uglify, + minimizer: [ + new UglifyJsPlugin({ + uglifyOptions: { + parallel: true, + cache: true, + output: { + comments: false, + }, + compress: { + // The Android SBG has problems parsing the output + // when these options are enabled + 'collapse_vars': platform !== "android", + sequences: platform !== "android", + } + } + }) + ], + }, + module: { + rules: [ + { + test: new RegExp(entryPath), + use: [ + // Require all Android app components + platform === "android" && { + loader: "nativescript-dev-webpack/android-app-components-loader", + options: { modules: appComponents } + }, + + { + loader: "nativescript-dev-webpack/bundle-config-loader", + options: { + loadCss: !snapshot, // load the application css if in debug mode + } + }, + ].filter(loader => !!loader) + }, + + { test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader"}, + + { + test: /\.css$/, + use: { loader: "css-loader", options: { minimize: false, url: false } } + }, + + { + test: /\.scss$/, + use: [ + { loader: "css-loader", options: { minimize: false, url: false } }, + "sass-loader" + ] + } + ] + }, + plugins: [ + // Define useful constants like TNS_WEBPACK + new webpack.DefinePlugin({ + "global.TNS_WEBPACK": "true", + }), + // Remove all files from the out dir. + new CleanWebpackPlugin([ `${dist}/**/*` ]), + // Copy native app resources to out dir. + new CopyWebpackPlugin([ + { + from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, + to: `${dist}/App_Resources/${appResourcesPlatformDir}`, + context: projectRoot + }, + ]), + // Copy assets to out dir. Add your own globs as needed. + new CopyWebpackPlugin([ + { from: "fonts/**" }, + { from: "**/*.jpg" }, + { from: "**/*.png" }, + ], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }), + // Generate a bundle starter script and activate it in package.json + new nsWebpack.GenerateBundleStarterPlugin([ + "./vendor", + "./bundle", + ]), + // For instructions on how to set up workers with webpack + // check out https://github.com/nativescript/worker-loader + new NativeScriptWorkerPlugin(), + new nsWebpack.PlatformFSPlugin({ + platform, + platforms, + }), + // Does IPC communication with the {N} CLI to notify events when running in watch mode. + new nsWebpack.WatchStateLoggerPlugin(), + ], + }; + + if (report) { + // Generate report files for bundles content + config.plugins.push(new BundleAnalyzerPlugin({ + analyzerMode: "static", + openAnalyzer: false, + generateStatsFile: true, + reportFilename: resolve(projectRoot, "report", `report.html`), + statsFilename: resolve(projectRoot, "report", `stats.json`), + })); + } + + if (snapshot) { + config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({ + chunk: "vendor", + requireModules: [ + "tns-core-modules/bundle-entry-points", + ], + projectRoot, + webpackConfig: config, + })); + } + + return config; +}; From b22ba3b9306fdc377410ca932427e287de94ea2b Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Fri, 22 Jun 2018 15:27:34 +0300 Subject: [PATCH 04/20] test(JavaScriptApp): extend android application --- .../App_Resources/Android/AndroidManifest.xml | 2 +- demo/JavaScriptApp/app/application.android.js | 16 ++++++++++++++++ demo/JavaScriptApp/webpack.config.js | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 demo/JavaScriptApp/app/application.android.js diff --git a/demo/JavaScriptApp/app/App_Resources/Android/AndroidManifest.xml b/demo/JavaScriptApp/app/App_Resources/Android/AndroidManifest.xml index 9db83215..f74e4154 100644 --- a/demo/JavaScriptApp/app/App_Resources/Android/AndroidManifest.xml +++ b/demo/JavaScriptApp/app/App_Resources/Android/AndroidManifest.xml @@ -19,7 +19,7 @@ { target: nativescriptTarget, entry: { bundle: entryPath, + application: "./application.android", }, output: { pathinfo: false, From 1677aac0db11626fee7942cf53d6cfabf6155353 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Fri, 22 Jun 2018 15:39:50 +0300 Subject: [PATCH 05/20] test(JavaScriptApp): extend android activity --- .../App_Resources/Android/AndroidManifest.xml | 2 +- demo/JavaScriptApp/app/activity.android.js | 35 +++++++++++++++++++ demo/JavaScriptApp/webpack.config.js | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 demo/JavaScriptApp/app/activity.android.js diff --git a/demo/JavaScriptApp/app/App_Resources/Android/AndroidManifest.xml b/demo/JavaScriptApp/app/App_Resources/Android/AndroidManifest.xml index f74e4154..0bb603e9 100644 --- a/demo/JavaScriptApp/app/App_Resources/Android/AndroidManifest.xml +++ b/demo/JavaScriptApp/app/App_Resources/Android/AndroidManifest.xml @@ -26,7 +26,7 @@ android:theme="@style/AppTheme"> diff --git a/demo/JavaScriptApp/app/activity.android.js b/demo/JavaScriptApp/app/activity.android.js new file mode 100644 index 00000000..82f10905 --- /dev/null +++ b/demo/JavaScriptApp/app/activity.android.js @@ -0,0 +1,35 @@ +let frame = require("ui/frame"); + +let superProto = android.app.Activity.prototype; +let Activity = android.app.Activity.extend("org.myApp.MainActivity", { + onCreate: function(savedInstanceState) { + if(!this._callbacks) { + frame.setActivityCallbacks(this); + } + // Modules will take care of calling super.onCreate, do not call it here + this._callbacks.onCreate(this, savedInstanceState, superProto.onCreate); + + // Add custom initialization logic here + }, + onSaveInstanceState: function(outState) { + this._callbacks.onSaveInstanceState(this, outState, superProto.onSaveInstanceState); + }, + onStart: function() { + this._callbacks.onStart(this, superProto.onStart); + }, + onStop: function() { + this._callbacks.onStop(this, superProto.onStop); + }, + onDestroy: function() { + this._callbacks.onDestroy(this, superProto.onDestroy); + }, + onBackPressed: function() { + this._callbacks.onBackPressed(this, superProto.onBackPressed); + }, + onRequestPermissionsResult: function (requestCode, permissions, grantResults) { + this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined); + }, + onActivityResult: function (requestCode, resultCode, data) { + this._callbacks.onActivityResult(this, requestCode, resultCode, data, _super.prototype.onActivityResult); + } +}); diff --git a/demo/JavaScriptApp/webpack.config.js b/demo/JavaScriptApp/webpack.config.js index 4e3f4d41..64ea43c1 100644 --- a/demo/JavaScriptApp/webpack.config.js +++ b/demo/JavaScriptApp/webpack.config.js @@ -14,6 +14,7 @@ module.exports = env => { const appComponents = [ "tns-core-modules/ui/frame", "tns-core-modules/ui/frame/activity", + resolve(__dirname, "app/activity.android.js"), ]; const platform = env && (env.android && "android" || env.ios && "ios"); From b42f16a41e352549d577258d20b4a2ee8a10b3f0 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Fri, 22 Jun 2018 15:45:02 +0300 Subject: [PATCH 06/20] chore(TypeScriptApp): add webpack.config.js file Clean up npm scripts. --- demo/.gitignore | 2 + demo/TypeScriptApp/package.json | 7 - demo/TypeScriptApp/webpack.config.js | 239 +++++++++++++++++++++++++++ 3 files changed, 241 insertions(+), 7 deletions(-) create mode 100644 demo/TypeScriptApp/webpack.config.js diff --git a/demo/.gitignore b/demo/.gitignore index 099474f8..dcdcde1a 100644 --- a/demo/.gitignore +++ b/demo/.gitignore @@ -15,3 +15,5 @@ tsconfig.aot.json vendor.js vendor.ts + +tsconfig.esm.json \ No newline at end of file diff --git a/demo/TypeScriptApp/package.json b/demo/TypeScriptApp/package.json index 3cef17fa..c4ecf688 100644 --- a/demo/TypeScriptApp/package.json +++ b/demo/TypeScriptApp/package.json @@ -34,13 +34,6 @@ "typescript": "~2.7.2" }, "scripts": { - "ns-bundle": "ns-bundle", - "start-android-bundle": "npm run ns-bundle --android --run-app", - "start-ios-bundle": "npm run ns-bundle --ios --run-app", - "build-android-bundle": "npm run ns-bundle --android --build-app", - "build-ios-bundle": "npm run ns-bundle --ios --build-app", - "publish-ios-bundle": "npm run ns-bundle --ios --publish-app", - "generate-android-snapshot": "generate-android-snapshot --targetArchs arm,arm64,ia32 --install", "e2e": "tsc -p e2e && mocha --opts ../config/mocha.opts --recursive e2e --appiumCapsLocation ../config/appium.capabilities.json", "compile-tests": "tsc -p e2e --watch" } diff --git a/demo/TypeScriptApp/webpack.config.js b/demo/TypeScriptApp/webpack.config.js new file mode 100644 index 00000000..7394c84d --- /dev/null +++ b/demo/TypeScriptApp/webpack.config.js @@ -0,0 +1,239 @@ +const { join, relative, resolve, sep } = require("path"); + +const webpack = require("webpack"); +const nsWebpack = require("nativescript-dev-webpack"); +const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); +const CleanWebpackPlugin = require("clean-webpack-plugin"); +const CopyWebpackPlugin = require("copy-webpack-plugin"); +const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); +const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin"); +const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); + +module.exports = env => { + // Add your custom Activities, Services and other Android app components here. + const appComponents = [ + "tns-core-modules/ui/frame", + "tns-core-modules/ui/frame/activity", + ]; + + const platform = env && (env.android && "android" || env.ios && "ios"); + if (!platform) { + throw new Error("You need to provide a target platform!"); + } + + const platforms = ["ios", "android"]; + const projectRoot = __dirname; + + // Default destination inside platforms//... + const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); + const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; + + const { + // The 'appPath' and 'appResourcesPath' values are fetched from + // the nsconfig.json configuration file + // when bundling with `tns run android|ios --bundle`. + appPath = "app", + appResourcesPath = "app/App_Resources", + + // You can provide the following flags when running 'tns run android|ios' + snapshot, // --env.snapshot + uglify, // --env.uglify + report, // --env.report + } = env; + + const appFullPath = resolve(projectRoot, appPath); + const appResourcesFullPath = resolve(projectRoot, appResourcesPath); + + const entryModule = nsWebpack.getEntryModule(appFullPath); + const entryPath = `.${sep}${entryModule}.ts`; + + const config = { + mode: uglify ? "production" : "development", + context: appFullPath, + watchOptions: { + ignored: [ + appResourcesFullPath, + // Don't watch hidden files + "**/.*", + ] + }, + target: nativescriptTarget, + entry: { + bundle: entryPath, + }, + output: { + pathinfo: false, + path: dist, + libraryTarget: "commonjs2", + filename: "[name].js", + globalObject: "global", + }, + resolve: { + extensions: [".ts", ".js", ".scss", ".css"], + // Resolve {N} system modules from tns-core-modules + modules: [ + resolve(__dirname, "node_modules/tns-core-modules"), + resolve(__dirname, "node_modules"), + "node_modules/tns-core-modules", + "node_modules", + ], + alias: { + '~': appFullPath + }, + // don't resolve symlinks to symlinked modules + symlinks: false + }, + resolveLoader: { + // don't resolve symlinks to symlinked loaders + symlinks: false + }, + node: { + // Disable node shims that conflict with NativeScript + "http": false, + "timers": false, + "setImmediate": false, + "fs": "empty", + "__dirname": false, + }, + devtool: "none", + optimization: { + splitChunks: { + cacheGroups: { + vendor: { + name: "vendor", + chunks: "all", + test: (module, chunks) => { + const moduleName = module.nameForCondition ? module.nameForCondition() : ''; + return /[\\/]node_modules[\\/]/.test(moduleName) || + appComponents.some(comp => comp === moduleName); + + }, + enforce: true, + }, + } + }, + minimize: !!uglify, + minimizer: [ + new UglifyJsPlugin({ + uglifyOptions: { + parallel: true, + cache: true, + output: { + comments: false, + }, + compress: { + // The Android SBG has problems parsing the output + // when these options are enabled + 'collapse_vars': platform !== "android", + sequences: platform !== "android", + } + } + }) + ], + }, + module: { + rules: [ + { + test: new RegExp(entryPath), + use: [ + // Require all Android app components + platform === "android" && { + loader: "nativescript-dev-webpack/android-app-components-loader", + options: { modules: appComponents } + }, + + { + loader: "nativescript-dev-webpack/bundle-config-loader", + options: { + loadCss: !snapshot, // load the application css if in debug mode + } + }, + ].filter(loader => !!loader) + }, + + { test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader"}, + + { + test: /\.css$/, + use: { loader: "css-loader", options: { minimize: false, url: false } } + }, + + { + test: /\.scss$/, + use: [ + { loader: "css-loader", options: { minimize: false, url: false } }, + "sass-loader" + ] + }, + + { + test: /\.ts$/, + use: { + loader: "awesome-typescript-loader", + options: { configFileName: "tsconfig.esm.json" }, + } + }, + ] + }, + plugins: [ + // Define useful constants like TNS_WEBPACK + new webpack.DefinePlugin({ + "global.TNS_WEBPACK": "true", + }), + // Remove all files from the out dir. + new CleanWebpackPlugin([ `${dist}/**/*` ]), + // Copy native app resources to out dir. + new CopyWebpackPlugin([ + { + from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, + to: `${dist}/App_Resources/${appResourcesPlatformDir}`, + context: projectRoot + }, + ]), + // Copy assets to out dir. Add your own globs as needed. + new CopyWebpackPlugin([ + { from: "fonts/**" }, + { from: "**/*.jpg" }, + { from: "**/*.png" }, + ], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }), + // Generate a bundle starter script and activate it in package.json + new nsWebpack.GenerateBundleStarterPlugin([ + "./vendor", + "./bundle", + ]), + // For instructions on how to set up workers with webpack + // check out https://github.com/nativescript/worker-loader + new NativeScriptWorkerPlugin(), + new nsWebpack.PlatformFSPlugin({ + platform, + platforms, + }), + // Does IPC communication with the {N} CLI to notify events when running in watch mode. + new nsWebpack.WatchStateLoggerPlugin(), + ], + }; + + if (report) { + // Generate report files for bundles content + config.plugins.push(new BundleAnalyzerPlugin({ + analyzerMode: "static", + openAnalyzer: false, + generateStatsFile: true, + reportFilename: resolve(projectRoot, "report", `report.html`), + statsFilename: resolve(projectRoot, "report", `stats.json`), + })); + } + + if (snapshot) { + config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({ + chunk: "vendor", + requireModules: [ + "tns-core-modules/bundle-entry-points", + ], + projectRoot, + webpackConfig: config, + })); + } + + return config; +}; From 0ed2c5ac4f5c25fd2716d27345f59a2c7e4885dd Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Fri, 22 Jun 2018 16:30:41 +0300 Subject: [PATCH 07/20] chore(TypeScriptApp): add platform declarations --- demo/TypeScriptApp/package.json | 1 + demo/TypeScriptApp/references.d.ts | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 demo/TypeScriptApp/references.d.ts diff --git a/demo/TypeScriptApp/package.json b/demo/TypeScriptApp/package.json index c4ecf688..c5863a49 100644 --- a/demo/TypeScriptApp/package.json +++ b/demo/TypeScriptApp/package.json @@ -31,6 +31,7 @@ "nativescript-dev-sass": "^1.3.5", "nativescript-dev-typescript": "next", "nativescript-dev-webpack": "file:../..", + "tns-platform-declarations": "next", "typescript": "~2.7.2" }, "scripts": { diff --git a/demo/TypeScriptApp/references.d.ts b/demo/TypeScriptApp/references.d.ts new file mode 100644 index 00000000..992a504a --- /dev/null +++ b/demo/TypeScriptApp/references.d.ts @@ -0,0 +1,2 @@ +/// +/// \ No newline at end of file From e9a1ea70220514fa2434d0d9e47d2eda36ade1ae Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Fri, 22 Jun 2018 16:32:18 +0300 Subject: [PATCH 08/20] test(TypeScriptApp): extend android application --- .../App_Resources/Android/AndroidManifest.xml | 2 +- demo/TypeScriptApp/app/application.android.ts | 18 ++++++++++++++++++ demo/TypeScriptApp/webpack.config.js | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 demo/TypeScriptApp/app/application.android.ts diff --git a/demo/TypeScriptApp/app/App_Resources/Android/AndroidManifest.xml b/demo/TypeScriptApp/app/App_Resources/Android/AndroidManifest.xml index 9db83215..f74e4154 100644 --- a/demo/TypeScriptApp/app/App_Resources/Android/AndroidManifest.xml +++ b/demo/TypeScriptApp/app/App_Resources/Android/AndroidManifest.xml @@ -19,7 +19,7 @@ { target: nativescriptTarget, entry: { bundle: entryPath, + application: "./application.android", }, output: { pathinfo: false, From cdde4918e3db4fa5e67495ca2fc1714ded8c202f Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Fri, 22 Jun 2018 16:39:35 +0300 Subject: [PATCH 09/20] test(TypeScriptApp): extend android activity --- .../App_Resources/Android/AndroidManifest.xml | 2 +- demo/TypeScriptApp/app/activity.android.ts | 42 +++++++++++++++++++ demo/TypeScriptApp/webpack.config.js | 1 + 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 demo/TypeScriptApp/app/activity.android.ts diff --git a/demo/TypeScriptApp/app/App_Resources/Android/AndroidManifest.xml b/demo/TypeScriptApp/app/App_Resources/Android/AndroidManifest.xml index f74e4154..0bb603e9 100644 --- a/demo/TypeScriptApp/app/App_Resources/Android/AndroidManifest.xml +++ b/demo/TypeScriptApp/app/App_Resources/Android/AndroidManifest.xml @@ -26,7 +26,7 @@ android:theme="@style/AppTheme"> diff --git a/demo/TypeScriptApp/app/activity.android.ts b/demo/TypeScriptApp/app/activity.android.ts new file mode 100644 index 00000000..5e9e72e9 --- /dev/null +++ b/demo/TypeScriptApp/app/activity.android.ts @@ -0,0 +1,42 @@ +import {setActivityCallbacks, AndroidActivityCallbacks} from "ui/frame"; + +@JavaProxy("org.myApp.MainActivity") +class Activity extends android.app.Activity { + private _callbacks: AndroidActivityCallbacks; + + protected onCreate(savedInstanceState: android.os.Bundle): void { + if (!this._callbacks) { + setActivityCallbacks(this); + } + + this._callbacks.onCreate(this, savedInstanceState, super.onCreate); + } + + protected onSaveInstanceState(outState: android.os.Bundle): void { + this._callbacks.onSaveInstanceState(this, outState, super.onSaveInstanceState); + } + + protected onStart(): void { + this._callbacks.onStart(this, super.onStart); + } + + protected onStop(): void { + this._callbacks.onStop(this, super.onStop); + } + + protected onDestroy(): void { + this._callbacks.onDestroy(this, super.onDestroy); + } + + public onBackPressed(): void { + this._callbacks.onBackPressed(this, super.onBackPressed); + } + + public onRequestPermissionsResult(requestCode: number, permissions: Array, grantResults: Array): void { + this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined /*TODO: Enable if needed*/); + } + + protected onActivityResult(requestCode: number, resultCode: number, data: android.content.Intent): void { + this._callbacks.onActivityResult(this, requestCode, resultCode, data, super.onActivityResult); + } +} diff --git a/demo/TypeScriptApp/webpack.config.js b/demo/TypeScriptApp/webpack.config.js index 01403e1a..3c2bd1e1 100644 --- a/demo/TypeScriptApp/webpack.config.js +++ b/demo/TypeScriptApp/webpack.config.js @@ -14,6 +14,7 @@ module.exports = env => { const appComponents = [ "tns-core-modules/ui/frame", "tns-core-modules/ui/frame/activity", + resolve(__dirname, "app/activity.android.ts"), ]; const platform = env && (env.android && "android" || env.ios && "ios"); From 24ff369471c3cd25ad7c24a1a6d4646d50466285 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Fri, 22 Jun 2018 16:43:45 +0300 Subject: [PATCH 10/20] chore(AngularApp): add webpack.config.js file Clean up npm scripts. --- demo/AngularApp/package.json | 7 - demo/AngularApp/webpack.config.js | 268 ++++++++++++++++++++++++++++++ 2 files changed, 268 insertions(+), 7 deletions(-) create mode 100644 demo/AngularApp/webpack.config.js diff --git a/demo/AngularApp/package.json b/demo/AngularApp/package.json index 27f97bbe..f28256fd 100644 --- a/demo/AngularApp/package.json +++ b/demo/AngularApp/package.json @@ -50,13 +50,6 @@ "typescript": "~2.7.2" }, "scripts": { - "ns-bundle": "ns-bundle", - "start-android-bundle": "npm run ns-bundle --android --run-app", - "start-ios-bundle": "npm run ns-bundle --ios --run-app", - "build-android-bundle": "npm run ns-bundle --android --build-app", - "build-ios-bundle": "npm run ns-bundle --ios --build-app", - "publish-ios-bundle": "npm run ns-bundle --ios --publish-app", - "generate-android-snapshot": "generate-android-snapshot --targetArchs arm,arm64,ia32 --install", "e2e": "tsc -p e2e && mocha --opts ../config/mocha.opts --recursive e2e --appiumCapsLocation ../config/appium.capabilities.json", "compile-tests": "tsc -p e2e --watch" } diff --git a/demo/AngularApp/webpack.config.js b/demo/AngularApp/webpack.config.js new file mode 100644 index 00000000..97c3beb2 --- /dev/null +++ b/demo/AngularApp/webpack.config.js @@ -0,0 +1,268 @@ +const { join, relative, resolve, sep } = require("path"); + +const webpack = require("webpack"); +const nsWebpack = require("nativescript-dev-webpack"); +const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); +const { PlatformReplacementHost } = require("nativescript-dev-webpack/host/platform"); +const CleanWebpackPlugin = require("clean-webpack-plugin"); +const CopyWebpackPlugin = require("copy-webpack-plugin"); +const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); +const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin"); +const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); +const { AngularCompilerPlugin } = require("@ngtools/webpack"); + +module.exports = env => { + // Add your custom Activities, Services and other Android app components here. + const appComponents = [ + "tns-core-modules/ui/frame", + "tns-core-modules/ui/frame/activity", + ]; + + const platform = env && (env.android && "android" || env.ios && "ios"); + if (!platform) { + throw new Error("You need to provide a target platform!"); + } + + const extensions = ["tns", platform]; + const platformHost = new PlatformReplacementHost(extensions); + + const projectRoot = __dirname; + + // Default destination inside platforms//... + const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); + const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; + + const { + // The 'appPath' and 'appResourcesPath' values are fetched from + // the nsconfig.json configuration file + // when bundling with `tns run android|ios --bundle`. + appPath = "app", + appResourcesPath = "app/App_Resources", + + // You can provide the following flags when running 'tns run android|ios' + aot, // --env.aot + snapshot, // --env.snapshot + uglify, // --env.uglify + report, // --env.report + } = env; + + const appFullPath = resolve(projectRoot, appPath); + const appResourcesFullPath = resolve(projectRoot, appResourcesPath); + + const entryModule = aot ? + nsWebpack.getAotEntryModule(appFullPath) : + `${nsWebpack.getEntryModule(appFullPath)}.ts`; + const entryPath = `.${sep}${entryModule}`; + + const config = { + mode: uglify ? "production" : "development", + context: appFullPath, + watchOptions: { + ignored: [ + appResourcesFullPath, + // Don't watch hidden files + "**/.*", + ] + }, + target: nativescriptTarget, + entry: { + bundle: entryPath, + }, + output: { + pathinfo: false, + path: dist, + libraryTarget: "commonjs2", + filename: "[name].js", + globalObject: "global", + }, + resolve: { + extensions: [".ts", ".js", ".scss", ".css"], + // Resolve {N} system modules from tns-core-modules + modules: [ + resolve(__dirname, "node_modules/tns-core-modules"), + resolve(__dirname, "node_modules"), + "node_modules/tns-core-modules", + "node_modules", + ], + alias: { + '~': appFullPath + }, + symlinks: true + }, + resolveLoader: { + symlinks: false + }, + node: { + // Disable node shims that conflict with NativeScript + "http": false, + "timers": false, + "setImmediate": false, + "fs": "empty", + "__dirname": false, + }, + devtool: "none", + optimization: { + splitChunks: { + cacheGroups: { + vendor: { + name: "vendor", + chunks: "all", + test: (module, chunks) => { + const moduleName = module.nameForCondition ? module.nameForCondition() : ''; + return /[\\/]node_modules[\\/]/.test(moduleName) || + appComponents.some(comp => comp === moduleName); + }, + enforce: true, + }, + } + }, + minimize: !!uglify, + minimizer: [ + new UglifyJsPlugin({ + uglifyOptions: { + parallel: true, + cache: true, + output: { + comments: false, + }, + compress: { + // The Android SBG has problems parsing the output + // when these options are enabled + 'collapse_vars': platform !== "android", + sequences: platform !== "android", + } + } + }) + ], + }, + module: { + rules: [ + { + test: new RegExp(entryPath), + use: [ + // Require all Android app components + platform === "android" && { + loader: "nativescript-dev-webpack/android-app-components-loader", + options: { modules: appComponents } + }, + + { + loader: "nativescript-dev-webpack/bundle-config-loader", + options: { + angular: true, + loadCss: !snapshot, // load the application css if in debug mode + } + }, + ].filter(loader => !!loader) + }, + + { test: /\.html$|\.xml$/, use: "raw-loader" }, + + // tns-core-modules reads the app.css and its imports using css-loader + { + test: /[\/|\\]app\.css$/, + use: { + loader: "css-loader", + options: { minimize: false, url: false }, + } + }, + { + test: /[\/|\\]app\.scss$/, + use: [ + { loader: "css-loader", options: { minimize: false, url: false } }, + "sass-loader" + ] + }, + + // Angular components reference css files and their imports using raw-loader + { test: /\.css$/, exclude: /[\/|\\]app\.css$/, use: "raw-loader" }, + { test: /\.scss$/, exclude: /[\/|\\]app\.scss$/, use: ["raw-loader", "resolve-url-loader", "sass-loader"] }, + + // Compile TypeScript files with ahead-of-time compiler. + { + test: /.ts$/, use: [ + "nativescript-dev-webpack/moduleid-compat-loader", + "@ngtools/webpack", + ] + }, + + // Mark files inside `@angular/core` as using SystemJS style dynamic imports. + // Removing this will cause deprecation warnings to appear. + { + test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/, + parser: { system: true }, + }, + ], + }, + plugins: [ + // Define useful constants like TNS_WEBPACK + new webpack.DefinePlugin({ + "global.TNS_WEBPACK": "true", + }), + // Remove all files from the out dir. + new CleanWebpackPlugin([ `${dist}/**/*` ]), + // Copy native app resources to out dir. + new CopyWebpackPlugin([ + { + from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, + to: `${dist}/App_Resources/${appResourcesPlatformDir}`, + context: projectRoot + }, + ]), + // Copy assets to out dir. Add your own globs as needed. + new CopyWebpackPlugin([ + { from: "fonts/**" }, + { from: "**/*.jpg" }, + { from: "**/*.png" }, + ], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }), + // Generate a bundle starter script and activate it in package.json + new nsWebpack.GenerateBundleStarterPlugin([ + "./vendor", + "./bundle", + ]), + // For instructions on how to set up workers with webpack + // check out https://github.com/nativescript/worker-loader + new NativeScriptWorkerPlugin(), + + new AngularCompilerPlugin({ + host: platformHost, + entryModule: resolve(appPath, "app.module#AppModule"), + tsConfigPath: join(__dirname, "tsconfig.esm.json"), + skipCodeGeneration: !aot, + }), + // Does IPC communication with the {N} CLI to notify events when running in watch mode. + new nsWebpack.WatchStateLoggerPlugin(), + ], + }; + + if (report) { + // Generate report files for bundles content + config.plugins.push(new BundleAnalyzerPlugin({ + analyzerMode: "static", + openAnalyzer: false, + generateStatsFile: true, + reportFilename: resolve(projectRoot, "report", `report.html`), + statsFilename: resolve(projectRoot, "report", `stats.json`), + })); + } + + if (snapshot) { + config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({ + chunk: "vendor", + angular: true, + requireModules: [ + "reflect-metadata", + "@angular/platform-browser", + "@angular/core", + "@angular/common", + "@angular/router", + "nativescript-angular/platform-static", + "nativescript-angular/router", + ], + projectRoot, + webpackConfig: config, + })); + } + + return config; +}; From 8c196ffca49303cac16229eb87c9211de9575ff3 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Fri, 22 Jun 2018 16:46:02 +0300 Subject: [PATCH 11/20] chore(AngularApp): add platform declarations --- demo/AngularApp/package.json | 1 + demo/AngularApp/references.d.ts | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 demo/AngularApp/references.d.ts diff --git a/demo/AngularApp/package.json b/demo/AngularApp/package.json index f28256fd..5f502d07 100644 --- a/demo/AngularApp/package.json +++ b/demo/AngularApp/package.json @@ -47,6 +47,7 @@ "nativescript-dev-sass": "^1.3.5", "nativescript-dev-typescript": "next", "nativescript-dev-webpack": "file:../..", + "tns-platform-declarations": "next", "typescript": "~2.7.2" }, "scripts": { diff --git a/demo/AngularApp/references.d.ts b/demo/AngularApp/references.d.ts new file mode 100644 index 00000000..992a504a --- /dev/null +++ b/demo/AngularApp/references.d.ts @@ -0,0 +1,2 @@ +/// +/// \ No newline at end of file From b271bbb4fddcfc7825769b39c9ad277525919d53 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Fri, 22 Jun 2018 16:48:07 +0300 Subject: [PATCH 12/20] test(AngularApp): extend android application --- .../App_Resources/Android/AndroidManifest.xml | 2 +- demo/AngularApp/app/application.android.ts | 18 ++++++++++++++++++ demo/AngularApp/webpack.config.js | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 demo/AngularApp/app/application.android.ts diff --git a/demo/AngularApp/app/App_Resources/Android/AndroidManifest.xml b/demo/AngularApp/app/App_Resources/Android/AndroidManifest.xml index 9db83215..f74e4154 100644 --- a/demo/AngularApp/app/App_Resources/Android/AndroidManifest.xml +++ b/demo/AngularApp/app/App_Resources/Android/AndroidManifest.xml @@ -19,7 +19,7 @@ { target: nativescriptTarget, entry: { bundle: entryPath, + application: "./application.android", }, output: { pathinfo: false, From ac6295c1eb3285abd056109f3deac2f86e968362 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Fri, 22 Jun 2018 16:56:10 +0300 Subject: [PATCH 13/20] test(AngularApp): extend android activity --- .../App_Resources/Android/AndroidManifest.xml | 2 +- demo/AngularApp/app/activity.android.ts | 42 +++++++++++++++++++ demo/AngularApp/webpack.config.js | 1 + 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 demo/AngularApp/app/activity.android.ts diff --git a/demo/AngularApp/app/App_Resources/Android/AndroidManifest.xml b/demo/AngularApp/app/App_Resources/Android/AndroidManifest.xml index f74e4154..0bb603e9 100644 --- a/demo/AngularApp/app/App_Resources/Android/AndroidManifest.xml +++ b/demo/AngularApp/app/App_Resources/Android/AndroidManifest.xml @@ -26,7 +26,7 @@ android:theme="@style/AppTheme"> diff --git a/demo/AngularApp/app/activity.android.ts b/demo/AngularApp/app/activity.android.ts new file mode 100644 index 00000000..5e9e72e9 --- /dev/null +++ b/demo/AngularApp/app/activity.android.ts @@ -0,0 +1,42 @@ +import {setActivityCallbacks, AndroidActivityCallbacks} from "ui/frame"; + +@JavaProxy("org.myApp.MainActivity") +class Activity extends android.app.Activity { + private _callbacks: AndroidActivityCallbacks; + + protected onCreate(savedInstanceState: android.os.Bundle): void { + if (!this._callbacks) { + setActivityCallbacks(this); + } + + this._callbacks.onCreate(this, savedInstanceState, super.onCreate); + } + + protected onSaveInstanceState(outState: android.os.Bundle): void { + this._callbacks.onSaveInstanceState(this, outState, super.onSaveInstanceState); + } + + protected onStart(): void { + this._callbacks.onStart(this, super.onStart); + } + + protected onStop(): void { + this._callbacks.onStop(this, super.onStop); + } + + protected onDestroy(): void { + this._callbacks.onDestroy(this, super.onDestroy); + } + + public onBackPressed(): void { + this._callbacks.onBackPressed(this, super.onBackPressed); + } + + public onRequestPermissionsResult(requestCode: number, permissions: Array, grantResults: Array): void { + this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined /*TODO: Enable if needed*/); + } + + protected onActivityResult(requestCode: number, resultCode: number, data: android.content.Intent): void { + this._callbacks.onActivityResult(this, requestCode, resultCode, data, super.onActivityResult); + } +} diff --git a/demo/AngularApp/webpack.config.js b/demo/AngularApp/webpack.config.js index 9b003aa8..04731f1a 100644 --- a/demo/AngularApp/webpack.config.js +++ b/demo/AngularApp/webpack.config.js @@ -16,6 +16,7 @@ module.exports = env => { const appComponents = [ "tns-core-modules/ui/frame", "tns-core-modules/ui/frame/activity", + resolve(__dirname, "app/activity.android.ts"), ]; const platform = env && (env.android && "android" || env.ios && "ios"); From b31b5f07d6904b6ec3c27b2e7eaa3fe8390a24dd Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Fri, 22 Jun 2018 17:31:45 +0300 Subject: [PATCH 14/20] chore(AngularApp): update @angular/compiler-cli version --- demo/AngularApp/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/AngularApp/package.json b/demo/AngularApp/package.json index 5f502d07..e96abc0e 100644 --- a/demo/AngularApp/package.json +++ b/demo/AngularApp/package.json @@ -30,7 +30,7 @@ }, "devDependencies": { "@angular-devkit/build-angular": "~0.7.0-beta.1", - "@angular/compiler-cli": "~6.0.0", + "@angular/compiler-cli": "~6.1.0-beta.1", "@types/chai": "^4.0.2", "@types/mocha": "^2.2.41", "@types/node": "^7.0.5", From dc38afc52d37e7a08d5e50b30b6397099c36b030 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Fri, 22 Jun 2018 17:47:12 +0300 Subject: [PATCH 15/20] refactor(demos): minor tweaks --- demo/AngularApp/app/application.android.ts | 8 -------- demo/JavaScriptApp/app/activity.android.js | 9 +++------ demo/JavaScriptApp/app/application.android.js | 11 ++--------- demo/TypeScriptApp/app/app.android.css | 1 + demo/TypeScriptApp/app/app.ios.css | 1 + demo/TypeScriptApp/app/application.android.ts | 8 -------- 6 files changed, 7 insertions(+), 31 deletions(-) create mode 100644 demo/TypeScriptApp/app/app.android.css create mode 100644 demo/TypeScriptApp/app/app.ios.css diff --git a/demo/AngularApp/app/application.android.ts b/demo/AngularApp/app/application.android.ts index 7d7c0ee6..d706f1a6 100644 --- a/demo/AngularApp/app/application.android.ts +++ b/demo/AngularApp/app/application.android.ts @@ -1,18 +1,10 @@ -// the `JavaProxy` decorator specifies the package and the name for the native *.JAVA file generated. @JavaProxy("org.myApp.Application") class Application extends android.app.Application { onCreate(): void { super.onCreate(); - - // At this point modules have already been initialized - - // Enter custom initialization code here } protected attachBaseContext(baseContext: android.content.Context) { super.attachBaseContext(baseContext); - - // This code enables MultiDex support for the application (if needed) - // android.support.multidex.MultiDex.install(this); } } diff --git a/demo/JavaScriptApp/app/activity.android.js b/demo/JavaScriptApp/app/activity.android.js index 82f10905..45858ccd 100644 --- a/demo/JavaScriptApp/app/activity.android.js +++ b/demo/JavaScriptApp/app/activity.android.js @@ -1,15 +1,12 @@ -let frame = require("ui/frame"); +const frame = require("ui/frame"); -let superProto = android.app.Activity.prototype; -let Activity = android.app.Activity.extend("org.myApp.MainActivity", { +const superProto = android.app.Activity.prototype; +const Activity = android.app.Activity.extend("org.myApp.MainActivity", { onCreate: function(savedInstanceState) { if(!this._callbacks) { frame.setActivityCallbacks(this); } - // Modules will take care of calling super.onCreate, do not call it here this._callbacks.onCreate(this, savedInstanceState, superProto.onCreate); - - // Add custom initialization logic here }, onSaveInstanceState: function(outState) { this._callbacks.onSaveInstanceState(this, outState, superProto.onSaveInstanceState); diff --git a/demo/JavaScriptApp/app/application.android.js b/demo/JavaScriptApp/app/application.android.js index 9ce3a255..1397009f 100644 --- a/demo/JavaScriptApp/app/application.android.js +++ b/demo/JavaScriptApp/app/application.android.js @@ -1,16 +1,9 @@ -var superProto = android.app.Application.prototype; -// the first parameter of the `extend` call defines the package and the name for the native *.JAVA file generated. -var Application = android.app.Application.extend("org.myApp.Application", { +const superProto = android.app.Application.prototype; +const Application = android.app.Application.extend("org.myApp.Application", { onCreate: function() { superProto.onCreate.call(this); - - // At this point modules have already been initialized - - // Enter custom initialization code here }, attachBaseContext: function(base) { superProto.attachBaseContext.call(this, base); - // This code enables MultiDex support for the application (if needed) - // android.support.multidex.MultiDex.install(this); } }); diff --git a/demo/TypeScriptApp/app/app.android.css b/demo/TypeScriptApp/app/app.android.css new file mode 100644 index 00000000..c55b85fe --- /dev/null +++ b/demo/TypeScriptApp/app/app.android.css @@ -0,0 +1 @@ +@import url(/Users/vchimev/Work/git/nativescript-dev-webpack/demo/TypeScriptApp/node_modules/nativescript-theme-core/css/core.light.css);ActionBar{background-color:#7F9}.app-class{background-color:#7F9} diff --git a/demo/TypeScriptApp/app/app.ios.css b/demo/TypeScriptApp/app/app.ios.css new file mode 100644 index 00000000..2a1f4e39 --- /dev/null +++ b/demo/TypeScriptApp/app/app.ios.css @@ -0,0 +1 @@ +@import url(/Users/vchimev/Work/git/nativescript-dev-webpack/demo/TypeScriptApp/node_modules/nativescript-theme-core/css/core.light.css);ActionBar{background-color:#999}.app-class{background-color:#999} diff --git a/demo/TypeScriptApp/app/application.android.ts b/demo/TypeScriptApp/app/application.android.ts index 7d7c0ee6..d706f1a6 100644 --- a/demo/TypeScriptApp/app/application.android.ts +++ b/demo/TypeScriptApp/app/application.android.ts @@ -1,18 +1,10 @@ -// the `JavaProxy` decorator specifies the package and the name for the native *.JAVA file generated. @JavaProxy("org.myApp.Application") class Application extends android.app.Application { onCreate(): void { super.onCreate(); - - // At this point modules have already been initialized - - // Enter custom initialization code here } protected attachBaseContext(baseContext: android.content.Context) { super.attachBaseContext(baseContext); - - // This code enables MultiDex support for the application (if needed) - // android.support.multidex.MultiDex.install(this); } } From f8aa3a9150ca26cf4fabe88d393cbf85a546f7f4 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Fri, 22 Jun 2018 18:30:13 +0300 Subject: [PATCH 16/20] chore(JavaScript): remove unused variables --- demo/JavaScriptApp/app/activity.android.js | 2 +- demo/JavaScriptApp/app/application.android.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/JavaScriptApp/app/activity.android.js b/demo/JavaScriptApp/app/activity.android.js index 45858ccd..c5013fd5 100644 --- a/demo/JavaScriptApp/app/activity.android.js +++ b/demo/JavaScriptApp/app/activity.android.js @@ -1,7 +1,7 @@ const frame = require("ui/frame"); const superProto = android.app.Activity.prototype; -const Activity = android.app.Activity.extend("org.myApp.MainActivity", { +android.app.Activity.extend("org.myApp.MainActivity", { onCreate: function(savedInstanceState) { if(!this._callbacks) { frame.setActivityCallbacks(this); diff --git a/demo/JavaScriptApp/app/application.android.js b/demo/JavaScriptApp/app/application.android.js index 1397009f..858b33b6 100644 --- a/demo/JavaScriptApp/app/application.android.js +++ b/demo/JavaScriptApp/app/application.android.js @@ -1,5 +1,5 @@ const superProto = android.app.Application.prototype; -const Application = android.app.Application.extend("org.myApp.Application", { +android.app.Application.extend("org.myApp.Application", { onCreate: function() { superProto.onCreate.call(this); }, From 6a8fdad84326f8ab69c12a744ed0e6b3ea31825c Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Fri, 22 Jun 2018 19:18:24 +0300 Subject: [PATCH 17/20] refactor: address comments --- android-app-components-loader.js | 2 +- xml-namespace-loader.js | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/android-app-components-loader.js b/android-app-components-loader.js index 71d5dd38..9321e401 100644 --- a/android-app-components-loader.js +++ b/android-app-components-loader.js @@ -3,7 +3,7 @@ const { convertSlashesInPath } = require("./projectHelpers"); module.exports = function (source) { this.cacheable(); const { modules } = this.query; - const imports = modules.map(m => convertSlashesInPath(m)) + const imports = modules.map(convertSlashesInPath) .map(m => `require("${m}");`).join("\n"); const augmentedSource = ` if (!global["__snapshot"]) { diff --git a/xml-namespace-loader.js b/xml-namespace-loader.js index aea57f56..f640b30d 100644 --- a/xml-namespace-loader.js +++ b/xml-namespace-loader.js @@ -68,11 +68,7 @@ module.exports = function (source) { parser.parse(source); const moduleRegisters = namespaces - .map(function (n) { - let obj = n; - obj.path = convertSlashesInPath(n.path); - return obj; - }) + .map(convertPath) .map(n => `global.registerModule("${n.name}", function() { return require("${n.path}"); });` ) @@ -89,6 +85,11 @@ module.exports = function (source) { this.callback(null, wrapped); } +function convertPath(obj) { + obj.path = convertSlashesInPath(obj.path); + return obj; +} + function tryResolve(path) { try { return require.resolve(path); From 25de3d4d1dc5862a72cfb5d4f27bfb25d91d85ab Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Sat, 23 Jun 2018 17:50:11 +0300 Subject: [PATCH 18/20] chore(e2e): update application activity to launch --- demo/config/appium.capabilities.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/demo/config/appium.capabilities.json b/demo/config/appium.capabilities.json index 16749592..8160e8cf 100644 --- a/demo/config/appium.capabilities.json +++ b/demo/config/appium.capabilities.json @@ -5,7 +5,7 @@ "deviceName": "Emulator-Api19-Default", "avd": "Emulator-Api19-Default", "lt": 60000, - "appActivity": "com.tns.NativeScriptActivity", + "appActivity": "org.myApp.MainActivity", "newCommandTimeout": 720, "noReset": true, "fullReset": false, @@ -17,7 +17,7 @@ "deviceName": "Emulator-Api21-Default", "avd": "Emulator-Api21-Default", "lt": 60000, - "appActivity": "com.tns.NativeScriptActivity", + "appActivity": "org.myApp.MainActivity", "newCommandTimeout": 720, "noReset": true, "fullReset": false, @@ -29,7 +29,7 @@ "deviceName": "Emulator-Api23-Default", "avd": "Emulator-Api23-Default", "lt": 60000, - "appActivity": "com.tns.NativeScriptActivity", + "appActivity": "org.myApp.MainActivity", "newCommandTimeout": 720, "noReset": true, "fullReset": false, @@ -41,7 +41,7 @@ "deviceName": "Emulator-Api24-Default", "avd": "Emulator-Api24-Default", "lt": 60000, - "appActivity": "com.tns.NativeScriptActivity", + "appActivity": "org.myApp.MainActivity", "newCommandTimeout": 720, "noReset": true, "fullReset": false, @@ -53,7 +53,7 @@ "deviceName": "Emulator-Api25-Google", "avd": "Emulator-Api25-Google", "lt": 60000, - "appActivity": "com.tns.NativeScriptActivity", + "appActivity": "org.myApp.MainActivity", "newCommandTimeout": 720, "noReset": true, "fullReset": false, @@ -65,7 +65,7 @@ "deviceName": "Emulator-Api26-Google", "avd": "Emulator-Api26-Google", "lt": 60000, - "appActivity": "com.tns.NativeScriptActivity", + "appActivity": "org.myApp.MainActivity", "newCommandTimeout": 720, "noReset": true, "fullReset": false, @@ -77,7 +77,7 @@ "deviceName": "Emulator-Api27-Google", "avd": "Emulator-Api27-Google", "lt": 60000, - "appActivity": "com.tns.NativeScriptActivity", + "appActivity": "org.myApp.MainActivity", "newCommandTimeout": 720, "noReset": true, "fullReset": false, From b8cd317d843606d84a45de560d74348629230d75 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Mon, 25 Jun 2018 13:58:08 +0300 Subject: [PATCH 19/20] refactor: remove tns-platform-declarations dependency --- demo/AngularApp/app/activity.android.ts | 6 +++--- demo/AngularApp/app/application.android.ts | 2 +- demo/AngularApp/app/application.d.ts | 1 + demo/AngularApp/package.json | 1 - demo/AngularApp/references.d.ts | 2 -- demo/TypeScriptApp/app/activity.android.ts | 6 +++--- demo/TypeScriptApp/app/application.android.ts | 2 +- demo/TypeScriptApp/app/application.d.ts | 1 + demo/TypeScriptApp/package.json | 1 - demo/TypeScriptApp/references.d.ts | 2 -- 10 files changed, 10 insertions(+), 14 deletions(-) create mode 100644 demo/AngularApp/app/application.d.ts delete mode 100644 demo/AngularApp/references.d.ts create mode 100644 demo/TypeScriptApp/app/application.d.ts delete mode 100644 demo/TypeScriptApp/references.d.ts diff --git a/demo/AngularApp/app/activity.android.ts b/demo/AngularApp/app/activity.android.ts index 5e9e72e9..f04e39bd 100644 --- a/demo/AngularApp/app/activity.android.ts +++ b/demo/AngularApp/app/activity.android.ts @@ -4,7 +4,7 @@ import {setActivityCallbacks, AndroidActivityCallbacks} from "ui/frame"; class Activity extends android.app.Activity { private _callbacks: AndroidActivityCallbacks; - protected onCreate(savedInstanceState: android.os.Bundle): void { + protected onCreate(savedInstanceState: any): void { // android.os.Bundle if (!this._callbacks) { setActivityCallbacks(this); } @@ -12,7 +12,7 @@ class Activity extends android.app.Activity { this._callbacks.onCreate(this, savedInstanceState, super.onCreate); } - protected onSaveInstanceState(outState: android.os.Bundle): void { + protected onSaveInstanceState(outState: any): void { // android.os.Bundle this._callbacks.onSaveInstanceState(this, outState, super.onSaveInstanceState); } @@ -36,7 +36,7 @@ class Activity extends android.app.Activity { this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined /*TODO: Enable if needed*/); } - protected onActivityResult(requestCode: number, resultCode: number, data: android.content.Intent): void { + protected onActivityResult(requestCode: number, resultCode: number, data: any): void { // android.content.Intent this._callbacks.onActivityResult(this, requestCode, resultCode, data, super.onActivityResult); } } diff --git a/demo/AngularApp/app/application.android.ts b/demo/AngularApp/app/application.android.ts index d706f1a6..4c23696f 100644 --- a/demo/AngularApp/app/application.android.ts +++ b/demo/AngularApp/app/application.android.ts @@ -4,7 +4,7 @@ class Application extends android.app.Application { super.onCreate(); } - protected attachBaseContext(baseContext: android.content.Context) { + protected attachBaseContext(baseContext: any) { // android.content.Context super.attachBaseContext(baseContext); } } diff --git a/demo/AngularApp/app/application.d.ts b/demo/AngularApp/app/application.d.ts new file mode 100644 index 00000000..3cb28cfd --- /dev/null +++ b/demo/AngularApp/app/application.d.ts @@ -0,0 +1 @@ +declare const android: any; diff --git a/demo/AngularApp/package.json b/demo/AngularApp/package.json index e96abc0e..79551755 100644 --- a/demo/AngularApp/package.json +++ b/demo/AngularApp/package.json @@ -47,7 +47,6 @@ "nativescript-dev-sass": "^1.3.5", "nativescript-dev-typescript": "next", "nativescript-dev-webpack": "file:../..", - "tns-platform-declarations": "next", "typescript": "~2.7.2" }, "scripts": { diff --git a/demo/AngularApp/references.d.ts b/demo/AngularApp/references.d.ts deleted file mode 100644 index 992a504a..00000000 --- a/demo/AngularApp/references.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -/// -/// \ No newline at end of file diff --git a/demo/TypeScriptApp/app/activity.android.ts b/demo/TypeScriptApp/app/activity.android.ts index 5e9e72e9..f04e39bd 100644 --- a/demo/TypeScriptApp/app/activity.android.ts +++ b/demo/TypeScriptApp/app/activity.android.ts @@ -4,7 +4,7 @@ import {setActivityCallbacks, AndroidActivityCallbacks} from "ui/frame"; class Activity extends android.app.Activity { private _callbacks: AndroidActivityCallbacks; - protected onCreate(savedInstanceState: android.os.Bundle): void { + protected onCreate(savedInstanceState: any): void { // android.os.Bundle if (!this._callbacks) { setActivityCallbacks(this); } @@ -12,7 +12,7 @@ class Activity extends android.app.Activity { this._callbacks.onCreate(this, savedInstanceState, super.onCreate); } - protected onSaveInstanceState(outState: android.os.Bundle): void { + protected onSaveInstanceState(outState: any): void { // android.os.Bundle this._callbacks.onSaveInstanceState(this, outState, super.onSaveInstanceState); } @@ -36,7 +36,7 @@ class Activity extends android.app.Activity { this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined /*TODO: Enable if needed*/); } - protected onActivityResult(requestCode: number, resultCode: number, data: android.content.Intent): void { + protected onActivityResult(requestCode: number, resultCode: number, data: any): void { // android.content.Intent this._callbacks.onActivityResult(this, requestCode, resultCode, data, super.onActivityResult); } } diff --git a/demo/TypeScriptApp/app/application.android.ts b/demo/TypeScriptApp/app/application.android.ts index d706f1a6..4c23696f 100644 --- a/demo/TypeScriptApp/app/application.android.ts +++ b/demo/TypeScriptApp/app/application.android.ts @@ -4,7 +4,7 @@ class Application extends android.app.Application { super.onCreate(); } - protected attachBaseContext(baseContext: android.content.Context) { + protected attachBaseContext(baseContext: any) { // android.content.Context super.attachBaseContext(baseContext); } } diff --git a/demo/TypeScriptApp/app/application.d.ts b/demo/TypeScriptApp/app/application.d.ts new file mode 100644 index 00000000..3cb28cfd --- /dev/null +++ b/demo/TypeScriptApp/app/application.d.ts @@ -0,0 +1 @@ +declare const android: any; diff --git a/demo/TypeScriptApp/package.json b/demo/TypeScriptApp/package.json index c5863a49..c4ecf688 100644 --- a/demo/TypeScriptApp/package.json +++ b/demo/TypeScriptApp/package.json @@ -31,7 +31,6 @@ "nativescript-dev-sass": "^1.3.5", "nativescript-dev-typescript": "next", "nativescript-dev-webpack": "file:../..", - "tns-platform-declarations": "next", "typescript": "~2.7.2" }, "scripts": { diff --git a/demo/TypeScriptApp/references.d.ts b/demo/TypeScriptApp/references.d.ts deleted file mode 100644 index 992a504a..00000000 --- a/demo/TypeScriptApp/references.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -/// -/// \ No newline at end of file From bbb97164895aecd1eb4fc51b2149b90a73cd9a45 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Mon, 25 Jun 2018 14:18:31 +0300 Subject: [PATCH 20/20] chore(e2e): remove application activity from capabilities The nativescript-dev-appium plugin gets it automatically, no need to declare it in the `appium.capabilities.json` file. --- demo/config/appium.capabilities.json | 7 ------- 1 file changed, 7 deletions(-) diff --git a/demo/config/appium.capabilities.json b/demo/config/appium.capabilities.json index 8160e8cf..4bdd8c65 100644 --- a/demo/config/appium.capabilities.json +++ b/demo/config/appium.capabilities.json @@ -5,7 +5,6 @@ "deviceName": "Emulator-Api19-Default", "avd": "Emulator-Api19-Default", "lt": 60000, - "appActivity": "org.myApp.MainActivity", "newCommandTimeout": 720, "noReset": true, "fullReset": false, @@ -17,7 +16,6 @@ "deviceName": "Emulator-Api21-Default", "avd": "Emulator-Api21-Default", "lt": 60000, - "appActivity": "org.myApp.MainActivity", "newCommandTimeout": 720, "noReset": true, "fullReset": false, @@ -29,7 +27,6 @@ "deviceName": "Emulator-Api23-Default", "avd": "Emulator-Api23-Default", "lt": 60000, - "appActivity": "org.myApp.MainActivity", "newCommandTimeout": 720, "noReset": true, "fullReset": false, @@ -41,7 +38,6 @@ "deviceName": "Emulator-Api24-Default", "avd": "Emulator-Api24-Default", "lt": 60000, - "appActivity": "org.myApp.MainActivity", "newCommandTimeout": 720, "noReset": true, "fullReset": false, @@ -53,7 +49,6 @@ "deviceName": "Emulator-Api25-Google", "avd": "Emulator-Api25-Google", "lt": 60000, - "appActivity": "org.myApp.MainActivity", "newCommandTimeout": 720, "noReset": true, "fullReset": false, @@ -65,7 +60,6 @@ "deviceName": "Emulator-Api26-Google", "avd": "Emulator-Api26-Google", "lt": 60000, - "appActivity": "org.myApp.MainActivity", "newCommandTimeout": 720, "noReset": true, "fullReset": false, @@ -77,7 +71,6 @@ "deviceName": "Emulator-Api27-Google", "avd": "Emulator-Api27-Google", "lt": 60000, - "appActivity": "org.myApp.MainActivity", "newCommandTimeout": 720, "noReset": true, "fullReset": false,