My First Package Tutorial - errors, unable to delete package and start over


#1

I tried the My First Package Tutorial.

I thought I followed the directions here:

To begin, press cmd-shift-P to bring up the Command Palette. Type "generate package" and select the "Package Generator: Generate Package" command. Now we need to name the package. Try to avoid naming your package with the atom- prefix, for example we are going to call this package ascii-art.

Atom will open a new window with the contents of our new ascii-art package displayed in the Tree View. Because this window is opened after the package is created, the ASCII Art package will be loaded and available in our new window. To verify this, toggle the Command Palette (cmd-shift-P) and type “ASCII Art”. You’ll see a new ASCII Art: Toggle command. When triggered, this command displays a default message.

Now let’s edit the package files to make our ASCII Art package do something interesting. Since this package doesn’t need any UI, we can remove all view-related code. Start by opening up lib/ascii-art.coffee. Remove all view code, so the module.exports section looks like this:

module.exports =
activate: ->

by deleting everything to the right of the assignment operator for module.exports, as well as everything below the line for “activate:” and modifying activate to look as shown. I am unsure what “Remove all view code” means and trusted that the tutorial shows all of the code that should remain in the file.

I then attempted this portion:

Create a Command Now let's add a command. We recommend that you namespace your commands with the package name followed by a :, so we'll call our command ascii-art:convert. Register the command in lib/ascii-art.coffee:

module.exports =
activate: ->
atom.workspaceView.command “ascii-art:convert”, => @convert()

convert: ->
# This assumes the active pane item is an editor
editor = atom.workspace.activePaneItem
editor.insertText(‘Hello, World!’)
The atom.workspaceView.command method takes a command name and a callback. The callback executes when the command is triggered. In this case, when the command is triggered the callback will call the convert method and insert ‘Hello, World!’.

Again, I made sure what was in the file matched what is pictured. This means what is pictured is the only thing that was in my edited copy of that file.

The errors showed up during the next section:

Reload the Package Before we can trigger ascii-art:convert, we need to load the latest code for our package by reloading the window. Run the command window:reload from the command palette or by pressing ctrl-alt-cmd-l.

Trigger the Command
Now open the command panel and search for the ascii-art:convert command. But it’s not there! To fix this, open package.json and find the property called activationEvents. Activation Events speed up load time by allowing Atom to delay a package’s activation until it’s needed. So remove the existing command and add ascii-art:convert to the activationEvents array:

“activationEvents”: [“ascii-art:convert”],
First, reload the window by running the command window:reload. Now when you run the ascii-art:convert command it will output ‘Hello, World!’

The only thing I changed in this instance was the text for “activationEvents”. I deleted what was in the file and replaced it with what is pictured. Reloading the package caused error messages in Atom. I wasn’t able to quickly trace down what was wrong. I decided to delete the package and start over.

I cannot delete the package and start over.

Atom will not let me delete the package in the file tree on the lefthand side of the screen. I get a message saying I cannot remove the root directory.

Pictured above is my second attempt to delete the package. I received the same message on the first attempt, after which, I uninstalled the package. Notice a directory for the package still exists. It will not go away when I delete it from my local file structure with Windows Explorer.

Please tell me how to permanently remove the package directory. If someone would point me toward info that will tell me what I goofed up with the package creation that would be great.

note: Sorry for all the block quotes, as a new user I am only allowed one image per post.


#2

Well, for a quick one: You will probably have to close Atom and make sure the folder isn’t open anywhere else, then you can delete it from the file system (i.e. via the Windows Explorer).

As to the tutorial package, you can always compare your code with the finished example code in this repository, to make sure you’ve got it right.


#3

Hi there, it seems you’ve been following an old version of the tutorial through that link - as it points to https://atom.io/docs/v0.80.0/your-first-package (Atom version 0.80.0). That’s why the errors appeared on reloading or trying to execute one of the commands, as the instructions on that page will be leading you to enter out of date/no longer existing function/class names.

As an aside, maybe a clearly visible warning could be automatically made to appear at the top of out of date documentation pages? [edit: so I’ve realised that just such a message is already there… I should’ve looked more closely, scratch that suggestion :smiley: ]

This should be the current version of the same tutorial: 3.4 Package: Modifying Text. Hopefully that will work for you with no further problems.

Although I think it is now “part 2” of a two part package creation mini-series, with the first part here: 3.3 Package: Word Count.


#4

try https://atom.io/docs/latest/


#5

Thank you. It will take me a little while to work through everything you’ve linked. I appreciate the help.