diff --git a/projectFilesManager.js b/projectFilesManager.js index c2ccd8e1..d033d492 100644 --- a/projectFilesManager.js +++ b/projectFilesManager.js @@ -1,7 +1,7 @@ const path = require("path"); const fs = require("fs"); -const { isTypeScript, isAngular, isVue } = require("./projectHelpers"); +const { isTypeScript, isAngular, isVue, isShared } = require("./projectHelpers"); function addProjectFiles(projectDir) { const projectTemplates = getProjectTemplates(projectDir); @@ -62,7 +62,11 @@ function getProjectTemplates(projectDir) { let templates; if (isAngular({ projectDir })) { - templates = getAngularTemplates(WEBPACK_CONFIG_NAME, TSCONFIG_TNS_NAME); + if (isShared({ projectDir })) { + templates = getSharedAngularTemplates(WEBPACK_CONFIG_NAME); + } else { + templates = getAngularTemplates(WEBPACK_CONFIG_NAME, TSCONFIG_TNS_NAME); + } } else if (isVue({ projectDir })) { templates = getVueTemplates(WEBPACK_CONFIG_NAME); } else if (isTypeScript({ projectDir })) { @@ -74,6 +78,12 @@ function getProjectTemplates(projectDir) { return getFullTemplatesPath(projectDir, templates); } +function getSharedAngularTemplates(webpackConfigName) { + return { + "webpack.angular.js": webpackConfigName, + }; +} + function getAngularTemplates(webpackConfigName, tsconfigName) { return { "webpack.angular.js": webpackConfigName, diff --git a/projectHelpers.js b/projectHelpers.js index 792dd8fa..ca3a24b6 100644 --- a/projectHelpers.js +++ b/projectHelpers.js @@ -17,6 +17,11 @@ const isTypeScript = ({ projectDir, packageJson } = {}) => { ) || isAngular({ packageJson }); }; +const isShared = ({ projectDir }) => { + const nsConfig = getNsConfig(projectDir); + return nsConfig && !!nsConfig.shared; +} + const isAngular = ({ projectDir, packageJson } = {}) => { packageJson = packageJson || getPackageJson(projectDir); @@ -39,9 +44,22 @@ const isVue = ({ projectDir, packageJson } = {}) => { const getPackageJson = projectDir => { const packageJsonPath = getPackageJsonPath(projectDir); + const result = readJsonFile(packageJsonPath); + + return result; +}; + +const getNsConfig = projectDir => { + const nsConfigPath = getNsConfigPath(projectDir); + const result = readJsonFile(nsConfigPath); + + return result; +}; + +const readJsonFile = filePath => { let result; try { - result = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")); + result = JSON.parse(fs.readFileSync(filePath, "utf8")); } catch (e) { result = {}; } @@ -69,6 +87,7 @@ const getIndentationCharacter = (jsonContent) => { const getProjectDir = hook.findProjectDir; const getPackageJsonPath = projectDir => resolve(projectDir, "package.json"); +const getNsConfigPath = projectDir => resolve(projectDir, "nsconfig.json"); const isAndroid = platform => /android/i.test(platform); const isIos = platform => /ios/i.test(platform); @@ -104,6 +123,7 @@ module.exports = { isAndroid, isIos, isAngular, + isShared, getAngularVersion, isVue, isTypeScript, @@ -111,4 +131,5 @@ module.exports = { convertSlashesInPath, getIndentationCharacter, safeGet, -}; \ No newline at end of file +}; +