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

Add use private npm& install from git url feat #129

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/installPackages.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ module.exports = async ({
installArgs,
packages,
saveDev,
registry
registry,
clientParams
}) => {
npmClient = npmClient || getNpmClient()
const packageName = packages ? packages.join(', ') : 'packages'

return new Promise((resolve, reject) => {
// `npm/pnpm/yarn add <packages>`
// `npm/pnpm/yarn install`
const args = [packages ? 'add' : 'install'].concat(packages ? packages : [])
let args = [packages ? 'add' : 'install'].concat(packages ? packages : [])
if (saveDev) {
args.push(npmClient === 'npm' ? '-D' : '--dev')
}
Expand All @@ -50,6 +51,11 @@ module.exports = async ({
args.push(...installArgs)
}

// add params between npmClient param and install
if (clientParams) {
args = clientParams.concat(args)
}

logger.debug(npmClient, args.join(' '))
logger.debug('install directory', cwd)
spinner.start(`Installing ${packageName} with ${npmClient}`)
Expand All @@ -65,7 +71,8 @@ module.exports = async ({
/* eslint-enable camelcase */
},
process.env
)
),
shell: true // fix sometimes can't read environment variables
})

let stdoutLogs = ''
Expand Down
28 changes: 27 additions & 1 deletion lib/parseGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = generator => {
}
}

const SPECIAL_PREFIX_RE = /^(npm|github|bitbucket|gitlab|alias):/
const SPECIAL_PREFIX_RE = /^(npm|github|bitbucket|gitlab|alias|direct):/

if (!SPECIAL_PREFIX_RE.test(generator) && !generator.includes('/')) {
generator = `npm:sao-${generator}`
Expand Down Expand Up @@ -90,6 +90,32 @@ module.exports = generator => {
path: path.join(paths.repoPath, hash)
}
}
// add direct git url
if (type === 'direct') {
const slug = 'direct:' + generator
let copyGenerator = generator
const protocolReg = /(http|https|ssh):(\/\/)/
const portReg = /:[1-9]\d*/
if (protocolReg.test(copyGenerator)) {
const fullProt = copyGenerator.match(protocolReg)[0]
copyGenerator = copyGenerator.split(fullProt)[1]
}
if (portReg.test(copyGenerator)) {
const fullPort = copyGenerator.match(portReg)[0]
copyGenerator = copyGenerator.split(fullPort)[1]
}

const hash = sum(`repo:${slug}`)
const hasSubGenerator = copyGenerator.indexOf(':') !== -1
return {
type: 'repo',
slug,
subGenerator:
hasSubGenerator && copyGenerator.slice(generator.indexOf(':') + 1),
hash,
path: path.join(paths.repoPath, hash)
}
}

const [
,
Expand Down