How do I add settings to my package?


#1

I have an existing package and I’d like to add some settings to it. Here’s what I’ve tried so far:

  • Adding a lib/config-schema.cson file
  • Changing the above file to a json file and changing the formatting
  • require-ing the above files in the main js file
  • Adding the config directly to the module.exports within the main

None of these have worked, my package has never displayed a Settings button after reloading Atom. I did see that there are issues related to this and using "activationCommands", but even removing that didn’t seem to help. Any advice on how to get settings to work?

As a possibly related side note, when viewing my package in Atom, it says there’s “No README.”, but I have a README.md file in the package. Am I doing something wrong there too?


#2

Figuring that maybe due to how long ago I worked on this, something was setup incorrectly, I decided to delete the existing symlink and run apm develop again. That seems to have fixed the missing README file.

Tinkering further, I was able to get settings to show up properly when I add them directly to module.exports:

module.exports = Docksend =
  subscriptions: null
  config:
    someInt:
      type: 'integer'
      default: 23
      minimum: 1

Do I have to do something special to get it to work in a config-schema.cson file?


#3

There are two locations that Atom looks for config information:

  1. In the config property of the object exported from the module named by main in the package.json
  2. In the configSchema property in the package.json

See:

So if you wanted to store your stuff in a config-schema.cson file, you would have to load it into the config property when your main module loads before it gets exported.


#4

That makes sense. I’m trying to do that with a require and I’m getting an error:

SyntaxError: Unexpected token default

This is my require statement:

configSchema = require './config-schema.cson'

Any ideas why that’s happening?


#5

You don’t need to specify .cson … I think I’ve seen that cause weirdness before. Also where do you have this require statement?


#6

Right after my other requires at the top:

opener = require 'opener'
fs     = require 'fs'
{CompositeDisposable} = require 'atom'
configSchema = require './config-schema'

module.exports = Docksend =
  subscriptions: null
  config: configSchema

#7

Ah ok, that should work. It looks like it is choking on something having default somewhere that it shouldn’t?


#8

Here’s the contents of my config-schema.cson, seems like it should be fine…

less:
  type: 'object'
  title: 'Less'
  order: 1
  properties:
    enableUpload:
      title: 'Upload related Less files'
      type: 'boolean'
      default: false
    extensions:
      title: 'Extensions of related Less files'
      type: 'string'
      default: '.css, .min.css'
sass:
  type: 'object'
  title: 'Sass'
  order: 2
  properties:
    enableUpload:
      title: 'Upload related Sass files'
      type: 'boolean'
      default: false
    extensions:
      title: 'Extensions of related Sass files'
      type: 'string'
      default: '.css, .min.css'
minifiedJavascript:
  type: 'object'
  title: 'Minified Javascript'
  order: 3
  properties:
    enableUpload:
      title: 'Upload related Javascript files'
      type: 'boolean'
      default: false
    extensions:
      title: 'Extensions of related Javascript files'
      type: 'string'
      default: '.min.js'

By the way, I’ve add config: at the top and ended up removing it in my rain dance to get this to work. Is it required?


#9

I don’t believe so.

What happens when you put those contents under config in the actual CoffeeScript file?


#10

It works just fine, it’s how I’m currently doing it: https://github.com/wesbaker/atom-docksend/blob/master/lib/docksend.coffee


#11

Package config documentation: https://atom.io/docs/api/latest/Config


#12

I’ve seen that, but there’s nothing in there about putting it into a separate file.


#13

I don’t think require supports CSON.
If you want to put your configuration into a separate file, you should either require the file as JSON or as a module:

module.exports =
  less:
    type: 'object'
    title: 'Less'
    order: 1
    properties:
      enableUpload:
        title: 'Upload related Less files'
        type: 'boolean'
        default: false
      extensions:
        title: 'Extensions of related Less files'
        type: 'string'
        default: '.css, .min.css'
  sass:
    type: 'object'
    title: 'Sass'
    order: 2
    properties:
      enableUpload:
        title: 'Upload related Sass files'
        type: 'boolean'
        default: false
      extensions:
        title: 'Extensions of related Sass files'
        type: 'string'
        default: '.css, .min.css'
  minifiedJavascript:
    type: 'object'
    title: 'Minified Javascript'
    order: 3
    properties:
      enableUpload:
        title: 'Upload related Javascript files'
        type: 'boolean'
        default: false
      extensions:
        title: 'Extensions of related Javascript files'
        type: 'string'
        default: '.min.js'

#14

Where is this documented?