-
Notifications
You must be signed in to change notification settings - Fork 22
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
1 parent
1382a8c
commit bd75400
Showing
4 changed files
with
63 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ dist | |
**.js | ||
**.d.ts | ||
!jest.config.js | ||
!scripts/** | ||
|
||
#gulp | ||
!gulpfile.js | ||
|
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,38 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const env = require("./variables"); | ||
|
||
// Define absolute paths for original pkg and temporary pkg. | ||
const ORIG_PATH = path.resolve(__dirname, env.ORIG_PATH); | ||
const TEMP_PATH = path.resolve(__dirname, env.TEMP_PATH); | ||
|
||
// Obtain original `package.json` contents. | ||
const packageData = require(ORIG_PATH); | ||
|
||
// Write/cache the original `package.json` data to `cached-package.json` file. | ||
fs.writeFile(TEMP_PATH, JSON.stringify(packageData, null, 2), function (err) { | ||
if (err) throw err; | ||
}); | ||
|
||
// Define properties to remove in `package.json`. | ||
const removableProps = ["devDependencies"]; | ||
|
||
// Remove the specified properties from `package.json`. | ||
removableProps.forEach((prop) => delete packageData[prop]); | ||
|
||
// Define new scripts | ||
const scripts = { | ||
clean: "rimraf interface && rimraf index.js && rimraf index.d.ts && rimraf utils && rimraf router && rimraf lib", | ||
postpack: "npm run clean && node ./scripts/restore-package.js", | ||
}; | ||
|
||
// Replace scripts value | ||
packageData.scripts = scripts; | ||
|
||
// Replace main value | ||
packageData.main = "index.js"; | ||
|
||
// Overwrite original `package.json` with new data (i.e. minus the specific data). | ||
fs.writeFile(ORIG_PATH, JSON.stringify(packageData, null, 2), function (err) { | ||
if (err) throw err; | ||
}); |
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,20 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const env = require("./variables"); | ||
|
||
// Define absolute paths for original pkg and temporary pkg. | ||
const ORIG_PATH = path.resolve(__dirname, env.ORIG_PATH); | ||
const TEMP_PATH = path.resolve(__dirname, env.TEMP_PATH); | ||
|
||
// Obtain original/cached contents from `cached-package.json`. | ||
const packageData = JSON.stringify(require(TEMP_PATH), null, 2) + "\n"; | ||
|
||
// Write data from `cached-package.json` back to original `package.json`. | ||
fs.writeFile(ORIG_PATH, packageData, function (err) { | ||
if (err) throw err; | ||
}); | ||
|
||
// Delete the temporary `cached-package.json` file. | ||
fs.unlink(TEMP_PATH, function (err) { | ||
if (err) throw err; | ||
}); |
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,4 @@ | ||
module.exports = { | ||
ORIG_PATH: "../package.json", | ||
TEMP_PATH: "./temp-package.json", | ||
}; |