Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

fix(update-ns-webpack): skip the update of tsconfig.tns.json in shared Angular projects #1010

Merged
merged 1 commit into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions projectFilesManager.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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 })) {
Expand All @@ -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,
Expand Down
25 changes: 23 additions & 2 deletions projectHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 = {};
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -104,11 +123,13 @@ module.exports = {
isAndroid,
isIos,
isAngular,
isShared,
getAngularVersion,
isVue,
isTypeScript,
writePackageJson,
convertSlashesInPath,
getIndentationCharacter,
safeGet,
};
};