Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Commit

Permalink
Run prettier on src and test js files
Browse files Browse the repository at this point in the history
  • Loading branch information
Benaiah committed Mar 14, 2019
1 parent f5c43e1 commit 4416a12
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 45 deletions.
18 changes: 9 additions & 9 deletions src/commands/functions/build.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const fs = require('fs')
const {flags} = require('@oclif/command')
const { flags } = require('@oclif/command')
const Command = require('@netlify/cli-utils')
const {zipFunctions} = require('@netlify/zip-it-and-ship-it')
const { zipFunctions } = require('@netlify/zip-it-and-ship-it')

class FunctionsBuildCommand extends Command {
async run() {
const {flags, args} = this.parse(FunctionsBuildCommand)
const {config} = this.netlify
const { flags, args } = this.parse(FunctionsBuildCommand)
const { config } = this.netlify

const src = flags.src || config.build.functionsSource
const dst = flags.functions || config.build.functions
Expand All @@ -26,10 +26,10 @@ class FunctionsBuildCommand extends Command {
process.exit(1)
}

fs.mkdirSync(dst, {recursive: true})
fs.mkdirSync(dst, { recursive: true })

this.log('Building functions')
zipFunctions(src, dst, {skipGo: true})
zipFunctions(src, dst, { skipGo: true })
this.log('Functions buildt to ', dst)
}
}
Expand All @@ -40,12 +40,12 @@ FunctionsBuildCommand.description = `build functions locally
FunctionsBuildCommand.flags = {
functions: flags.string({
char: 'f',
description: 'Specify a functions folder to build to',
description: 'Specify a functions folder to build to'
}),
src: flags.string({
char: 's',
description: 'Specify the source folder for the functions',
}),
description: 'Specify the source folder for the functions'
})
}

module.exports = FunctionsBuildCommand
45 changes: 15 additions & 30 deletions src/commands/functions/create.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs')
const path = require('path')
const {flags} = require('@oclif/command')
const { flags } = require('@oclif/command')
const Command = require('@netlify/cli-utils')

const template = `async function hello() {
Expand All @@ -19,76 +19,61 @@ exports.handler = async function(event, context) {

class FunctionsCreateCommand extends Command {
async run() {
const {flags, args} = this.parse(FunctionsCreateCommand)
const {name} = args
const {config} = this.netlify
const { flags, args } = this.parse(FunctionsCreateCommand)
const { name } = args
const { config } = this.netlify

this.log(`Creating function ${name}`)

const functionsDir =
flags.functions || (config.build && config.build.functions)
const functionsDir = flags.functions || (config.build && config.build.functions)
if (!functionsDir) {
this.log(
'No functions folder specified in netlify.toml or as an argument'
)
this.log('No functions folder specified in netlify.toml or as an argument')
process.exit(1)
}

if (!fs.existsSync(functionsDir)) {
fs.mkdir(functionsDir)
}

const functionPath = flags.dir ?
path.join(functionsDir, name, name + '.js') :
path.join(functionsDir, name + '.js')
const functionPath = flags.dir ? path.join(functionsDir, name, name + '.js') : path.join(functionsDir, name + '.js')
if (fs.existsSync(functionPath)) {
this.log(`Function ${functionPath} already exists`)
process.exit(1)
}

if (flags.dir) {
const fnFolder = path.join(functionsDir, name)
if (
fs.existsSync(fnFolder + '.js') &&
fs.lstatSync(fnFolder + '.js').isFile()
) {
this.log(
`A single file version of the function ${name} already exists at ${fnFolder}.js`
)
if (fs.existsSync(fnFolder + '.js') && fs.lstatSync(fnFolder + '.js').isFile()) {
this.log(`A single file version of the function ${name} already exists at ${fnFolder}.js`)
process.exit(1)
}

try {
fs.mkdirSync(fnFolder, {recursive: true})
fs.mkdirSync(fnFolder, { recursive: true })
} catch (e) {
// Ignore
}
} else if (fs.existsSync(functionPath.replace(/\.js/, ''))) {
this.log(
`A folder version of the function ${name} alreadt exists at ${functionPath.replace(
/\.js/,
''
)}`
)
this.log(`A folder version of the function ${name} alreadt exists at ${functionPath.replace(/\.js/, '')}`)
process.exit(1)
}

fs.writeFileSync(functionPath, template)
}
}

FunctionsCreateCommand.args = [{name: 'name'}]
FunctionsCreateCommand.args = [{ name: 'name' }]

FunctionsCreateCommand.description = `create a new function locally
`

FunctionsCreateCommand.examples = ['netlify functions:create hello-world']

FunctionsCreateCommand.flags = {
functions: flags.string({char: 'f', description: 'functions folder'}),
functions: flags.string({ char: 'f', description: 'functions folder' }),
dir: flags.boolean({
char: 'd',
description: 'create function as a directory',
}),
description: 'create function as a directory'
})
}
module.exports = FunctionsCreateCommand
8 changes: 4 additions & 4 deletions src/commands/functions/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const chalk = require('chalk')
const {Command} = require('@oclif/command')
const { Command } = require('@oclif/command')

function showHelp(command) {
execSync(`netlify ${command} --help`, {stdio: [0, 1, 2]})
execSync(`netlify ${command} --help`, { stdio: [0, 1, 2] })
}

function isEmptyCommand(flags, args) {
Expand All @@ -22,7 +22,7 @@ function hasArgs(args) {

class FunctionsCommand extends Command {
async run() {
const {flags, args} = this.parse(FunctionsCommand)
const { flags, args } = this.parse(FunctionsCommand)
// run help command if no args passed
if (isEmptyCommand(flags, args)) {
showHelp(this.id)
Expand All @@ -38,7 +38,7 @@ The ${name} command will help you manage the functions in this site
`
FunctionsCommand.examples = [
'netlify functions:create --name function-xyz --runtime nodejs',
'netlify functions:update --name function-abc --timeout 30s',
'netlify functions:update --name function-abc --timeout 30s'
]

// TODO make visible once implementation complete
Expand Down
2 changes: 1 addition & 1 deletion src/commands/functions/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Extra documentation goes here
`

FunctionsServeCommand.flags = {
name: flags.string({char: 'n', description: 'name to print'}),
name: flags.string({ char: 'n', description: 'name to print' })
}

// TODO make visible once implementation complete
Expand Down
2 changes: 1 addition & 1 deletion src/commands/functions/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Extra documentation goes here
`

FunctionsUpdateCommand.flags = {
name: flags.string({char: 'n', description: 'name to print'}),
name: flags.string({ char: 'n', description: 'name to print' })
}

// TODO make visible once implementation complete
Expand Down

0 comments on commit 4416a12

Please sign in to comment.