Permalink
Browse files

feat: bundle dependencies

Close #338
  • Loading branch information...
1 parent 579a258 commit 58aaa0d6fd9da9c326a42079c3b575adde611db1 @zkochan zkochan committed with zkochan Oct 3, 2016
Showing with 35 additions and 79 deletions.
  1. +4 −6 .scripts/hide_deps.js
  2. +20 −25 .scripts/release.sh
  3. +0 −24 .scripts/rename.js
  4. +3 −13 .scripts/{rename_key.js → rename_keys.js}
  5. +4 −6 .scripts/unhide_deps.js
  6. +4 −5 package.json
View
@@ -1,9 +1,7 @@
'use strict'
-const renameKey = require('./rename_key')
+const renameKeys = require('./rename_keys')
-renameKey({
- pkgName: 'pnpm-rocket',
- currentKeyName: 'dependencies',
- newKeyName: '__dependencies',
- addPreinstall: true
+renameKeys({
+ dependencies: '__dependencies',
+ scripts: '__scripts'
})
View
@@ -1,45 +1,40 @@
#!/bin/bash
+set -e;
+
if [ -d node_modules ]; then
- echo "rename the current node_modules";
- mv node_modules prev_node_modules;
+ echo "moving the current node_modules to a temporal location";
+ mv node_modules .tmp/node_modules;
fi
-set -e;
echo "install just the dependencies and don't run any pre/post install scripts";
npm install --production --ignore-scripts;
-publish () {
- if [[ $1 ]]; then
- npm publish --tag $1;
- else
- npm publish;
- fi
-}
-
-echo "publish pnpm $1";
-publish;
-
-echo "rename node_modules to cached_node_modules";
-node .scripts/rename node_modules cached_node_modules;
+echo "move node_modules/ to lib/";
+mv node_modules lib/node_modules;
echo "remove the dependencies section from package.json";
node .scripts/hide_deps;
-set +e;
-echo "publish pnpm-rocket $1";
-publish;
+echo "publish pnpm $1";
+if [[ $1 ]]; then
+ npm publish --tag $1;
+else
+ npm publish;
+fi
+
+set +e;
echo "return the dependencies section to package.json";
node .scripts/unhide_deps;
-if [ -d prev_node_modules ]; then
- echo "remove cached_node_modules";
- rm -rf cached_node_modules;
+if [ -d .tmp/node_modules ]; then
+ echo "remove lib/node_modules";
+ rm -rf lib/node_modules;
echo "return the initial node_modules";
- mv prev_node_modules node_modules;
+ mv .tmp/node_modules node_modules;
else
- echo "rename cached_node_modules to node_modules";
- mv cached_node_modules node_modules;
+ echo "move node_modules back to the root";
+ mv lib/node_modules node_modules;
fi
View
@@ -1,24 +0,0 @@
-'use strict'
-const fs = require('fs')
-const path = require('path')
-
-const cwd = process.cwd()
-
-const oldDirName = process.argv[2]
-const newDirName = process.argv[3]
-
-renameDirectories(cwd)
-
-function renameDirectories (srcpath) {
- return fs.readdirSync(srcpath)
- .map(file => path.join(srcpath, file))
- .filter(file => fs.statSync(file).isDirectory())
- .forEach(file => {
- renameDirectories(file)
- const parts = file.split(path.sep)
- if (parts[parts.length - 1] === oldDirName) {
- const newDirPath = (parts.slice(0, -1).concat([newDirName])).join(path.sep)
- fs.renameSync(file, newDirPath)
- }
- })
-}
@@ -3,30 +3,20 @@ const fs = require('fs')
const path = require('path')
const eof = require('os').EOL
-module.exports = opts => {
+module.exports = keysMap => {
const pkgPath = path.resolve(process.cwd(), 'package.json')
const rawPkgJSON = fs.readFileSync(pkgPath, 'UTF8')
const pkgJSON = JSON.parse(rawPkgJSON)
const newPkgJSON = {}
const keys = Object.keys(pkgJSON)
for (let i = 0; i < keys.length; i++) {
- if (keys[i] === 'scripts') {
- newPkgJSON.scripts = pkgJSON.scripts
- if (opts.pkgName === 'pnpm-rocket') {
- newPkgJSON.scripts.preinstall = 'node .scripts/rename cached_node_modules node_modules'
- continue
- }
- delete newPkgJSON.scripts.preinstall
- continue
- }
- if (keys[i] === opts.currentKeyName) {
- newPkgJSON[opts.newKeyName] = pkgJSON[opts.currentKeyName]
+ if (keysMap[keys[i]]) {
+ newPkgJSON[keysMap[keys[i]]] = pkgJSON[keys[i]]
continue
}
newPkgJSON[keys[i]] = pkgJSON[keys[i]]
}
- newPkgJSON.name = opts.pkgName
fs.writeFileSync(pkgPath, JSON.stringify(newPkgJSON, null, 2) + eof, 'UTF8')
}
@@ -1,9 +1,7 @@
'use strict'
-const renameKey = require('./rename_key')
+const renameKeys = require('./rename_keys')
-renameKey({
- pkgName: 'pnpm',
- currentKeyName: '__dependencies',
- newKeyName: 'dependencies',
- addPreinstall: false
+renameKeys({
+ __dependencies: 'dependencies',
+ __scripts: 'scripts'
})
View
@@ -13,9 +13,7 @@
"typings": "lib/index.d.ts",
"files": [
"bin/",
- "lib/",
- ".scripts/",
- "cached_node_modules/"
+ "lib/"
],
"dependencies": {
"@zkochan/logger": "0.1.0",
@@ -67,6 +65,7 @@
"docpress": "0.6.13",
"ghooks": "^1.3.2",
"git-update-ghpages": "1.3.0",
+ "in-publish": "2.0.0",
"isexe": "1.1.2",
"istanbul": "^0.4.5",
"ncp": "^2.0.0",
@@ -106,10 +105,10 @@
"lint": "standard && tslint -c tslint.json ./src/**/*.ts ./test/**/*.ts",
"test": "npm run lint && ts-node test | tap-diff",
"posttest": "rm -rf .tmp",
- "prerelease": "npm test",
+ "prerelease": "npm run tsc && npm test",
"release": "sh .scripts/release.sh",
"tsc": "rm -rf lib && tsc",
- "prepublish": "npm run tsc"
+ "prepublish": "in-publish && echo 'You need to use \"npm run release\" to publish pnpm' && false || not-in-publish"
},
"config": {
"commitizen": {

0 comments on commit 58aaa0d

Please sign in to comment.