diff --git a/index.js b/index.js index 766d4af4..45232a77 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ const path = require("path"); -const { existsSync } = require("fs"); +const { existsSync, readFileSync } = require("fs"); const { ANDROID_APP_PATH } = require("./androidProjectHelpers"); const { getPackageJson, @@ -110,6 +110,22 @@ exports.getAppPath = (platform, projectDir) => { } }; +exports.getNSConfigPaths = (projectDir, defaultAppPath, defaultAppResourcePath) => { + let appPath = defaultAppPath || "app"; + let appResourcesPath = defaultAppResourcePath || "app/App_Resources"; + const nsConfigPath = path.join(projectDir, 'nsconfig.json'); + if (existsSync(nsConfigPath)) { + const nsConfig = readFileSync(nsConfigPath).toJSON(); + if (nsConfig.appPath) { + appPath = nsConfig.appPath; + } + if (nsConfig.appResourcesPath) { + appResourcesPath = nsConfig.appResourcesPath; + } + } + return { appPath, appResourcesPath }; +}; + /** * For backward compatibility. This method is deprecated. Do not use it anymore. * This method also has a bug of not escaping valid regex symbols in entry path. diff --git a/templates/webpack.angular.js b/templates/webpack.angular.js index f0b43bbe..cea07439 100644 --- a/templates/webpack.angular.js +++ b/templates/webpack.angular.js @@ -35,12 +35,14 @@ module.exports = env => { // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); + const { // The 'appPath' and 'appResourcesPath' values are fetched from - // the nsconfig.json configuration file. - appPath = "src", - appResourcesPath = "App_Resources", - + // the nsconfig.json configuration file + appPath, + appResourcesPath + } = nsWebpack.getNSConfigPaths(projectRoot, "src") + const { // You can provide the following flags when running 'tns run android|ios' aot, // --env.aot snapshot, // --env.snapshot, diff --git a/templates/webpack.config.spec.ts b/templates/webpack.config.spec.ts index 8d62b062..6f8d8773 100644 --- a/templates/webpack.config.spec.ts +++ b/templates/webpack.config.spec.ts @@ -28,6 +28,7 @@ const nativeScriptDevWebpack = { WatchStateLoggerPlugin: EmptyClass, PlatformFSPlugin: EmptyClass, getAppPath: () => 'app', + getNSConfigPaths: () => ({ appPath: 'app', appResourcesPath: 'app/App_Resources' }), getEntryModule: () => 'EntryModule', hasRootLevelScopedModules: () => false, hasRootLevelScopedAngular: () => false, diff --git a/templates/webpack.javascript.js b/templates/webpack.javascript.js index 59360c38..e8352af5 100644 --- a/templates/webpack.javascript.js +++ b/templates/webpack.javascript.js @@ -35,10 +35,11 @@ module.exports = env => { const { // The 'appPath' and 'appResourcesPath' values are fetched from - // the nsconfig.json configuration file. - appPath = "app", - appResourcesPath = "app/App_Resources", - + // the nsconfig.json configuration file + appPath, + appResourcesPath + } = nsWebpack.getNSConfigPaths(projectRoot) + const { // You can provide the following flags when running 'tns run android|ios' snapshot, // --env.snapshot production, // --env.production diff --git a/templates/webpack.typescript.js b/templates/webpack.typescript.js index 35c4fe65..c8d5e4ec 100644 --- a/templates/webpack.typescript.js +++ b/templates/webpack.typescript.js @@ -37,10 +37,11 @@ module.exports = env => { const { // The 'appPath' and 'appResourcesPath' values are fetched from - // the nsconfig.json configuration file. - appPath = "app", - appResourcesPath = "app/App_Resources", - + // the nsconfig.json configuration file + appPath, + appResourcesPath + } = nsWebpack.getNSConfigPaths(projectRoot) + const { // You can provide the following flags when running 'tns run android|ios' snapshot, // --env.snapshot production, // --env.production diff --git a/templates/webpack.vue.js b/templates/webpack.vue.js index 16339117..86155907 100644 --- a/templates/webpack.vue.js +++ b/templates/webpack.vue.js @@ -39,10 +39,11 @@ module.exports = env => { const { // The 'appPath' and 'appResourcesPath' values are fetched from - // the nsconfig.json configuration file. - appPath = "app", - appResourcesPath = "app/App_Resources", - + // the nsconfig.json configuration file + appPath, + appResourcesPath + } = nsWebpack.getNSConfigPaths(projectRoot) + const { // You can provide the following flags when running 'tns run android|ios' snapshot, // --env.snapshot production, // --env.production