See #864. Add Migration command from old option keys to new keys
Old: { LANG_OPTION: 'VALUE' } New: { LANG: { OPTION: 'VALUE' }}
This commit is contained in:
parent
fa9dd8dd4f
commit
afa27fd50b
|
@ -121,6 +121,7 @@
|
|||
"atom-workspace": [
|
||||
"atom-beautify:help-debug-editor",
|
||||
"atom-beautify:beautify-editor",
|
||||
"atom-beautify:migrate-settings",
|
||||
"core:save",
|
||||
"core:save-as"
|
||||
],
|
||||
|
|
|
@ -198,6 +198,25 @@ describe "Atom-Beautify", ->
|
|||
editor = e
|
||||
expect(editor.getText()).toEqual("")
|
||||
|
||||
describe "Migrate Settings", ->
|
||||
|
||||
migrateSettings = (beforeKey, afterKey, val) ->
|
||||
# set old options
|
||||
atom.config.set("atom-beautify.#{beforeKey}", val)
|
||||
atom.commands.dispatch workspaceElement, "atom-beautify:migrate-settings"
|
||||
# Check resulting config
|
||||
expect(_.has(atom.config.get('atom-beautify'), beforeKey)).toBe(false)
|
||||
expect(atom.config.get("atom-beautify.#{afterKey}")).toBe(val)
|
||||
|
||||
it "should migrate js_indent_size to js.indent_size", ->
|
||||
migrateSettings("js_indent_size","js.indent_size", 10)
|
||||
|
||||
it "should migrate analytics to general.analytics", ->
|
||||
migrateSettings("analytics","general.analytics", true)
|
||||
|
||||
it "should migrate _analyticsUserId to general._analyticsUserId", ->
|
||||
migrateSettings("_analyticsUserId","general._analyticsUserId", "userid")
|
||||
|
||||
beautifyEditor = (callback) ->
|
||||
isComplete = false
|
||||
beforeText = null
|
||||
|
@ -238,9 +257,9 @@ describe "Atom-Beautify", ->
|
|||
# See https://discuss.atom.io/t/solved-settimeout-not-working-firing-in-specs-tests/11427/17
|
||||
jasmine.unspy(window, 'setTimeout')
|
||||
|
||||
afterEach ->
|
||||
atom.packages.deactivatePackages()
|
||||
atom.packages.unloadPackages()
|
||||
# afterEach ->
|
||||
# atom.packages.deactivatePackages()
|
||||
# atom.packages.unloadPackages()
|
||||
|
||||
describe ".jsbeautifyrc", ->
|
||||
|
||||
|
@ -249,7 +268,7 @@ describe "Atom-Beautify", ->
|
|||
getOptions = (callback) ->
|
||||
options = null
|
||||
waitsForPromise ->
|
||||
console.log('beautifier', beautifier.getOptionsForPath, beautifier)
|
||||
# console.log('beautifier', beautifier.getOptionsForPath, beautifier)
|
||||
allOptions = beautifier.getOptionsForPath(null, null)
|
||||
# Resolve options with promises
|
||||
return Promise.all(allOptions)
|
||||
|
@ -308,7 +327,7 @@ describe "Languages", ->
|
|||
namespaceGroups = _.groupBy(languages.languages, "namespace")
|
||||
namespacePairs = _.toPairs(namespaceGroups)
|
||||
namespaceOverlap = _.filter(namespacePairs, ([namespace, group]) -> group.length > 1)
|
||||
console.log('namespaces', namespaceGroups, namespacePairs, namespaceOverlap)
|
||||
# console.log('namespaces', namespaceGroups, namespacePairs, namespaceOverlap)
|
||||
expect(namespaceOverlap.length).toBe(0, \
|
||||
"Language namespaces are overlapping.\n\
|
||||
Namespaces are unique: only one language for each namespace.\n"+
|
||||
|
|
|
@ -15,7 +15,7 @@ isWindows = process.platform is 'win32' or
|
|||
process.env.OSTYPE is 'cygwin' or
|
||||
process.env.OSTYPE is 'msys'
|
||||
|
||||
xdescribe "BeautifyLanguages", ->
|
||||
describe "BeautifyLanguages", ->
|
||||
|
||||
optionsDir = path.resolve(__dirname, "../examples")
|
||||
|
||||
|
|
|
@ -286,16 +286,16 @@ module.exports = class Beautifiers extends EventEmitter
|
|||
|
||||
# Setup Analytics
|
||||
analytics = new Analytics(analyticsWriteKey)
|
||||
unless atom.config.get("atom-beautify.general.analyticsUserId")
|
||||
unless atom.config.get("atom-beautify.general._analyticsUserId")
|
||||
uuid = require("node-uuid")
|
||||
atom.config.set "atom-beautify.general.analyticsUserId", uuid.v4()
|
||||
atom.config.set "atom-beautify.general._analyticsUserId", uuid.v4()
|
||||
|
||||
# Setup Analytics User Id
|
||||
userId = atom.config.get("atom-beautify.general.analyticsUserId")
|
||||
userId = atom.config.get("atom-beautify.general._analyticsUserId")
|
||||
analytics.identify userId : userId
|
||||
version = pkg.version
|
||||
analytics.track
|
||||
userId : atom.config.get("atom-beautify.general.analyticsUserId")
|
||||
userId : atom.config.get("atom-beautify.general._analyticsUserId")
|
||||
event : "Beautify"
|
||||
properties :
|
||||
language : language?.name
|
||||
|
|
|
@ -67,6 +67,8 @@ showError = (error) ->
|
|||
|
||||
beautify = ({onSave}) ->
|
||||
|
||||
plugin.checkUnsupportedOptions()
|
||||
|
||||
# Continue beautifying
|
||||
path ?= require("path")
|
||||
forceEntireFile = onSave and atom.config.get("atom-beautify.general.beautifyEntireFileOnSave")
|
||||
|
@ -259,6 +261,8 @@ beautifyDirectory = ({target}) ->
|
|||
|
||||
debug = () ->
|
||||
|
||||
plugin.checkUnsupportedOptions()
|
||||
|
||||
# Get current editor
|
||||
editor = atom.workspace.getActiveTextEditor()
|
||||
|
||||
|
@ -497,6 +501,53 @@ handleSaveEvent = ->
|
|||
)
|
||||
)
|
||||
plugin.subscriptions.add disposable
|
||||
|
||||
getUnsupportedOptions = ->
|
||||
settings = atom.config.get('atom-beautify')
|
||||
schema = atom.config.getSchema('atom-beautify')
|
||||
unsupportedOptions = _.filter(_.keys(settings), (key) ->
|
||||
# return atom.config.getSchema("atom-beautify.${key}").type
|
||||
# return typeof settings[key]
|
||||
schema.properties[key] is undefined
|
||||
)
|
||||
return unsupportedOptions
|
||||
|
||||
plugin.checkUnsupportedOptions = ->
|
||||
unsupportedOptions = getUnsupportedOptions()
|
||||
if unsupportedOptions.length isnt 0
|
||||
atom.notifications.addWarning("You have unsupported options: #{unsupportedOptions.join(', ')} <br> Please run Atom command 'Atom-Beautify: Migrate Settings'.")
|
||||
|
||||
plugin.migrateSettings = ->
|
||||
unsupportedOptions = getUnsupportedOptions()
|
||||
namespaces = beautifier.languages.namespaces
|
||||
# console.log('migrate-settings', schema, namespaces, unsupportedOptions)
|
||||
if unsupportedOptions.length is 0
|
||||
atom.notifications.addSuccess("No options to migrate.")
|
||||
else
|
||||
rex = new RegExp("(#{namespaces.join('|')})_(.*)")
|
||||
rename = _.toPairs(_.zipObject(unsupportedOptions, _.map(unsupportedOptions, (key) ->
|
||||
m = key.match(rex)
|
||||
if m is null
|
||||
# Did not match
|
||||
# Put into general
|
||||
return "general.#{key}"
|
||||
else
|
||||
return "#{m[1]}.#{m[2]}"
|
||||
)))
|
||||
# console.log('rename', rename)
|
||||
# logger.verbose('rename', rename)
|
||||
|
||||
# Move all option values to renamed key
|
||||
_.each(rename, ([key, newKey]) ->
|
||||
# console.log('rename', key, newKey)
|
||||
# Copy to new key
|
||||
val = atom.config.get("atom-beautify.#{key}")
|
||||
atom.config.set("atom-beautify.#{newKey}", val)
|
||||
# Delete old key
|
||||
atom.config.set("atom-beautify.#{key}", undefined)
|
||||
)
|
||||
atom.notifications.addSuccess("Successfully migrated options: #{unsupportedOptions.join(', ')}")
|
||||
|
||||
plugin.config = _.merge(require('./config.coffee'), defaultLanguageOptions)
|
||||
plugin.activate = ->
|
||||
@subscriptions = new CompositeDisposable
|
||||
|
@ -505,6 +556,7 @@ plugin.activate = ->
|
|||
@subscriptions.add atom.commands.add "atom-workspace", "atom-beautify:help-debug-editor", debug
|
||||
@subscriptions.add atom.commands.add ".tree-view .file .name", "atom-beautify:beautify-file", beautifyFile
|
||||
@subscriptions.add atom.commands.add ".tree-view .directory .name", "atom-beautify:beautify-directory", beautifyDirectory
|
||||
@subscriptions.add atom.commands.add "atom-workspace", "atom-beautify:migrate-settings", plugin.migrateSettings
|
||||
|
||||
plugin.deactivate = ->
|
||||
@subscriptions.dispose()
|
||||
|
|
|
@ -15,7 +15,7 @@ module.exports = {
|
|||
used the most, as well as other stats. Everything is anonymized and no personal
|
||||
information, such as source code, is sent.
|
||||
See https://github.com/Glavin001/atom-beautify/issues/47 for more details."
|
||||
analyticsUserId :
|
||||
_analyticsUserId :
|
||||
title: 'Analytics User Id'
|
||||
type : 'string'
|
||||
default : ""
|
||||
|
|
Loading…
Reference in New Issue