forked from necccc/npm-migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.js
32 lines (24 loc) · 917 Bytes
/
update.js
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
const fs = require('graceful-fs')
const async = require('async')
const curry = require('lodash.curry')
const updatePackageJson = function (newRegistry, folder, callback) {
const packjson = folder + '/package.json'
let packageJsonObject = require(packjson)
packageJsonObject.publishConfig = { registry: newRegistry }
fs.writeFile(packjson, JSON.stringify(packageJsonObject), (err) => {
if (err) return callback(err);
callback(null, folder)
})
}
module.exports = function update (newRegistry, folders) {
let curried_updatePackageJson = curry(updatePackageJson)
let series = folders.map((folder) => curried_updatePackageJson(newRegistry, folder))
return new Promise((resolve, reject) => {
async.series(
series,
(err, results) => {
if (err) return reject(err);
resolve(results)
})
})
}