forked from EddyVerbruggen/nativescript-dev-webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojectHelpers.js
More file actions
36 lines (28 loc) · 1.09 KB
/
projectHelpers.js
File metadata and controls
36 lines (28 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const path = require("path");
const fs = require("fs");
const isTypeScript = ({projectDir, packageJson} = {}) => {
packageJson = packageJson || getPackageJson(projectDir);
return packageJson.dependencies.hasOwnProperty("typescript") ||
packageJson.devDependencies.hasOwnProperty("typescript") ||
isAngular({packageJson});
};
const isAngular = ({projectDir, packageJson} = {}) => {
packageJson = packageJson || getPackageJson(projectDir);
return Object.keys(packageJson.dependencies)
.some(dependency => /^@angular\b/.test(dependency));
};
const getPackageJson = projectDir => {
const packageJsonPath = getPackageJsonPath(projectDir);
return JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
};
const writePackageJson = (content, projectDir) => {
const packageJsonPath = getPackageJsonPath(projectDir);
fs.writeFileSync(packageJsonPath, JSON.stringify(content, null, 2))
}
const getPackageJsonPath = projectDir => path.resolve(projectDir, "package.json");
module.exports = {
isTypeScript,
isAngular,
getPackageJson,
writePackageJson,
};