Skip to content
This repository has been archived by the owner on Feb 5, 2022. It is now read-only.

Commit

Permalink
feat: '--registry' option (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz authored and egoist committed Nov 18, 2018
1 parent ac55732 commit e944eb6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
4 changes: 4 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ cli
desc: 'Use the default options',
alias: 'y'
})
.option('registry', {
desc: 'Use a custom registry for npm and yarn',
type: 'string'
})

cli.command('set-alias', 'Set an alias for a generator path', input => {
const store = require('../lib/store')
Expand Down
1 change: 1 addition & 0 deletions lib/GeneratorContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ module.exports = class GeneratorContext {
return require('./installPackages')(
Object.assign(
{
registry: this.sao.opts.registry,
cwd: this.outDir
},
opts
Expand Down
12 changes: 7 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class SAO {
generator = generator || this.parsedGenerator

if (generator.type === 'repo') {
await ensureRepo(generator, this.opts.update, this.opts.clone)
await ensureRepo(generator, this.opts)
} else if (generator.type === 'npm') {
await ensurePackage(generator, this.opts.update)
await ensurePackage(generator, this.opts)
} else if (generator.type === 'local') {
await ensureLocal(generator)
}
Expand Down Expand Up @@ -162,9 +162,9 @@ function downloadRepo(repo, target, opts) {
* Ensure packages are installed in a generator
* In most cases this is used for `repo` generators
* @param {Object} generator
* @param {boolean=} update
* @param {Object} options
*/
async function ensureRepo(generator, update, clone) {
async function ensureRepo(generator, { update, clone, registry }) {
if (!update && (await fs.pathExists(generator.path))) {
return
}
Expand All @@ -191,6 +191,7 @@ async function ensureRepo(generator, update, clone) {
if (hasConfig && hasPackageJson) {
await installPackages({
cwd: generator.path,
registry,
installArgs: ['--production']
})
}
Expand All @@ -206,7 +207,7 @@ async function ensureLocal(generator) {
}
}

async function ensurePackage(generator, update) {
async function ensurePackage(generator, { update, registry }) {
const installPath = path.join(paths.packagePath, generator.hash)

if (update || !(await fs.pathExists(generator.path))) {
Expand All @@ -221,6 +222,7 @@ async function ensurePackage(generator, update) {
logger.debug('Installing generator at', installPath)
await installPackages({
cwd: installPath,
registry,
packages: [`${generator.name}@${generator.version || 'latest'}`]
})
}
Expand Down
17 changes: 15 additions & 2 deletions lib/installPackages.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,29 @@ function getNpmClient() {
return cachedNpmClient || setNpmClient()
}

module.exports = async ({ cwd, npmClient, installArgs, packages, saveDev }) => {
module.exports = async ({
cwd,
npmClient,
installArgs,
packages,
saveDev,
registry
}) => {
npmClient = npmClient || getNpmClient()
const packageName = packages ? packages.join(', ') : 'packages'
spinner.start(`Installing ${packageName} with ${npmClient}`)

return new Promise((resolve, reject) => {
const args = [packages ? 'add' : 'install'].concat(packages ? packages : [])
if (saveDev) {
args.push(npmClient === 'npm' ? '-D' : '--dev')
}
if (registry) {
args.push('--registry', registry)
}

installArgs = args.concat(installArgs || [])
logger.debug(npmClient, installArgs.join(' '))
spinner.start(`Installing ${packageName} with ${npmClient}`)
const ps = spawn(npmClient, args.concat(installArgs || []), {
stdio: [0, 'pipe', 'pipe'],
cwd,
Expand Down

0 comments on commit e944eb6

Please sign in to comment.