Skip to content

Commit

Permalink
Remove nuxt/consola from dependencies (#4)
Browse files Browse the repository at this point in the history
* Remove nuxt/consola from dependencies

* Modify log info
  • Loading branch information
kthjm authored Jul 23, 2018
1 parent 3f699c6 commit 8c9d3ba
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 58 deletions.
12 changes: 8 additions & 4 deletions bin/chin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ function _interopDefault(ex) {
return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex
}

var consola = _interopDefault(require('consola'))
var chalk = _interopDefault(require('chalk'))
var figures = _interopDefault(require('figures'))
var appRootPath = require('app-root-path')
var fsExtra = require('fs-extra')
var path = require('path')
var program = _interopDefault(require('commander'))
var __ = require('..')

const PUT = 'assets'
const OUT = 'public'
const CONFIG1 = 'chin.config.js'
const CONFIG2 = '.chin/index.js'
const PRE_INFO = chalk.blue('info')
const PRE_FAIL = chalk.red(figures.cross)

const requireModules = requireValue =>
requireValue.split(',').forEach(moduleName => require(moduleName))
Expand All @@ -32,7 +36,7 @@ const getConfig = configValue => {
try {
config = appRootPath.require(CONFIG2)
} catch (e2) {
throw !e2.message.includes(CONFIG2)
throw !e2.message.includes(path.normalize(CONFIG2))
? e2
: new Error(`Cannot find ${CONFIG1} || ${CONFIG2}`)
}
Expand All @@ -49,13 +53,13 @@ var action = (program$$1, action) =>
() =>
program$$1.config
? getConfig(program$$1.config)
: consola.info('no config')
: console.info(`${PRE_INFO} no config`)
)
.then((config = {}) => (Array.isArray(config) ? config : [config]))
.then(configs => recursiveSpliceAction(program$$1, configs, action))
.then(() => console.log(''))
.catch(err => {
consola.error(err)
console.error(PRE_FAIL, err)
process.exit(1)
})

Expand Down
14 changes: 9 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,19 +538,23 @@ const zapAll = (map, verbose) =>
const zapAllQuiet = map => Promise.all([].concat(...[...map.values()]).map(zap))

const zapAllVerbose = map =>
recursiveZapDir([].concat([...map.entries()])).then(count =>
recursiveZapDir(map.size === 1, [].concat([...map.entries()])).then(count =>
console.log(chalk[BASE_COLOR](`${figures.pointer} ${count} files`))
)

const recursiveZapDir = (() => {
var _ref5 = asyncToGenerator(function*(entries, count = 0) {
var _ref5 = asyncToGenerator(function*(isOneDir, entries, count = 0) {
var _entries$splice$ = slicedToArray(entries.splice(0, 1)[0], 2)

const dirpath = _entries$splice$[0],
eggs = _entries$splice$[1]

if (eggs.length) {
console.log(`${dirpath}: ${chalk[BASE_COLOR](`${eggs.length} files`)}`)
console.log(
(isOneDir ? `` : `${dirpath}: `) +
chalk[BASE_COLOR](`${eggs.length} files`)
)

let countByDir = 0
yield Promise.all(
eggs.map(function(egg) {
Expand All @@ -575,10 +579,10 @@ const recursiveZapDir = (() => {
count += countByDir
}

return entries.length ? recursiveZapDir(entries, count) : count
return entries.length ? recursiveZapDir(isOneDir, entries, count) : count
})

return function recursiveZapDir(_x3) {
return function recursiveZapDir(_x3, _x4) {
return _ref5.apply(this, arguments)
}
})()
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chin",
"version": "3.1.0",
"version": "3.1.1",
"repository": "chinjs/chin",
"author": "kthjm <toxictoxer@gmail.com>",
"license": "MIT",
Expand Down Expand Up @@ -32,7 +32,6 @@
"chalk": "^2.4.1",
"chokidar": "^2.0.3",
"commander": "^2.11.0",
"consola": "^1.3.0",
"figures": "^2.0.0",
"fs-extra": "^4.0.1",
"recursive-readdir": "^2.2.1"
Expand Down
14 changes: 9 additions & 5 deletions src/bin.action.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import consola from 'consola'
import chalk from 'chalk'
import figures from 'figures'
import { require as rooquire } from 'app-root-path'
import { remove } from 'fs-extra'
import { normalize } from 'path'

export const PUT = 'assets'
export const OUT = 'public'
export const CONFIG1 = 'chin.config.js'
export const CONFIG2 = '.chin/index.js'
const PRE_INFO = chalk.blue('info')
const PRE_FAIL = chalk.red(figures.cross)

const requireModules = (requireValue) =>
requireValue
Expand All @@ -14,15 +18,15 @@ const requireModules = (requireValue) =>

const getConfig = (configValue) => {
let config

if (typeof configValue === 'string') {
config = rooquire(configValue)
} else {
try { config = rooquire(CONFIG1) }
catch (e1) {
if (!e1.message.includes(CONFIG1)) throw e1
try { config = rooquire(CONFIG2) }
catch (e2) { throw !e2.message.includes(CONFIG2) ? e2 : new Error(`Cannot find ${CONFIG1} || ${CONFIG2}`) }
catch (e2) { throw !e2.message.includes(normalize(CONFIG2)) ? e2 : new Error(`Cannot find ${CONFIG1} || ${CONFIG2}`) }
}
}

Expand All @@ -37,7 +41,7 @@ export default (program, action) => Promise.resolve()
.then(() =>
program.config
? getConfig(program.config)
: consola.info('no config')
: console.info(`${PRE_INFO} no config`)
)
.then((config = {}) =>
Array.isArray(config)
Expand All @@ -53,7 +57,7 @@ export default (program, action) => Promise.resolve()
)
.then(() => console.log(''))
.catch((err) => {
consola.error(err)
console.error(PRE_FAIL, err)
process.exit(1)
})

Expand Down
18 changes: 13 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,27 @@ const zapAll = (map, verbose) =>
: zapAllVerbose(map)

const zapAllQuiet = (map) =>
Promise.all([].concat(...[...map.values()]).map(zap))
Promise.all(
[]
.concat(...[...map.values()])
.map(zap)
)

const zapAllVerbose = (map) =>
recursiveZapDir([].concat([...map.entries()])).then(count =>
recursiveZapDir(
map.size === 1,
[].concat([...map.entries()])
).then(count =>
console.log(chalk[BASE_COLOR](`${figures.pointer} ${count} files`))
)

const recursiveZapDir = async (entries, count = 0) => {
const recursiveZapDir = async (isOneDir, entries, count = 0) => {

const [ dirpath, eggs ] = entries.splice(0, 1)[0]

if (eggs.length) {
console.log(`${dirpath}: ${chalk[BASE_COLOR](`${eggs.length} files`)}`)
console.log((isOneDir ? `` : `${dirpath}: `) + chalk[BASE_COLOR](`${eggs.length} files`))

let countByDir = 0
await Promise.all(eggs.map(egg =>
zap(egg)
Expand All @@ -66,7 +74,7 @@ const recursiveZapDir = async (entries, count = 0) => {
count += countByDir
}

return entries.length ? recursiveZapDir(entries, count) : count
return entries.length ? recursiveZapDir(isOneDir, entries, count) : count
}

export { chin, watch }
Expand Down
37 changes: 0 additions & 37 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -935,14 +935,6 @@ chalk@^2.1.0:
escape-string-regexp "^1.0.5"
supports-color "^4.0.0"

chalk@^2.3.2:
version "2.4.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.0.tgz#a060a297a6b57e15b61ca63ce84995daa0fe6e52"
dependencies:
ansi-styles "^3.2.1"
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"

chalk@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e"
Expand Down Expand Up @@ -977,10 +969,6 @@ chownr@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.0.1.tgz#e2a75042a9551908bebd25b8523d5f9769d79181"

ci-info@^1.0.0:
version "1.1.3"
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.1.3.tgz#710193264bb05c77b8c90d02f5aaf22216a667b2"

class-utils@^0.3.5:
version "0.3.6"
resolved "https://registry.yarnpkg.com/class-utils/-/class-utils-0.3.6.tgz#f93369ae8b9a7ce02fd41faad0ca83033190c463"
Expand Down Expand Up @@ -1065,15 +1053,6 @@ concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"

consola@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/consola/-/consola-1.3.0.tgz#b5effe41c4ecdce971d79268d72b8f9bde0a8c7a"
dependencies:
chalk "^2.3.2"
figures "^2.0.0"
lodash "^4.17.5"
std-env "^1.1.0"

console-control-strings@^1.0.0, console-control-strings@~1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e"
Expand Down Expand Up @@ -1940,12 +1919,6 @@ is-callable@^1.1.1, is-callable@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.3.tgz#86eb75392805ddc33af71c92a0eedf74ee7604b2"

is-ci@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-1.1.0.tgz#247e4162e7860cebbdaf30b774d6b0ac7dcfe7a5"
dependencies:
ci-info "^1.0.0"

is-data-descriptor@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/is-data-descriptor/-/is-data-descriptor-0.1.4.tgz#0b5ee648388e2c860282e793f1856fec3f301b56"
Expand Down Expand Up @@ -2327,10 +2300,6 @@ lodash@^4.17.4:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"

lodash@^4.17.5:
version "4.17.10"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"

longest@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
Expand Down Expand Up @@ -3549,12 +3518,6 @@ static-extend@^0.1.1:
define-property "^0.2.5"
object-copy "^0.1.0"

std-env@^1.1.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/std-env/-/std-env-1.3.0.tgz#8ce754a401a61f1ac49c8eb55f2a8c0c63d54954"
dependencies:
is-ci "^1.1.0"

stream-combiner@~0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/stream-combiner/-/stream-combiner-0.0.4.tgz#4d5e433c185261dde623ca3f44c586bcf5c4ad14"
Expand Down

0 comments on commit 8c9d3ba

Please sign in to comment.