Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

Commit

Permalink
logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ntwcklng committed Dec 30, 2016
1 parent 11f24ac commit 8972caf
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 148 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,8 @@ This runs the full test, including several `npm install`s. It will also lint you

`$ npm test`

#### Linting
FRAME uses xo for linting.

`$ npm run lint`

#### Builing

#### Building
`$ npm run build` will just build the `/src` folder. Running `$ npm test` will lint and build everything.


Heavily inspired by [nwb](https://github.com/insin/nwb)
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"pretest": "npm run build",
"prepublish": "npm run build",
"build": "rimraf build && babel src --out-dir build",
"dev": "rimraf build && babel src --watch --out-dir build",
"lint": "xo"
"dev": "rimraf build && babel src --watch --out-dir build"
},
"bin": {
"frame": "./build/bin/frame.js"
Expand Down
12 changes: 6 additions & 6 deletions src/bin/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ const args = parseArgs(process.argv.slice(2), {
alias: {
h: 'help',
v: 'version',
q: 'quiet'
s: 'silent'
},
boolean: ['help', 'version', 'skip-git', 'skip-install', 'quiet']
boolean: ['help', 'version', 'skip-git', 'skip-install', 'silent']
})

if (!args.quiet) {
if (!args.silent) {
console.log(boxen('FRAME v' + frameVersion, {padding: 1, margin: 1, borderStyle: 'double', borderColor: 'blue'}))
}

Expand All @@ -40,7 +40,7 @@ if (args.help) {
${chalk.dim('Options:')}
--help, -h display this
--version, -v display version
--quiet, -q ssshhhhhhh!
--silent, -s ssshhhhhhh!
--skip-git don't initialize a git repository
--skip-install don't install project dependencies
Expand All @@ -65,7 +65,7 @@ if (args.help) {
`)
process.exit(0)
}

process.title = 'FRAME'
frame(args).catch(err => {
console.log(`> ${chalk.red('Error!')} ${err.message}`)
console.log(`> ${chalk.red('Error!')} ${err.messag}`)
})
3 changes: 2 additions & 1 deletion src/create-project.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {validateOptions, copyTemplate, installAppDependencies, initGit, successfullyCreated} from './utils'
import {validateOptions, copyTemplate, installAppDependencies, initGit, successfullyCreated, log} from './utils'

export default function createProject(opts) {
opts.logger = opts.silent ? function () {} : log
return Promise.resolve()
.then(() => validateOptions(opts))
.then(() => copyTemplate(opts))
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function frame(args) {
name,
skipGit: args['skip-git'],
skipInstall: args['skip-install'],
quiet: args.quiet
silent: args.silent
}

return Promise.resolve()
Expand Down
18 changes: 9 additions & 9 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import glob from 'glob'
import ora from 'ora'
import {SUPPORTED_PROJECTS, PRINT_PROJ_TYPE, VERSIONS} from './constants'

export function log(type, msg, quiet) {
if (!quiet && msg && type) {
export function log(type, msg) {
if (msg && type) {
switch (type) {
case 'info':
console.log(`${chalk.dim(`>`)} ${msg}`)
Expand Down Expand Up @@ -52,7 +52,7 @@ export function validateOptions(opts) {
if (glob.sync(`${opts.name}/`).length !== 0) {
return reject(`A directory with the name ${chalk.bold(opts.name)} already exists`)
}
log('info', `Validated Options`, opts.quiet)
opts.logger('info', `Validated Options`)
resolve()
})
}
Expand All @@ -66,7 +66,7 @@ export function copyTemplate(opts) {
if (err) {
return reject(err)
}
log('info', `Copied template to ${path.resolve(targetDir)}`, opts.quiet)
opts.logger('info', `Copied template to ${path.resolve(targetDir)}`)
resolve()
})
})
Expand All @@ -85,7 +85,7 @@ export function installAppDependencies(opts) {
return reject(err)
}
spinner.stop()
log('info', `Installed ${PRINT_PROJ_TYPE[opts.type]} dependencies`, opts.quiet)
opts.logger('info', `Installed ${PRINT_PROJ_TYPE[opts.type]} dependencies`)
resolve()
})
})
Expand All @@ -102,21 +102,21 @@ export function initGit(opts) {
} catch (err) {
return reject(err)
}
log('info', `Initialized a git repository`, opts.quiet)
opts.logger('info', `Initialized a git repository`)
resolve()
})
}

export function successfullyCreated(opts) {
const npmInstall = opts.skipInstall ? ' && npm install ' : ' '
log('info', chalk.green(`Successfully created a new ${chalk.bold(PRINT_PROJ_TYPE[opts.type])} Project`), opts.quiet)
log('normal', `
opts.logger('info', chalk.green(`Successfully created a new ${chalk.bold(PRINT_PROJ_TYPE[opts.type])} Project`))
opts.logger('normal', `
${chalk.dim('To get started run:')}
${chalk.cyan(`$ cd ${opts.name}${npmInstall}&& npm run dev`)}
${chalk.dim('Your new Project is then available @ http://localhost:3000')}
`, opts.quiet)
`)

return opts
}
6 changes: 3 additions & 3 deletions test/create-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test.before(() => {

test('create a new react project without errors', async t => {
const tmpDir = 'tmp-react'
await cli({_: ['react', tmpDir], 'skip-git': true, 'skip-install': true, quiet: true}).then(proj => {
await cli({_: ['react', tmpDir], 'skip-git': true, 'skip-install': true, silent: true}).then(proj => {
const pkg = require(path.resolve(process.cwd(), `./${tmpDir}/package.json`))
t.is(pkg.dependencies.react, VERSIONS[proj.type])
t.is(proj.name, tmpDir)
Expand All @@ -28,7 +28,7 @@ test('create a new react project without errors', async t => {

test('create a new preact project without errors', async t => {
const tmpDir = 'tmp-preact'
await cli({_: ['preact', tmpDir], 'skip-git': true, 'skip-install': true, quiet: true}).then(proj => {
await cli({_: ['preact', tmpDir], 'skip-git': true, 'skip-install': true, silent: true}).then(proj => {
const pkg = require(path.resolve(process.cwd(), `./${tmpDir}/package.json`))
t.is(pkg.dependencies.preact, VERSIONS[proj.type])
t.is(proj.name, tmpDir)
Expand All @@ -38,7 +38,7 @@ test('create a new preact project without errors', async t => {

test('create a new Next.js project without errors', async t => {
const tmpDir = 'tmp-next'
await cli({_: ['next', tmpDir], 'skip-git': true, 'skip-install': true, quiet: true}).then(proj => {
await cli({_: ['next', tmpDir], 'skip-git': true, 'skip-install': true, silent: true}).then(proj => {
const pkg = require(path.resolve(process.cwd(), `./${tmpDir}/package.json`))
t.is(pkg.dependencies.next, VERSIONS[proj.type])
t.is(proj.name, tmpDir)
Expand Down
Loading

0 comments on commit 8972caf

Please sign in to comment.