Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: enable and fix class-methods-use-this #2827

Merged
merged 26 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
accd95c
refactor: enable and fix class-methods-use-this
tinfoil-knight Jul 3, 2021
638bb45
Merge branch 'main' into 1891-class-methods
tinfoil-knight Jul 5, 2021
d2ec3ab
refactor: prettier newline lint
tinfoil-knight Jul 5, 2021
379003c
Merge branch 'main' into 1891-class-methods
erezrokah Jul 7, 2021
2ab47ef
Merge branch 'main' into 1891-class-methods
erezrokah Jul 7, 2021
6b5c4c9
refactor: replace getConfigToken with getToken
tinfoil-knight Jul 7, 2021
1f804f7
refactor: token and log functions separated from base Command class
tinfoil-knight Jul 12, 2021
8a43cad
fix: merge conflict
tinfoil-knight Jul 12, 2021
2983cbd
fix: pass correct log to FunctionRegistry, fix import in link.js
tinfoil-knight Jul 12, 2021
1d4d5bc
Merge branch 'main' into 1891-class-methods
erezrokah Jul 13, 2021
d720ec8
fix: merge conflict
tinfoil-knight Jul 13, 2021
712c66a
refactor: remove log from detectServerSettings
tinfoil-knight Jul 13, 2021
c5dea0f
Merge branch 'main' into 1891-class-methods
erezrokah Jul 14, 2021
a18b9a4
Merge branch 'main' into 1891-class-methods
erezrokah Jul 14, 2021
789d897
refactor: extract more utils
erezrokah Jul 14, 2021
cc55928
Merge branch 'main' into 1891-class-methods
erezrokah Jul 14, 2021
4c0a43c
Merge branch 'main' into 1891-class-methods
erezrokah Jul 15, 2021
982b6af
style: run formatter
erezrokah Jul 15, 2021
39f311c
fix: merge conflict due to log parameter
tinfoil-knight Jul 21, 2021
b8dff96
Merge branch 'main' into 1891-class-methods
erezrokah Jul 25, 2021
d9b612f
refactor: use log instead of console.log
erezrokah Jul 25, 2021
9bdd9ca
chore: fix linting
erezrokah Jul 25, 2021
92790ca
refactor: update comment
erezrokah Jul 25, 2021
e968e06
refactor: remove dead code
erezrokah Jul 25, 2021
f296efa
refactor: switch from static method to top level function
erezrokah Jul 25, 2021
eccfc5f
Merge branch 'main' into 1891-class-methods
erezrokah Jul 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module.exports = {
rules: {
// Those rules from @netlify/eslint-config-node are currently disabled
// TODO: remove, so those rules are enabled
'class-methods-use-this': 0,
complexity: 0,
'max-depth': 0,
'max-lines': 0,
Expand Down
13 changes: 7 additions & 6 deletions src/commands/addons/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { prepareAddonCommand, ADDON_VALIDATION } = require('../../utils/addons/prepare')
const Command = require('../../utils/command')
const { log } = require('../../utils/command-helpers')
const openBrowser = require('../../utils/open-browser')

class AddonsAuthCommand extends Command {
Expand All @@ -18,12 +19,12 @@ class AddonsAuthCommand extends Command {
return false
}

this.log()
this.log(`Opening ${addonName} add-on admin URL:`)
this.log()
this.log(addon.auth_url)
this.log()
await openBrowser({ url: addon.auth_url, log: this.log })
log()
log(`Opening ${addonName} add-on admin URL:`)
log()
log(addon.auth_url)
log()
await openBrowser({ url: addon.auth_url })
this.exit()
}
}
Expand Down
41 changes: 20 additions & 21 deletions src/commands/addons/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const generatePrompts = require('../../utils/addons/prompts')
const render = require('../../utils/addons/render')
const { requiredConfigValues, missingConfigValues, updateConfigValues } = require('../../utils/addons/validation')
const Command = require('../../utils/command')
const { log } = require('../../utils/command-helpers')
const { parseRawFlags } = require('../../utils/parse-raw-flags')

class AddonsConfigCommand extends Command {
Expand All @@ -33,15 +34,15 @@ class AddonsConfigCommand extends Command {
const currentConfig = addon.config || {}

const words = `Current "${addonName} add-on" Settings:`
this.log(` ${chalk.yellowBright.bold(words)}`)
log(` ${chalk.yellowBright.bold(words)}`)
if (hasConfig) {
if (!rawFlags.silent) {
render.configValues(addonName, manifest.config, currentConfig)
}
} else {
// For addons without manifest. TODO remove once we enfore manifests
Object.keys(currentConfig).forEach((key) => {
this.log(`${key} - ${currentConfig[key]}`)
log(`${key} - ${currentConfig[key]}`)
})
}

Expand All @@ -61,7 +62,6 @@ class AddonsConfigCommand extends Command {
instanceId: addon.id,
api,
error: this.error,
log: this.log,
})
return false
}
Expand All @@ -75,16 +75,16 @@ class AddonsConfigCommand extends Command {
},
])
if (!updatePrompt.updateNow) {
this.log('Sounds good! Exiting configuration...')
log('Sounds good! Exiting configuration...')
return false
}
this.log()
this.log(` - Hit ${chalk.white.bold('enter')} to keep the existing value in (parentheses)`)
this.log(` - Hit ${chalk.white.bold('down arrow')} to remove the value`)
this.log(` - Hit ${chalk.white.bold('ctrl + C')} to cancel & exit configuration`)
this.log()
this.log(` You will need to verify the changed before we push them to your live site!`)
this.log()
log()
log(` - Hit ${chalk.white.bold('enter')} to keep the existing value in (parentheses)`)
log(` - Hit ${chalk.white.bold('down arrow')} to remove the value`)
log(` - Hit ${chalk.white.bold('ctrl + C')} to cancel & exit configuration`)
log()
log(` You will need to verify the changed before we push them to your live site!`)
log()
const prompts = generatePrompts({
config: manifest.config,
configValues: currentConfig,
Expand All @@ -94,20 +94,20 @@ class AddonsConfigCommand extends Command {
const newConfig = updateConfigValues(manifest.config, currentConfig, userInput)

const diffs = compare(currentConfig, newConfig)
// this.log('compare', diffs)
// log('compare', diffs)
if (diffs.isEqual) {
this.log(`No changes. exiting early`)
log(`No changes. exiting early`)
return false
}
this.log()
this.log(`${chalk.yellowBright.bold.underline('Confirm your updates:')}`)
this.log()
log()
log(`${chalk.yellowBright.bold.underline('Confirm your updates:')}`)
log()
diffs.keys.forEach((key) => {
const { newValue, oldValue } = diffs.diffs[key]
const oldVal = oldValue || 'NO VALUE'
this.log(`${chalk.cyan(key)} changed from ${chalk.whiteBright(oldVal)} to ${chalk.green(newValue)}`)
log(`${chalk.cyan(key)} changed from ${chalk.whiteBright(oldVal)} to ${chalk.green(newValue)}`)
})
this.log()
log()

const confirmPrompt = await inquirer.prompt([
{
Expand All @@ -121,7 +121,7 @@ class AddonsConfigCommand extends Command {
])

if (!confirmPrompt.confirmChange) {
this.log('Canceling changes... You are good to go!')
log('Canceling changes... You are good to go!')
return false
}

Expand All @@ -133,13 +133,12 @@ class AddonsConfigCommand extends Command {
instanceId: addon.id,
api,
error: this.error,
log: this.log,
})
}
}
}

const update = async function ({ addonName, currentConfig, newConfig, siteId, instanceId, api, error, log }) {
const update = async function ({ addonName, currentConfig, newConfig, siteId, instanceId, api, error }) {
const codeDiff = diffValues(currentConfig, newConfig)
if (!codeDiff) {
log('No changes, exiting early')
Expand Down
45 changes: 22 additions & 23 deletions src/commands/addons/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ const generatePrompts = require('../../utils/addons/prompts')
const render = require('../../utils/addons/render')
const { requiredConfigValues, missingConfigValues, updateConfigValues } = require('../../utils/addons/validation')
const Command = require('../../utils/command')
const { log } = require('../../utils/command-helpers')
const { parseRawFlags } = require('../../utils/parse-raw-flags')

const createAddon = async ({ api, siteId, addonName, config, siteData, log, error }) => {
const createAddon = async ({ api, siteId, addonName, config, siteData, error }) => {
try {
const response = await api.createServiceInstance({
siteId,
Expand Down Expand Up @@ -37,7 +38,7 @@ class AddonsCreateCommand extends Command {
validation: ADDON_VALIDATION.NOT_EXISTS,
})

const { log, error, netlify } = this
const { error, netlify } = this
const { api, site } = netlify
const siteId = site.id

Expand All @@ -50,43 +51,41 @@ class AddonsCreateCommand extends Command {
if (hasConfig) {
const required = requiredConfigValues(manifest.config)
const missingValues = missingConfigValues(required, rawFlags)
this.log(`Starting the setup for "${addonName} add-on"`)
this.log()
log(`Starting the setup for "${addonName} add-on"`)
log()

if (Object.keys(rawFlags).length !== 0) {
const newConfig = updateConfigValues(manifest.config, {}, rawFlags)

if (missingValues.length !== 0) {
/* Warn user of missing required values */
this.log(
`${chalk.redBright.underline.bold(`Error: Missing required configuration for "${addonName} add-on"`)}`,
)
this.log()
log(`${chalk.redBright.underline.bold(`Error: Missing required configuration for "${addonName} add-on"`)}`)
log()
render.missingValues(missingValues, manifest)
this.log()
log()
const msg = `netlify addons:create ${addonName}`
this.log(`Please supply the configuration values as CLI flags`)
this.log()
this.log(`Alternatively, you can run ${chalk.cyan(msg)} with no flags to walk through the setup steps`)
this.log()
log(`Please supply the configuration values as CLI flags`)
log()
log(`Alternatively, you can run ${chalk.cyan(msg)} with no flags to walk through the setup steps`)
log()
return false
}

await createAddon({ api, siteId, addonName, config: newConfig, siteData, log, error })
await createAddon({ api, siteId, addonName, config: newConfig, siteData, error })

return false
}

const words = `The ${addonName} add-on has the following configurable options:`
this.log(` ${chalk.yellowBright.bold(words)}`)
log(` ${chalk.yellowBright.bold(words)}`)
render.configValues(addonName, manifest.config)
this.log()
this.log(` ${chalk.greenBright.bold('Lets configure those!')}`)
log()
log(` ${chalk.greenBright.bold('Lets configure those!')}`)

this.log()
this.log(` - Hit ${chalk.white.bold('enter')} to confirm value or set empty value`)
this.log(` - Hit ${chalk.white.bold('ctrl + C')} to cancel & exit configuration`)
this.log()
log()
log(` - Hit ${chalk.white.bold('enter')} to confirm value or set empty value`)
log(` - Hit ${chalk.white.bold('ctrl + C')} to cancel & exit configuration`)
log()

const prompts = generatePrompts({
config: manifest.config,
Expand All @@ -99,13 +98,13 @@ class AddonsCreateCommand extends Command {
const missingRequiredValues = missingConfigValues(required, configValues)
if (missingRequiredValues && missingRequiredValues.length !== 0) {
missingRequiredValues.forEach((val) => {
this.log(`Missing required value "${val}". Please run the command again`)
log(`Missing required value "${val}". Please run the command again`)
})
return false
}
}

await createAddon({ api, siteId, addonName, config: configValues, siteData, log, error })
await createAddon({ api, siteId, addonName, config: configValues, siteData, error })
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/commands/addons/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const inquirer = require('inquirer')

const { prepareAddonCommand, ADDON_VALIDATION } = require('../../utils/addons/prepare')
const Command = require('../../utils/command')
const { log } = require('../../utils/command-helpers')
const { parseRawFlags } = require('../../utils/parse-raw-flags')

class AddonsDeleteCommand extends Command {
Expand Down Expand Up @@ -35,7 +36,7 @@ class AddonsDeleteCommand extends Command {
addon: addonName,
instanceId: addon.id,
})
this.log(`Addon "${addonName}" deleted`)
log(`Addon "${addonName}" deleted`)
} catch (error) {
this.error(error.message)
}
Expand Down
12 changes: 6 additions & 6 deletions src/commands/addons/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ const AsciiTable = require('ascii-table')

const { prepareAddonCommand } = require('../../utils/addons/prepare')
const Command = require('../../utils/command')
const { log, logJson } = require('../../utils/command-helpers')

class AddonsListCommand extends Command {
async run() {
const { flags } = this.parse(AddonsListCommand)

const { addons, siteData } = await prepareAddonCommand({ context: this })

// Return json response for piping commands
if (flags.json) {
this.logJson(addons)
logJson(addons)
return false
}

if (!addons || addons.length === 0) {
this.log(`No addons currently installed for ${siteData.name}`)
this.log(`> Run \`netlify addons:create addon-namespace\` to install an addon`)
log(`No addons currently installed for ${siteData.name}`)
log(`> Run \`netlify addons:create addon-namespace\` to install an addon`)
return false
}

Expand All @@ -29,7 +29,7 @@ class AddonsListCommand extends Command {
}))

// Build a table out of addons
this.log(`site: ${siteData.name}`)
log(`site: ${siteData.name}`)
const table = new AsciiTable(`Currently Installed addons`)

table.setHeading('NameSpace', 'Name', 'Instance Id')
Expand All @@ -38,7 +38,7 @@ class AddonsListCommand extends Command {
table.addRow(namespace, name, id)
})
// Log da addons
this.log(table.toString())
log(table.toString())
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/commands/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { methods } = require('netlify')

const { isEmptyCommand } = require('../utils/check-command-inputs')
const Command = require('../utils/command')
const { log, logJson } = require('../utils/command-helpers')

class APICommand extends Command {
async run() {
Expand All @@ -20,10 +21,10 @@ class APICommand extends Command {
const { operationId } = method
table.addRow(operationId, `https://open-api.netlify.com/#operation/${operationId}`)
})
this.log(table.toString())
this.log()
this.log('Above is a list of available API methods')
this.log(`To run a method use "${chalk.cyanBright('netlify api methodName')}"`)
log(table.toString())
log()
log('Above is a list of available API methods')
log(`To run a method use "${chalk.cyanBright('netlify api methodName')}"`)
this.exit()
}

Expand All @@ -43,7 +44,7 @@ class APICommand extends Command {
}
try {
const apiResponse = await api[apiMethod](payload)
this.logJson(apiResponse)
logJson(apiResponse)
} catch (error) {
this.error(error)
}
Expand Down
3 changes: 2 additions & 1 deletion src/commands/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { flags: flagsLib } = require('@oclif/command')

const { getBuildOptions, runBuild } = require('../../lib/build')
const Command = require('../../utils/command')
const { getToken } = require('../../utils/command-helpers')

class BuildCommand extends Command {
// Run Netlify Build
Expand All @@ -11,7 +12,7 @@ class BuildCommand extends Command {
this.setAnalyticsPayload({ dry: flags.dry })

// Retrieve Netlify Build options
const [token] = await this.getConfigToken()
const [token] = await getToken()

const options = await getBuildOptions({
context: this,
Expand Down
Loading