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

Commit

Permalink
Merge pull request #729 from FrederickGeek8/master
Browse files Browse the repository at this point in the history
Textmate conversion error reporting & apm list --enabled
  • Loading branch information
50Wliu committed Aug 21, 2017
2 parents ec68b90 + 58fad18 commit 5cf83aa
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
26 changes: 26 additions & 0 deletions spec/list-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,32 @@ describe 'apm list', ->
listPackages [], ->
expect(console.log.argsForCall[1][0]).toContain 'test-module@1.0.0 (disabled)'

it 'displays only enabled packages when --enabled is called', ->
atomPackages =
'test-module':
metadata:
name: 'test-module'
version: '1.0.0'
'test2-module':
metadata:
name: 'test2-module'
version: '1.0.0'

fs.writeFileSync(path.join(resourcePath, 'package.json'), JSON.stringify(_atomPackages: atomPackages))

packagesPath = path.join(atomHome, 'packages')
fs.makeTreeSync(packagesPath)
wrench.copyDirSyncRecursive(path.join(__dirname, 'fixtures', 'test-module'), path.join(packagesPath, 'test-module'))
configPath = path.join(atomHome, 'config.cson')
CSON.writeFileSync configPath, '*':
core: disabledPackages: ["test-module"]

listPackages ['--enabled'], ->
expect(console.log.argsForCall[1][0]).toContain 'test2-module@1.0.0'
expect(console.log.argsForCall[4][0]).toContain 'dev-package@1.0.0'
expect(console.log.argsForCall[7][0]).toContain 'user-package@1.0.0'
expect(console.log.argsForCall[10][0]).toContain 'git-package@1.0.0'

it 'lists packages in json format when --json is passed', ->
listPackages ['--json'], ->
json = JSON.parse(console.log.argsForCall[0][0])
Expand Down
17 changes: 12 additions & 5 deletions src/list.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ class List extends Command
apm list --themes
apm list --packages
apm list --installed
apm list --installed --enabled
apm list --installed --bare > my-packages.txt
apm list --json
List all the installed packages and also the packages bundled with Atom.
"""
options.alias('b', 'bare').boolean('bare').describe('bare', 'Print packages one per line with no formatting')
options.alias('e', 'enabled').boolean('enabled').describe('enabled', 'Print only enabled packages')
options.alias('d', 'dev').boolean('dev').default('dev', true).describe('dev', 'Include dev packages')
options.alias('h', 'help').describe('help', 'Print this usage message')
options.alias('i', 'installed').boolean('installed').describe('installed', 'Only list installed packages/themes')
Expand Down Expand Up @@ -81,11 +83,14 @@ class List extends Command
manifest ?= {}
manifest.name = child
if options.argv.themes
packages.push(manifest) if manifest.theme
if manifest.theme and not (options.argv.enabled and @isPackageDisabled(manifest.name))
packages.push(manifest)
else if options.argv.packages
packages.push(manifest) unless manifest.theme
unless manifest.theme or (options.argv.enabled and @isPackageDisabled(manifest.name))
packages.push(manifest)
else
packages.push(manifest)
unless options.argv.enabled and @isPackageDisabled(manifest.name)
packages.push(manifest)

packages

Expand Down Expand Up @@ -114,18 +119,20 @@ class List extends Command
callback?(null, gitPackages)

listBundledPackages: (options, callback) ->
config.getResourcePath (resourcePath) ->
config.getResourcePath (resourcePath) =>
try
metadataPath = path.join(resourcePath, 'package.json')
{_atomPackages} = JSON.parse(fs.readFileSync(metadataPath))
_atomPackages ?= {}
packages = (metadata for packageName, {metadata} of _atomPackages)

packages = packages.filter (metadata) ->
packages = packages.filter (metadata) =>
if options.argv.themes
metadata.theme
else if options.argv.packages
not metadata.theme
else if options.argv.enabled
not @isPackageDisabled(metadata.name)
else
true

Expand Down
12 changes: 10 additions & 2 deletions src/package-converter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ class PackageConverter
extension = path.extname(child)
name = path.basename(child, extension)

selector = new ScopeSelector(scope).toCssSelector() if scope
try
selector = new ScopeSelector(scope).toCssSelector() if scope
catch e
e.message = "In file #{e.fileName} at #{JSON.stringify(scope)}: #{e.message}"
throw e
selector ?= '*'

snippetsBySelector[selector] ?= {}
Expand All @@ -184,7 +188,11 @@ class PackageConverter
continue unless scope and settings

if properties = @convertSettings(settings)
selector = new ScopeSelector(scope).toCssSelector()
try
selector = new ScopeSelector(scope).toCssSelector()
catch e
e.message = "In file #{e.fileName} at #{JSON.stringify(scope)}: #{e.message}"
throw e
for key, value of properties
preferencesBySelector[selector] ?= {}
if preferencesBySelector[selector][key]?
Expand Down

0 comments on commit 5cf83aa

Please sign in to comment.