Comparing version 1.4.1 to 1.5.0
@@ -5,3 +5,3 @@ #!/usr/bin/env node | ||
const cli = cac() | ||
const cli = cac('sao') | ||
@@ -28,3 +28,3 @@ cli | ||
'--npm-client <client>', | ||
`Use a specific npm client ('yarn' or 'npm')` | ||
`Use a specific npm client ('yarn' | 'npm' | 'pnpm')` | ||
) | ||
@@ -34,3 +34,4 @@ .option('-u, --update', 'Update cached generator') | ||
.option('-y, --yes', 'Use the default options') | ||
.option('--registry <registry>', 'Use a custom registry for npm and yarn') | ||
.option('--registry <registry>', 'Use a custom registry for package manager') | ||
.option('--debug', 'Show debug logs') | ||
@@ -37,0 +38,0 @@ cli |
@@ -44,3 +44,3 @@ const path = require('path') | ||
get npmClient() { | ||
return this.sao.opts.npmClient | ||
return require('./installPackages').getNpmClient() | ||
} | ||
@@ -47,0 +47,0 @@ |
@@ -33,6 +33,6 @@ const path = require('path') | ||
: this.opts.debug | ||
? 4 | ||
: this.opts.quiet | ||
? 1 | ||
: 3 | ||
? 4 | ||
: this.opts.quiet | ||
? 1 | ||
: 3 | ||
}) | ||
@@ -39,0 +39,0 @@ |
@@ -1,5 +0,3 @@ | ||
const readline = require('readline') | ||
const stripAnsi = require('strip-ansi') | ||
const spawn = require('cross-spawn') | ||
const wcwidth = require('wcwidth') | ||
const logUpdate = require('log-update') | ||
const spinner = require('./spinner') | ||
@@ -12,16 +10,19 @@ const logger = require('./logger') | ||
function setNpmClient(npmClient) { | ||
if (npmClient) { | ||
cachedNpmClient = npmClient | ||
return npmClient | ||
cachedNpmClient = npmClient | ||
} | ||
function getNpmClient() { | ||
if (cachedNpmClient) { | ||
return cachedNpmClient | ||
} | ||
const { stdout, status } = spawn.sync('yarn', ['--version']) | ||
cachedNpmClient = status === 0 && stdout ? 'yarn' : 'npm' | ||
if (spawn.sync('pnpm', ['--version']).status === 0) { | ||
cachedNpmClient = 'pnpm' | ||
} else if (spawn.sync('yarn', ['--version']).status === 0) { | ||
cachedNpmClient = 'yarn' | ||
} | ||
return cachedNpmClient | ||
} | ||
function getNpmClient() { | ||
return cachedNpmClient || setNpmClient() | ||
} | ||
module.exports = async ({ | ||
@@ -39,2 +40,4 @@ cwd, | ||
return new Promise((resolve, reject) => { | ||
// `npm/pnpm/yarn add <packages>` | ||
// `npm/pnpm/yarn install` | ||
const args = [packages ? 'add' : 'install'].concat(packages ? packages : []) | ||
@@ -53,2 +56,3 @@ if (saveDev) { | ||
logger.debug(npmClient, args.join(' ')) | ||
logger.debug('install directory', cwd) | ||
spinner.start(`Installing ${packageName} with ${npmClient}`) | ||
@@ -70,10 +74,14 @@ const ps = spawn(npmClient, args, { | ||
let output = '' | ||
const stream = process.stderr | ||
let stdoutLogs = '' | ||
let stderrLogs = '' | ||
ps.stdout && | ||
ps.stdout.on('data', data => { | ||
output += data | ||
ps.stdout.setEncoding('utf8').on('data', data => { | ||
if (npmClient === 'pnpm') { | ||
stdoutLogs = data | ||
} else { | ||
stdoutLogs += data | ||
} | ||
spinner.stop() | ||
stream.write(data) | ||
logUpdate(stdoutLogs) | ||
spinner.start() | ||
@@ -83,6 +91,12 @@ }) | ||
ps.stderr && | ||
ps.stderr.on('data', data => { | ||
output += data | ||
ps.stderr.setEncoding('utf8').on('data', data => { | ||
if (npmClient === 'pnpm') { | ||
stderrLogs = data | ||
} else { | ||
stderrLogs += data | ||
} | ||
spinner.stop() | ||
stream.write(data) | ||
logUpdate.clear() | ||
logUpdate.stderr(stderrLogs) | ||
logUpdate(stdoutLogs) | ||
spinner.start() | ||
@@ -95,15 +109,4 @@ }) | ||
if (code === 0) { | ||
const columns = stream.columns || 80 | ||
const lineCount = stripAnsi(output) | ||
.split('\n') | ||
.reduce((count, line) => { | ||
return count + Math.max(1, Math.ceil(wcwidth(line) / columns)) | ||
}, 0) | ||
for (let i = 0; i < lineCount; i++) { | ||
if (i > 0) { | ||
readline.moveCursor(stream, 0, -1) | ||
} | ||
readline.clearLine(stream, 0) | ||
readline.cursorTo(stream, 0) | ||
} | ||
logUpdate.clear() | ||
logUpdate.stderr.clear() | ||
logger.success(`Installed ${packageName}`) | ||
@@ -110,0 +113,0 @@ } else { |
@@ -26,6 +26,9 @@ const path = require('path') | ||
) | ||
const isYarn = yarnGlobal.hasDependency('sao') | ||
const isPnpm = __dirname.includes('/pnpm-global/') | ||
const isYarn = !isPnpm && yarnGlobal.hasDependency('sao') | ||
logger.tip( | ||
`To upgrade SAO, run the following command:\n${chalk.dim( | ||
isYarn ? '$ yarn global add sao' : '$ npm i -g sao' | ||
isYarn | ||
? '$ yarn global add sao' | ||
: `$ ${isPnpm ? 'pnpm' : 'npm'} i -g sao` | ||
)}` | ||
@@ -32,0 +35,0 @@ ) |
{ | ||
"name": "sao", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"description": "Futuristic scaffolding tool ⚔", | ||
@@ -23,3 +23,3 @@ "repository": { | ||
"dependencies": { | ||
"cac": "^6.1.3", | ||
"cac": "^6.3.8", | ||
"chalk": "^2.4.1", | ||
@@ -37,2 +37,3 @@ "conf": "^2.0.0", | ||
"jstransformer-ejs": "^0.2.0", | ||
"log-update": "^2.3.0", | ||
"majo": "^0.6.2", | ||
@@ -43,5 +44,3 @@ "micromatch": "^3.1.10", | ||
"resolve-from": "^4.0.0", | ||
"strip-ansi": "^5.0.0", | ||
"update-notifier": "^2.5.0", | ||
"wcwidth": "^1.0.1", | ||
"yarn-global": "^1.1.0" | ||
@@ -48,0 +47,0 @@ }, |
@@ -26,3 +26,3 @@ <p align="center"> | ||
```bash | ||
yarn global add sao | ||
npm i -g sao | ||
@@ -29,0 +29,0 @@ # An official generator for creating a Node.js project |
38238
21
1101
9551
+ Addedlog-update@^2.3.0
+ Addedlog-update@2.3.0(transitive)
+ Addedwrap-ansi@3.0.1(transitive)
- Removedstrip-ansi@^5.0.0
- Removedwcwidth@^1.0.1
Updatedcac@^6.3.8