Skip to content

Commit

Permalink
[cli] Replace progrescii + thenify dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Feb 21, 2018
1 parent dd2cd28 commit f4d3b0e
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 36 deletions.
4 changes: 2 additions & 2 deletions packages/@sanity/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@
"debug": "^3.1.0",
"decompress": "^4.2.0",
"deep-sort-object": "^1.0.1",
"es6-promisify": "^6.0.0",
"eventsource": "^1.0.5",
"execa": "^0.9.0",
"fs-extra": "^5.0.0",
"gauge": "^2.7.4",
"git-user-info": "^1.0.1",
"gitconfiglocal": "^2.0.1",
"inquirer": "^5.1.0",
Expand All @@ -65,15 +67,13 @@
"ora": "^1.3.0",
"osenv": "^0.1.4",
"package-json": "^4.0.1",
"progrescii": "^0.1.1",
"promise-props-recursive": "^1.0.0",
"resolve-from": "^4.0.0",
"rimraf": "^2.6.2",
"semver": "^5.5.0",
"semver-compare": "^1.0.0",
"simple-get": "^2.7.0",
"split2": "^2.1.1",
"thenify": "^3.3.0",
"validate-npm-package-name": "^3.0.0",
"webpack": "^3.8.1",
"which": "^1.3.0",
Expand Down
15 changes: 7 additions & 8 deletions packages/@sanity/cli/scripts/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,14 @@ compiler.run((err, stats) => {
throw err
}

if (stats.compilation.warnings.length > 0) {
console.warn('=== [ Warnings ]========')
stats.compilation.warnings.forEach(warn => {
if (!warn.name === 'ModuleDependencyWarning') {
console.warn(warn)
return
}
const filtered = stats.compilation.warnings.filter(warn => {
return !warn.origin || warn.origin.userRequest.indexOf('spawn-sync.js') === -1
})

console.warn(`\n${warn.origin.userRequest}:`)
if (filtered.length > 0) {
console.warn('=== [ Warnings ]========')
filtered.forEach(warn => {
console.warn(warn.origin ? `\n${warn.origin.userRequest}:` : '\n')
console.warn(`${warn}\n`)
})
console.warn('=== [ /Warnings ]========\n')
Expand Down
29 changes: 15 additions & 14 deletions packages/@sanity/cli/src/actions/yarn/yarnWithProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import ora from 'ora'
import execa from 'execa'
import split2 from 'split2'
import chalk from 'chalk'
import progrescii from 'progrescii'
import {noop, padEnd, throttle} from 'lodash'
import Gauge from 'gauge'
import {noop, throttle} from 'lodash'
import dynamicRequire from '../../util/dynamicRequire'

const useProgress = process.stderr && process.stderr.isTTY && !process.env.CI
Expand All @@ -31,9 +31,6 @@ export default function yarnWithProgress(args, options = {}) {
const error = options.error || console.error
/* eslint-enable no-console */

const padLength = 'Resolving dependencies'.length
const getProgressTemplate = (symbol, msg) => `${symbol} ${padEnd(msg, padLength)} :b :p% (:ts)`

const execOpts = Object.assign(
{
cwd: options.rootDir || process.cwd(),
Expand All @@ -46,6 +43,10 @@ export default function yarnWithProgress(args, options = {}) {
const nodeArgs = [yarnPath].concat(args, ['--json', '--non-interactive'])

const state = {firstStepReceived: false, currentProgressStep: null}
state.progress = new Gauge(process.stderr, {
theme: 'colorASCII',
enabled: true
})

// Yarn takes a while before starting to emit events, we want to show
// some sort of indication while it's getting started
Expand All @@ -71,8 +72,8 @@ export default function yarnWithProgress(args, options = {}) {
const interceptors = options.interceptors || {}
const throttledOnProgressTick = throttle(onProgressTick, 50)

// eslint-disable-next-line complexity
function onChunk(event) {
// eslint-disable-line complexity
if (interceptors[event.type]) {
return interceptors[event.type](event)
}
Expand Down Expand Up @@ -150,10 +151,8 @@ export default function yarnWithProgress(args, options = {}) {

if (useProgress && event.data.total) {
state.currentProgressStep = state.step.message
state.progress = progrescii.create({
template: getProgressTemplate(chalk.yellow('●'), state.step.message),
total: event.data.total
})
state.progressTotal = event.data.total
state.progress.show(state.step.message, 0)
} else {
print(`${chalk.yellow('●')} ${state.step.message}`)
}
Expand All @@ -169,7 +168,7 @@ export default function yarnWithProgress(args, options = {}) {
return // Will be taken care of by onProgressFinish
}

prog.set(event.data.current)
prog.show(state.step.message, event.data.current / state.progressTotal)
}

function onProgressFinish(event) {
Expand All @@ -178,8 +177,7 @@ export default function yarnWithProgress(args, options = {}) {
return
}

prog.template = getProgressTemplate(chalk.green('✔'), state.step.message)
prog.set(prog.total)
prog.show(`${chalk.green('✔')} ${state.step.message}`, 1)
}

function onStep(event) {
Expand All @@ -191,6 +189,10 @@ export default function yarnWithProgress(args, options = {}) {
state.spinner.stop()
}

if (state.progress) {
state.progress.disable()
}

print(`\n${chalk.green('✔')} Saved lockfile`)
}

Expand All @@ -206,7 +208,6 @@ export default function yarnWithProgress(args, options = {}) {
function onWarning(event) {
// For now, skip the warnings as they seem to only contain the first line of the text,
// so it makes no sense to show it. Debug this later and consider reimplementing this.
// holdSpinner(() => print(`${chalk.yellow('●')} ${event.data}`))
}

function onError(event) {
Expand Down
7 changes: 4 additions & 3 deletions packages/@sanity/cli/src/util/getProjectDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fse from 'fs-extra'
import gitConfigLocal from 'gitconfiglocal'
import gitUserInfo from 'git-user-info'
import promiseProps from 'promise-props-recursive'
import thenify from 'thenify'
import {promisify} from 'es6-promisify'

export default (workDir, {isPlugin, context}) => {
const cwd = process.cwd()
Expand All @@ -23,9 +23,10 @@ export default (workDir, {isPlugin, context}) => {
})
}

const getGitConfig = thenify(gitConfigLocal)
const getGitConfig = promisify(gitConfigLocal)
function resolveGitRemote(cwd) {
return fse.stat(path.join(cwd, '.git'))
return fse
.stat(path.join(cwd, '.git'))
.then(() => getGitConfig(cwd))
.then(cfg => cfg.remote && cfg.remote.origin && cfg.remote.origin.url)
.catch(() => null)
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"batch-stream-operation": "^1.0.2",
"debug": "^3.1.0",
"deep-sort-object": "^1.0.1",
"es6-promisify": "^6.0.0",
"filesize": "^3.5.6",
"fs-extra": "^5.0.0",
"get-uri": "^2.0.1",
Expand All @@ -50,7 +51,6 @@
"simple-concat": "^1.0.0",
"simple-get": "^2.7.0",
"tar-fs": "^1.16.0",
"thenify": "^3.3.0",
"through2": "^2.0.3",
"uglify-es": "3.3.9"
},
Expand Down
12 changes: 6 additions & 6 deletions packages/@sanity/core/src/actions/build/buildStaticAssets.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import fse from 'fs-extra'
import path from 'path'
import fse from 'fs-extra'
import rimTheRaf from 'rimraf'
import thenify from 'thenify'
import filesize from 'filesize'
import compressJavascript from './compressJavascript'
import {promisify} from 'es6-promisify'
import getConfig from '@sanity/util/lib/getConfig'
import {getWebpackCompiler, getDocumentElement, ReactDOM} from '@sanity/server'
import sortModulesBySize from '../../stats/sortModulesBySize'
import checkReactCompatibility from '../../util/checkReactCompatibility'
import {tryInitializePluginConfigs} from '../config/reinitializePluginConfigs'
import {getWebpackCompiler, getDocumentElement, ReactDOM} from '@sanity/server'
import compressJavascript from './compressJavascript'

const rimraf = thenify(rimTheRaf)
const rimraf = promisify(rimTheRaf)
const absoluteMatch = /^https?:\/\//i

export default async (args, context) => {
Expand Down Expand Up @@ -38,7 +38,7 @@ export default async (args, context) => {
checkReactCompatibility(workDir)

const compiler = getWebpackCompiler(compilationConfig)
const compile = thenify(compiler.run.bind(compiler))
const compile = promisify(compiler.run.bind(compiler))
let shouldDelete = true

if (outputDir !== defaultOutputDir) {
Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/core/src/actions/start/startAction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path'
import chalk from 'chalk'
import thenify from 'thenify'
import {promisify} from 'es6-promisify'
import {getProdServer, getDevServer} from '@sanity/server'
import getConfig from '@sanity/util/lib/getConfig'
import isProduction from '../../util/isProduction'
Expand Down Expand Up @@ -46,7 +46,7 @@ export default async (args, context) => {

// Start the server and try to create more user-friendly errors if we encounter issues
try {
await thenify(server.listen.bind(server))(httpPort, httpHost)
await promisify(server.listen.bind(server))(httpPort, httpHost)
} catch (err) {
gracefulDeath(httpHost, config, err)
}
Expand Down

0 comments on commit f4d3b0e

Please sign in to comment.