-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
108 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as Fs from "fs"; | ||
import * as Path from "path"; | ||
import * as _ from "lodash"; | ||
|
||
/** | ||
* Add a list of packages to a package.json's depedencies | ||
* @param pkgJson - package.json data | ||
* @param packages - list of packages to add | ||
* @param dep - which dependencies section to add | ||
* | ||
* @returns packages actually added | ||
*/ | ||
export const addDepToPkgJson = (pkgJson: any, packages: Record<string, string>, dep: string) => { | ||
const section = (pkgJson[dep] = pkgJson[dep] || {}); | ||
const added = {}; | ||
Object.keys(packages).forEach(name => { | ||
if (!section.hasOwnProperty(name)) { | ||
section[name] = packages[name]; | ||
added[name] = packages[name]; | ||
} | ||
}); | ||
|
||
if (!_.isEmpty(added)) { | ||
pkgJson[dep] = Object.keys(section) | ||
.sort() | ||
.reduce((sorted, key) => { | ||
sorted[key] = section[key]; | ||
return sorted; | ||
}, {}); | ||
} | ||
|
||
return added; | ||
}; | ||
|
||
/** | ||
* Load a package.json from dir | ||
* @param dir - directory | ||
* @returns package.json object | ||
*/ | ||
export const loadPkgJson = (dir: string) => { | ||
return JSON.parse(Fs.readFileSync(Path.resolve(dir, "package.json"), "utf-8")); | ||
}; | ||
|
||
/** | ||
* Save a package.json to dir | ||
* @param dir - directory | ||
* @params pkgJson - package.json object | ||
* @returns none | ||
*/ | ||
export const savePkgJson = (dir: string, pkgJson: any) => { | ||
return Fs.writeFileSync(Path.resolve(dir, "package.json"), JSON.stringify(pkgJson, null, 2)); | ||
}; | ||
|
||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const xarcAppPkgJson = require("@xarc/app/package.json"); | ||
const logger = require("../logger"); | ||
|
||
/** | ||
* Update app's dependencies | ||
* | ||
* @param xarcCwd - CWD for app | ||
* @returns nothing | ||
*/ | ||
export const updateAppDep = (xarcCwd: string) => { | ||
const appPkg = loadPkgJson(xarcCwd); | ||
const added = addDepToPkgJson( | ||
appPkg, | ||
_.pick(xarcAppPkgJson.dependencies, ["@babel/runtime"]), | ||
"dependencies" | ||
); | ||
if (!_.isEmpty(added)) { | ||
savePkgJson(xarcCwd, appPkg); | ||
logger.info( | ||
`*** | ||
Added these packages to your dependencies, please run install again: ${Object.keys(added)} | ||
***` | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,13 +36,14 @@ | |
"Joel Chen <[email protected]>" | ||
], | ||
"dependencies": { | ||
"@babel/runtime": "^7.8.3", | ||
"@babel/runtime": "^7.12.5", | ||
"babel-plugin-react-css-modules": "^5.2.6", | ||
"css-modules-require-hook": "^4.0.2", | ||
"ignore-styles": "^5.0.1", | ||
"isomorphic-loader": "^4.3.0", | ||
"optional-require": "^1.0.0", | ||
"subapp-util": "^1.1.2" | ||
"subapp-util": "^1.1.2", | ||
"tslib": "^2.1.0" | ||
}, | ||
"devDependencies": { | ||
"@istanbuljs/nyc-config-typescript": "^1.0.1", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"lib": [ | ||
"es2018" | ||
], | ||
"lib": ["es2018"], | ||
"module": "CommonJS", | ||
"esModuleInterop": false, | ||
"target": "ES2018", | ||
"preserveConstEnums": true, | ||
"sourceMap": true, | ||
"declaration": true, | ||
"types": [ | ||
"node" | ||
], | ||
"types": ["node"], | ||
"forceConsistentCasingInFileNames": true, | ||
"noImplicitReturns": true, | ||
"alwaysStrict": true, | ||
"strictFunctionTypes": true | ||
"strictFunctionTypes": true, | ||
"importHelpers": true | ||
}, | ||
"include": [ | ||
"src" | ||
] | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters