mirror of
https://github.com/atom/atom.git
synced 2026-01-21 04:48:12 -05:00
Load config schemas from packages' package.json files
This commit is contained in:
13
spec/fixtures/packages/package-with-json-config-schema/package.json
vendored
Normal file
13
spec/fixtures/packages/package-with-json-config-schema/package.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "package-with-json-config-schema",
|
||||
"configSchema": {
|
||||
"a": {
|
||||
"type": "number",
|
||||
"default": 5
|
||||
},
|
||||
"b": {
|
||||
"type": "string",
|
||||
"default": "five"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -194,6 +194,21 @@ describe "PackageManager", ->
|
||||
expect(atom.config.set('package-with-config-schema.numbers.one', '10')).toBe true
|
||||
expect(atom.config.get('package-with-config-schema.numbers.one')).toBe 10
|
||||
|
||||
it "assigns the config schema when the package contains a schema in its package.json", ->
|
||||
expect(atom.config.get('package-with-json-config-schema')).toBeUndefined()
|
||||
|
||||
waitsForPromise ->
|
||||
atom.packages.activatePackage('package-with-json-config-schema')
|
||||
|
||||
runs ->
|
||||
expect(atom.config.getSchema('package-with-json-config-schema')).toEqual {
|
||||
type: 'object'
|
||||
properties: {
|
||||
a: {type: 'number', default: 5}
|
||||
b: {type: 'string', default: 'five'}
|
||||
}
|
||||
}
|
||||
|
||||
describe "when the package metadata includes `activationCommands`", ->
|
||||
[mainModule, promise, workspaceCommandListener, registration] = []
|
||||
|
||||
|
||||
@@ -133,11 +133,14 @@ class Package
|
||||
activateConfig: ->
|
||||
return if @configActivated
|
||||
|
||||
@requireMainModule() unless @mainModule?
|
||||
if @mainModule?
|
||||
if @mainModule.config? and typeof @mainModule.config is 'object'
|
||||
@config.setSchema @name, {type: 'object', properties: @mainModule.config}
|
||||
@mainModule.activateConfig?()
|
||||
if configSchema = @metadata.configSchema
|
||||
@config.setSchema @name, {type: 'object', properties: configSchema}
|
||||
else
|
||||
@requireMainModule() unless @mainModule?
|
||||
if @mainModule?
|
||||
if @mainModule.config? and typeof @mainModule.config is 'object'
|
||||
@config.setSchema @name, {type: 'object', properties: @mainModule.config}
|
||||
@mainModule.activateConfig?()
|
||||
@configActivated = true
|
||||
|
||||
activateStylesheets: ->
|
||||
|
||||
Reference in New Issue
Block a user