Skip to content

Commit

Permalink
fix: remove commandNames from the classes
Browse files Browse the repository at this point in the history
- `@commandNames` in CoffeeScript is translated to verbose `initClass` in JavaScript

- This paves the way for making loading of the commands lazy.
  • Loading branch information
aminya committed Jul 22, 2021
1 parent f66bf72 commit f46a490
Show file tree
Hide file tree
Showing 29 changed files with 78 additions and 91 deletions.
113 changes: 78 additions & 35 deletions src/apm-cli.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,84 @@ setupTempDirectory = ->

setupTempDirectory()

commandClasses = [
require './ci'
require './clean'
require './config'
require './dedupe'
require './develop'
require './disable'
require './docs'
require './enable'
require './featured'
require './init'
require './install'
require './links'
require './link'
require './list'
require './login'
require './publish'
require './rebuild'
require './rebuild-module-cache'
require './search'
require './star'
require './stars'
require './test'
require './uninstall'
require './unlink'
require './unpublish'
require './unstar'
require './upgrade'
require './view'
]

commands = {}
for commandClass in commandClasses
for name in commandClass.commandNames ? []
commands[name] = commandClass
# TODO make loading lazy
ciClass = require './ci'
cleanClass = require './clean'
configClass = require './config'
dedupClass = require './dedupe'
developClass = require './develop'
disableClass = require './disable'
docsClass = require './docs'
enableClass = require './enable'
featuredClass = require './featured'
initClass = require './init'
installClass = require './install'
linksClass = require './links'
linkClass = require './link'
listClass = require './list'
loginClass = require './login'
publishClass = require './publish'
rebuildClass = require './rebuild'
rebuildModuleCacheClass = require './rebuild-module-cache'
searchClass = require './search'
starClass = require './star'
starsClass = require './stars'
testClass = require './test'
uninstallClass = require './uninstall'
unlinkClass = require './unlink'
unpublishClass = require './unpublish'
unstarClass = require './unstar'
upgradeClass = require './upgrade'
viewClass = require './view'

commands = {
'ci': ciClass,
'clean': cleanClass,
'prune': cleanClass,
'config': configClass,
'dedupe': dedupClass,
'dev': developClass,
'develop': developClass,
'disable': disableClass,
'docs': docsClass,
'home': docsClass,
'open': docsClass,
'enable': enableClass
'featured': featuredClass
'init': initClass,
'install': installClass,
'i': installClass,
'link': linkClass,
'ln': linkClass
'linked': linksClass,
'links': linksClass,
'lns': linksClass,
'list': listClass,
'ls': listClass,
'login': loginClass,
'publish': publishClass,
'rebuild-module-cache': rebuildModuleCacheClass,
'rebuild': rebuildClass,
'search': searchClass,
'star': starClass,
'stars': starsClass,
'starred': starsClass
'test': testClass
'deinstall': uninstallClass,
'delete': uninstallClass,
'erase': uninstallClass,
'remove': uninstallClass,
'rm': uninstallClass,
'uninstall': uninstallClass,
'unlink': unlinkClass,
'unpublish': unpublishClass,
'unstar': unstarClass,
'upgrade': upgradeClass,
'outdated': upgradeClass,
'update': upgradeClass,
'view': viewClass,
'show': viewClass,
}

parseOptions = (args=[]) ->
options = yargs(args).wrap(Math.min(100, yargs.terminalWidth()))
Expand Down
2 changes: 0 additions & 2 deletions src/ci.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Command = require './command'

module.exports =
class Ci extends Command
@commandNames: ['ci']

constructor: ->
super()
@atomDirectory = config.getAtomDirectory()
Expand Down
2 changes: 0 additions & 2 deletions src/clean.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ fs = require './fs'

module.exports =
class Clean extends Command
@commandNames: ['clean', 'prune']

constructor: ->
super()
@atomNpmPath = require.resolve('npm/bin/npm-cli')
Expand Down
2 changes: 0 additions & 2 deletions src/config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ Command = require './command'

module.exports =
class Config extends Command
@commandNames: ['config']

constructor: ->
super()
atomDirectory = apm.getAtomDirectory()
Expand Down
2 changes: 0 additions & 2 deletions src/dedupe.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ fs = require './fs'

module.exports =
class Dedupe extends Command
@commandNames: ['dedupe']

constructor: ->
super()
@atomDirectory = config.getAtomDirectory()
Expand Down
2 changes: 0 additions & 2 deletions src/develop.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ request = require './request'

module.exports =
class Develop extends Command
@commandNames: ['dev', 'develop']

constructor: ->
super()
@atomDirectory = config.getAtomDirectory()
Expand Down
2 changes: 0 additions & 2 deletions src/disable.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ List = require './list'

module.exports =
class Disable extends Command
@commandNames: ['disable']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/docs.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ config = require './apm'

module.exports =
class Docs extends View
@commandNames: ['docs', 'home', 'open']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/enable.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ Command = require './command'

module.exports =
class Enable extends Command
@commandNames: ['enable']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/featured.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ tree = require './tree'

module.exports =
class Featured extends Command
@commandNames: ['featured']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/init.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ fs = require './fs'

module.exports =
class Init extends Command
@commandNames: ['init']

supportedSyntaxes: ['coffeescript', 'javascript']

parseOptions: (argv) ->
Expand Down
2 changes: 0 additions & 2 deletions src/install.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ request = require './request'

module.exports =
class Install extends Command
@commandNames: ['install', 'i']

constructor: ->
super()
@atomDirectory = config.getAtomDirectory()
Expand Down
2 changes: 0 additions & 2 deletions src/link.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ fs = require './fs'

module.exports =
class Link extends Command
@commandNames: ['link', 'ln']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/links.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ tree = require './tree'

module.exports =
class Links extends Command
@commandNames: ['linked', 'links', 'lns']

constructor: ->
super()
@devPackagesPath = path.join(config.getAtomDirectory(), 'dev', 'packages')
Expand Down
2 changes: 0 additions & 2 deletions src/list.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ tree = require './tree'

module.exports =
class List extends Command
@commandNames: ['list', 'ls']

constructor: ->
super()
@userPackagesDirectory = path.join(config.getAtomDirectory(), 'packages')
Expand Down
2 changes: 0 additions & 2 deletions src/login.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class Login extends Command
else
callback(null, token)

@commandNames: ['login']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))

Expand Down
2 changes: 0 additions & 2 deletions src/publish.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ request = require './request'

module.exports =
class Publish extends Command
@commandNames: ['publish']

constructor: ->
super()
@userConfigPath = config.getUserConfigPath()
Expand Down
2 changes: 0 additions & 2 deletions src/rebuild-module-cache.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ fs = require './fs'

module.exports =
class RebuildModuleCache extends Command
@commandNames: ['rebuild-module-cache']

constructor: ->
super()
@atomPackagesDirectory = path.join(config.getAtomDirectory(), 'packages')
Expand Down
2 changes: 0 additions & 2 deletions src/rebuild.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Install = require './install'

module.exports =
class Rebuild extends Command
@commandNames: ['rebuild']

constructor: ->
super()
@atomDirectory = config.getAtomDirectory()
Expand Down
2 changes: 0 additions & 2 deletions src/search.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ tree = require './tree'

module.exports =
class Search extends Command
@commandNames: ['search']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/star.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ request = require './request'

module.exports =
class Star extends Command
@commandNames: ['star']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/stars.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ tree = require './tree'

module.exports =
class Stars extends Command
@commandNames: ['stars', 'starred']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ fs = require './fs'

module.exports =
class Test extends Command
@commandNames: ['test']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))

Expand Down
2 changes: 0 additions & 2 deletions src/uninstall.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ request = require './request'

module.exports =
class Uninstall extends Command
@commandNames: ['deinstall', 'delete', 'erase', 'remove', 'rm', 'uninstall']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/unlink.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ fs = require './fs'

module.exports =
class Unlink extends Command
@commandNames: ['unlink']

constructor: ->
super()
@devPackagesPath = path.join(config.getAtomDirectory(), 'dev', 'packages')
Expand Down
2 changes: 0 additions & 2 deletions src/unpublish.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ request = require './request'

module.exports =
class Unpublish extends Command
@commandNames: ['unpublish']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))

Expand Down
2 changes: 0 additions & 2 deletions src/unstar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ request = require './request'

module.exports =
class Unstar extends Command
@commandNames: ['unstar']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/upgrade.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ git = require './git'

module.exports =
class Upgrade extends Command
@commandNames: ['upgrade', 'outdated', 'update']

constructor: ->
super()
@atomDirectory = config.getAtomDirectory()
Expand Down
2 changes: 0 additions & 2 deletions src/view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ tree = require './tree'

module.exports =
class View extends Command
@commandNames: ['view', 'show']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down

0 comments on commit f46a490

Please sign in to comment.