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

Commit 5c76812

Browse files
committed
Run prettier on src and test js files
1 parent 4adca69 commit 5c76812

File tree

6 files changed

+68
-92
lines changed

6 files changed

+68
-92
lines changed

src/commands/dev/index.js

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
const {flags} = require('@oclif/command')
2-
const {spawn} = require('child_process')
1+
const { flags } = require('@oclif/command')
2+
const { spawn } = require('child_process')
33
const http = require('http')
44
const httpProxy = require('http-proxy')
55
const waitPort = require('wait-port')
66
const getPort = require('get-port')
7-
const {serveFunctions} = require('@netlify/zip-it-and-ship-it')
8-
const {serverSettings} = require('../../detect-server')
7+
const { serveFunctions } = require('@netlify/zip-it-and-ship-it')
8+
const { serverSettings } = require('../../detect-server')
99
const Command = require('@netlify/cli-utils')
10-
const {getAddons} = require('netlify/src/addons')
10+
const { getAddons } = require('netlify/src/addons')
1111

1212
function cleanExit() {
1313
process.exit()
@@ -26,47 +26,45 @@ function addonUrl(addonUrls, req) {
2626
async function startProxy(settings, addonUrls) {
2727
const rulesProxy = require('netlify-rules-proxy')
2828

29-
await waitPort({port: settings.proxyPort})
29+
await waitPort({ port: settings.proxyPort })
3030
if (settings.functionsPort) {
31-
await waitPort({port: settings.functionsPort})
31+
await waitPort({ port: settings.functionsPort })
3232
}
33-
const port = await getPort({port: settings.port})
34-
const functionsServer = settings.functionsPort ?
35-
`http://localhost:${settings.functionsPort}` :
36-
null
33+
const port = await getPort({ port: settings.port })
34+
const functionsServer = settings.functionsPort ? `http://localhost:${settings.functionsPort}` : null
3735

3836
const proxy = httpProxy.createProxyServer({
3937
target: {
4038
host: 'localhost',
41-
port: settings.proxyPort,
42-
},
39+
port: settings.proxyPort
40+
}
4341
})
4442

45-
const rewriter = rulesProxy({publicFolder: settings.dist})
43+
const rewriter = rulesProxy({ publicFolder: settings.dist })
4644

47-
const server = http.createServer(function (req, res) {
45+
const server = http.createServer(function(req, res) {
4846
if (isFunction(settings, req)) {
49-
return proxy.web(req, res, {target: functionsServer})
47+
return proxy.web(req, res, { target: functionsServer })
5048
}
5149
let url = addonUrl(addonUrls, req)
5250
if (url) {
53-
return proxy.web(req, res, {target: url})
51+
return proxy.web(req, res, { target: url })
5452
}
5553

5654
rewriter(req, res, () => {
5755
if (isFunction(settings, req)) {
58-
return proxy.web(req, res, {target: functionsServer})
56+
return proxy.web(req, res, { target: functionsServer })
5957
}
6058
url = addonUrl(addonUrls, req)
6159
if (url) {
62-
return proxy.web(req, res, {target: url})
60+
return proxy.web(req, res, { target: url })
6361
}
6462

65-
proxy.web(req, res, {target: `http://localhost:${settings.proxyPort}`})
63+
proxy.web(req, res, { target: `http://localhost:${settings.proxyPort}` })
6664
})
6765
})
6866

69-
server.on('upgrade', function (req, socket, head) {
67+
server.on('upgrade', function(req, socket, head) {
7068
proxy.ws(req, socket, head)
7169
})
7270

@@ -82,17 +80,17 @@ function startDevServer(settings, log, error) {
8280
name: 'netlify-dev',
8381
port: settings.proxyPort,
8482
templates: {
85-
notFound: '404.html',
86-
},
83+
notFound: '404.html'
84+
}
8785
})
8886

89-
server.start(function () {
87+
server.start(function() {
9088
log('Server listening to', settings.proxyPort)
9189
})
9290
return
9391
}
9492

95-
const ps = spawn(settings.cmd, settings.args, {env: settings.env})
93+
const ps = spawn(settings.cmd, settings.args, { env: settings.env })
9694

9795
ps.stdout.on('data', data => {
9896
log(`${data}`.replace(settings.urlRegexp, `$1$2${settings.port}$3`))
@@ -112,24 +110,21 @@ function startDevServer(settings, log, error) {
112110

113111
class DevCommand extends Command {
114112
async run() {
115-
const {flags, args} = this.parse(DevCommand)
116-
const {api, site, config} = this.netlify
117-
const functionsDir =
118-
flags.functions || (config.build && config.build.functions)
113+
const { flags, args } = this.parse(DevCommand)
114+
const { api, site, config } = this.netlify
115+
const functionsDir = flags.functions || (config.build && config.build.functions)
119116
const addonUrls = {}
120117
if (site.id && !flags.offline) {
121118
const accessToken = await this.authenticate()
122119
const addons = await getAddons(site.id, accessToken)
123120
addons.forEach(addon => {
124-
addonUrls[addon.slug] = `${addon.config.site_url}/.netlify/${
125-
addon.slug
126-
}`
121+
addonUrls[addon.slug] = `${addon.config.site_url}/.netlify/${addon.slug}`
127122
for (const key in addon.env) {
128123
process.env[key] = process.env[key] || addon.env[key]
129124
}
130125
})
131126
const api = this.netlify.api
132-
const apiSite = await api.getSite({site_id: site.id})
127+
const apiSite = await api.getSite({ site_id: site.id })
133128
// TODO: We should move the environment outside of build settings and possibly have a
134129
// `/api/v1/sites/:site_id/environment` endpoint for it that we can also gate access to
135130
// In the future and that we could make context dependend
@@ -147,12 +142,12 @@ class DevCommand extends Command {
147142
noCmd: true,
148143
port: 8888,
149144
proxyPort: 3999,
150-
dist: config.build && config.build.publish,
145+
dist: config.build && config.build.publish
151146
}
152147
}
153148
startDevServer(settings, this.log, this.error)
154149
if (functionsDir) {
155-
const fnSettings = await serveFunctions({functionsDir})
150+
const fnSettings = await serveFunctions({ functionsDir })
156151
settings.functionsPort = fnSettings.port
157152
}
158153

@@ -165,30 +160,26 @@ DevCommand.description = `Local dev server
165160
The dev command will run a local dev server with Netlify's proxy and redirect rules
166161
`
167162

168-
DevCommand.examples = [
169-
'$ netlify dev',
170-
'$ netlify dev -c "yarn start"',
171-
'$ netlify dev -c hugo',
172-
]
163+
DevCommand.examples = ['$ netlify dev', '$ netlify dev -c "yarn start"', '$ netlify dev -c hugo']
173164

174165
DevCommand.strict = false
175166

176167
DevCommand.flags = {
177-
cmd: flags.string({char: 'c', description: 'command to run'}),
168+
cmd: flags.string({ char: 'c', description: 'command to run' }),
178169
devport: flags.integer({
179170
char: 'd',
180-
description: 'port of the dev server started by command',
171+
description: 'port of the dev server started by command'
181172
}),
182-
port: flags.integer({char: 'p', description: 'port of netlify dev'}),
183-
dir: flags.integer({char: 'd', description: 'dir with static files'}),
173+
port: flags.integer({ char: 'p', description: 'port of netlify dev' }),
174+
dir: flags.integer({ char: 'd', description: 'dir with static files' }),
184175
functions: flags.string({
185176
char: 'f',
186-
description: 'Specify a functions folder to serve',
177+
description: 'Specify a functions folder to serve'
187178
}),
188179
offline: flags.boolean({
189180
char: 'o',
190-
description: 'disables any features that require network access',
191-
}),
181+
description: 'disables any features that require network access'
182+
})
192183
}
193184

194185
module.exports = DevCommand

src/commands/functions/build.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const fs = require('fs')
2-
const {flags} = require('@oclif/command')
2+
const { flags } = require('@oclif/command')
33
const Command = require('@netlify/cli-utils')
4-
const {zipFunctions} = require('@netlify/zip-it-and-ship-it')
4+
const { zipFunctions } = require('@netlify/zip-it-and-ship-it')
55

66
class FunctionsBuildCommand extends Command {
77
async run() {
8-
const {flags, args} = this.parse(FunctionsBuildCommand)
9-
const {config} = this.netlify
8+
const { flags, args } = this.parse(FunctionsBuildCommand)
9+
const { config } = this.netlify
1010

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

29-
fs.mkdirSync(dst, {recursive: true})
29+
fs.mkdirSync(dst, { recursive: true })
3030

3131
this.log('Building functions')
32-
zipFunctions(src, dst, {skipGo: true})
32+
zipFunctions(src, dst, { skipGo: true })
3333
this.log('Functions buildt to ', dst)
3434
}
3535
}
@@ -40,12 +40,12 @@ FunctionsBuildCommand.description = `build functions locally
4040
FunctionsBuildCommand.flags = {
4141
functions: flags.string({
4242
char: 'f',
43-
description: 'Specify a functions folder to build to',
43+
description: 'Specify a functions folder to build to'
4444
}),
4545
src: flags.string({
4646
char: 's',
47-
description: 'Specify the source folder for the functions',
48-
}),
47+
description: 'Specify the source folder for the functions'
48+
})
4949
}
5050

5151
module.exports = FunctionsBuildCommand

src/commands/functions/create.js

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require('fs')
22
const path = require('path')
3-
const {flags} = require('@oclif/command')
3+
const { flags } = require('@oclif/command')
44
const Command = require('@netlify/cli-utils')
55

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

2020
class FunctionsCreateCommand extends Command {
2121
async run() {
22-
const {flags, args} = this.parse(FunctionsCreateCommand)
23-
const {name} = args
24-
const {config} = this.netlify
22+
const { flags, args } = this.parse(FunctionsCreateCommand)
23+
const { name } = args
24+
const { config } = this.netlify
2525

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

28-
const functionsDir =
29-
flags.functions || (config.build && config.build.functions)
28+
const functionsDir = flags.functions || (config.build && config.build.functions)
3029
if (!functionsDir) {
31-
this.log(
32-
'No functions folder specified in netlify.toml or as an argument'
33-
)
30+
this.log('No functions folder specified in netlify.toml or as an argument')
3431
process.exit(1)
3532
}
3633

3734
if (!fs.existsSync(functionsDir)) {
3835
fs.mkdir(functionsDir)
3936
}
4037

41-
const functionPath = flags.dir ?
42-
path.join(functionsDir, name, name + '.js') :
43-
path.join(functionsDir, name + '.js')
38+
const functionPath = flags.dir ? path.join(functionsDir, name, name + '.js') : path.join(functionsDir, name + '.js')
4439
if (fs.existsSync(functionPath)) {
4540
this.log(`Function ${functionPath} already exists`)
4641
process.exit(1)
4742
}
4843

4944
if (flags.dir) {
5045
const fnFolder = path.join(functionsDir, name)
51-
if (
52-
fs.existsSync(fnFolder + '.js') &&
53-
fs.lstatSync(fnFolder + '.js').isFile()
54-
) {
55-
this.log(
56-
`A single file version of the function ${name} already exists at ${fnFolder}.js`
57-
)
46+
if (fs.existsSync(fnFolder + '.js') && fs.lstatSync(fnFolder + '.js').isFile()) {
47+
this.log(`A single file version of the function ${name} already exists at ${fnFolder}.js`)
5848
process.exit(1)
5949
}
6050

6151
try {
62-
fs.mkdirSync(fnFolder, {recursive: true})
52+
fs.mkdirSync(fnFolder, { recursive: true })
6353
} catch (e) {
6454
// Ignore
6555
}
6656
} else if (fs.existsSync(functionPath.replace(/\.js/, ''))) {
67-
this.log(
68-
`A folder version of the function ${name} alreadt exists at ${functionPath.replace(
69-
/\.js/,
70-
''
71-
)}`
72-
)
57+
this.log(`A folder version of the function ${name} alreadt exists at ${functionPath.replace(/\.js/, '')}`)
7358
process.exit(1)
7459
}
7560

7661
fs.writeFileSync(functionPath, template)
7762
}
7863
}
7964

80-
FunctionsCreateCommand.args = [{name: 'name'}]
65+
FunctionsCreateCommand.args = [{ name: 'name' }]
8166

8267
FunctionsCreateCommand.description = `create a new function locally
8368
`
8469

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

8772
FunctionsCreateCommand.flags = {
88-
functions: flags.string({char: 'f', description: 'functions folder'}),
73+
functions: flags.string({ char: 'f', description: 'functions folder' }),
8974
dir: flags.boolean({
9075
char: 'd',
91-
description: 'create function as a directory',
92-
}),
76+
description: 'create function as a directory'
77+
})
9378
}
9479
module.exports = FunctionsCreateCommand

src/commands/functions/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const chalk = require('chalk')
2-
const {Command} = require('@oclif/command')
2+
const { Command } = require('@oclif/command')
33

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

88
function isEmptyCommand(flags, args) {
@@ -22,7 +22,7 @@ function hasArgs(args) {
2222

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

4444
// TODO make visible once implementation complete

src/commands/functions/serve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Extra documentation goes here
1212
`
1313

1414
FunctionsServeCommand.flags = {
15-
name: flags.string({char: 'n', description: 'name to print'}),
15+
name: flags.string({ char: 'n', description: 'name to print' })
1616
}
1717

1818
// TODO make visible once implementation complete

src/commands/functions/update.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Extra documentation goes here
1212
`
1313

1414
FunctionsUpdateCommand.flags = {
15-
name: flags.string({char: 'n', description: 'name to print'}),
15+
name: flags.string({ char: 'n', description: 'name to print' })
1616
}
1717

1818
// TODO make visible once implementation complete

0 commit comments

Comments
 (0)