Created
March 24, 2016 10:02
-
-
Save makenowjust/0894cd336a4683c3fb77 to your computer and use it in GitHub Desktop.
Bye npm, Hello Git repository.
This file contains hidden or 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
'use strict' | |
/* | |
* Rewrite package.json to get dependencies from Git repository instead of npm. | |
* | |
* See also: https://medium.com/@azerbike/i-ve-just-liberated-my-modules-9045c06be67c | |
* and: http://blog.npmjs.org/post/141577284765/kik-left-pad-and-npm | |
* | |
* Usage: cd /path/to/your/package && node npm2git | |
* | |
* This script is warning because: | |
* | |
* - this is forgotten dependencies' version information. | |
* - Git repository dose not contain all package files always. | |
* | |
* You will be happened some troubles in many case. | |
* | |
* Author: TSUYUSATO Kitsune (GitHub: @MakeNowJust, Twitter: @make_now_just) | |
* License: WTFPL <http://www.wtfpl.net/txt/copying/> | |
* | |
* If you have some idea to improve, you could fork this Gist, thanks;) | |
*/ | |
const fs = require('fs') | |
const pkg = require('./package.json') | |
const npm2git = field => { | |
if (!pkg[field]) return | |
for (let name of Object.keys(pkg[field])) { | |
pkg[field][name] = require(`./node_modules/${name}/package.json`).repository.url || (()=> { | |
console.error(`${name} has no repository field`) | |
return pkg[field][name] | |
})() | |
} | |
} | |
'dependencies devDependencies peerDependencies optionalDependencies' | |
.split(' ') | |
.forEach(npm2git) | |
const json = JSON.stringify(pkg, null, ' ') | |
console.log(json) | |
fs.writeFileSync('package.json', json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. I'm thinking along the same lines.