This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 295
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9698a9e
Add `apm init -p package-name` for generating packages
5bc0733
Sort command requires alphabetically.
94240ef
Correct spec comment
9a1e5df
Remove unused requires/variables
6423cea
Throw an error if a type isn't specified
eada453
Accept absolute paths as well as relative paths
af5b901
Implement `apm init --theme <theme-name>`
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
path = require 'path' | ||
|
||
optimist = require 'optimist' | ||
|
||
Command = require './command' | ||
fs = require './fs' | ||
|
||
module.exports = | ||
class Generator extends Command | ||
@commandNames: ['init'] | ||
|
||
parseOptions: (argv) -> | ||
options = optimist(argv) | ||
|
||
options.usage """ | ||
Usage: | ||
apm init -p <package-name> | ||
apm init -t <theme-name> | ||
|
||
Generates code scaffolding for either a theme or package depending | ||
on option selected. | ||
""" | ||
options.alias('p', 'package').describe('package', 'Generates a basic package') | ||
options.alias('t', 'theme').describe('theme', 'Generates a basic theme') | ||
options.alias('h', 'help').describe('help', 'Print this usage message') | ||
|
||
showHelp: (argv) -> @parseOptions(argv).showHelp() | ||
|
||
run: (options) -> | ||
{callback} = options | ||
options = @parseOptions(options.commandArgs) | ||
if options.argv.package? | ||
packagePath = path.resolve(options.argv.package) | ||
templatePath = path.resolve(__dirname, '..', 'templates', 'package') | ||
@generateFromTemplate(packagePath, templatePath) | ||
callback() | ||
else if options.argv.theme? | ||
themePath = path.resolve(options.argv.theme) | ||
templatePath = path.resolve(__dirname, '..', 'templates', 'theme') | ||
@generateFromTemplate(themePath, templatePath) | ||
callback() | ||
else | ||
callback('Error: You must specify either --package or --theme to `apm init`') | ||
|
||
generateFromTemplate: (packagePath, templatePath) -> | ||
packageName = path.basename(packagePath) | ||
|
||
fs.mkdir(packagePath) | ||
|
||
for childPath in fs.listRecursive(templatePath) | ||
templateChildPath = path.resolve(templatePath, childPath) | ||
relativePath = templateChildPath.replace(templatePath, "") | ||
relativePath = relativePath.replace(/^\//, '') | ||
relativePath = relativePath.replace(/\.template$/, '') | ||
relativePath = @replacePackageNamePlaceholders(relativePath, packageName) | ||
|
||
sourcePath = path.join(packagePath, relativePath) | ||
if fs.isDirectory(templateChildPath) | ||
fs.mkdir(sourcePath) | ||
else if fs.isFile(templateChildPath) | ||
fs.mkdir(path.dirname(sourcePath)) | ||
contents = fs.readFileSync(templateChildPath).toString() | ||
content = @replacePackageNamePlaceholders(contents, packageName) | ||
fs.writeFileSync(sourcePath, content) | ||
|
||
replacePackageNamePlaceholders: (string, packageName) -> | ||
placeholderRegex = /__(?:(package-name)|([pP]ackageName)|(package_name))__/g | ||
string = string.replace placeholderRegex, (match, dash, camel, underscore) => | ||
if dash | ||
@dasherize(packageName) | ||
else if camel | ||
if /[a-z]/.test(camel[0]) | ||
packageName = packageName[0].toLowerCase() + packageName[1...] | ||
else if /[A-Z]/.test(camel[0]) | ||
packageName = packageName[0].toUpperCase() + packageName[1...] | ||
@camelize(packageName) | ||
|
||
else if underscore | ||
@underscore(packageName) | ||
|
||
dasherize: (string) -> | ||
string = string[0].toLowerCase() + string[1..] | ||
string.replace /([A-Z])|(_)/g, (m, letter, underscore) -> | ||
if letter | ||
"-" + letter.toLowerCase() | ||
else | ||
"-" | ||
|
||
camelize: (string) -> | ||
string.replace /[_-]+(\w)/g, (m) -> m[1].toUpperCase() | ||
|
||
underscore: (string) -> | ||
string = string[0].toLowerCase() + string[1..] | ||
string.replace /([A-Z])|(-)/g, (m, letter, dash) -> | ||
if letter | ||
"_" + letter.toLowerCase() | ||
else | ||
"_" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# DOCUMENT: link to keymap documentation | ||
'body': | ||
'meta-alt-ctrl-o': '__package-name__:toggle' |
25 changes: 25 additions & 0 deletions
25
templates/package/lib/__package-name__-view.coffee.template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{$$, View} = require 'space-pen' | ||
|
||
module.exports = | ||
class __PackageName__View extends View | ||
@content: -> | ||
@div class: '__package-name__ overlay from-top', => | ||
@div "The __PackageName__ package is Alive! It's ALIVE!", class: "message" | ||
|
||
initialize: (serializeState) -> | ||
rootView.command "__package-name__:toggle", => @toggle() | ||
|
||
# Returns an object that can be retrieved when package is activated | ||
serialize: -> | ||
|
||
# Tear down any state and detach | ||
destroy: -> | ||
@detach() | ||
|
||
toggle: -> | ||
console.log "__PackageName__View was toggled!" | ||
if @hasParent() | ||
@detach() | ||
else | ||
rootView.append(this) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
__PackageName__View = require './__package-name__-view' | ||
|
||
module.exports = | ||
__packageName__View: null | ||
|
||
activate: (state) -> | ||
@__packageName__View = new __PackageName__View(state.__packageName__ViewState) | ||
|
||
deactivate: -> | ||
@__packageName__View.destroy() | ||
|
||
serialize: -> | ||
__packageName__ViewState: @__packageName__View.serialize() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
'main': './lib/__package-name__' | ||
'activationEvents': ['__package-name__:toggle'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
__PackageName__ = require '../lib/__package-name__' | ||
|
||
describe "__PackageName__", -> | ||
it "has one valid test", -> | ||
expect("life").toBe "easy" |
21 changes: 21 additions & 0 deletions
21
templates/package/spec/__package-name__-view-spec.coffee.template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
__PackageName__View = require '../lib/__package-name__-view' | ||
RootView = require 'root-view' | ||
|
||
# This spec is focused because it starts with an `f`. Remove the `f` | ||
# to unfocus the spec. | ||
# | ||
# Press meta-alt-ctrl-s to run the specs | ||
fdescribe "__PackageName__View", -> | ||
__packageName__ = null | ||
|
||
beforeEach -> | ||
window.rootView = new RootView | ||
__packageName__ = atom.activatePackage('__packageName__', immediate: true) | ||
|
||
describe "when the __package-name__:toggle event is triggered", -> | ||
it "attaches and then detaches the view", -> | ||
expect(rootView.find('.__package-name__')).not.toExist() | ||
rootView.trigger '__package-name__:toggle' | ||
expect(rootView.find('.__package-name__')).toExist() | ||
rootView.trigger '__package-name__:toggle' | ||
expect(rootView.find('.__package-name__')).not.toExist() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.__package-name__ { | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## __package-name__ Theme | ||
|
||
A short description of your theme. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import "./stylesheets/base.less"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "__package-name__", | ||
"theme": true, | ||
"version": "0.0.0", | ||
"description": "A short description of your theme", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/your/repo.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/your/repo/issues" | ||
}, | ||
"engines": { | ||
"atom": ">26.0" | ||
}, | ||
"publishConfig": { | ||
"registry": "https://atom.iriscouch.com/registry/_design/app/_rewrite" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// The ui-variables file is provided by base themes provided by Atom. | ||
// | ||
// See https://github.com/atom/atom-dark-ui/blob/master/stylesheets/ui-variables.less | ||
// for a full listing of what's available. | ||
@import "ui-variables"; | ||
|
||
.editor { | ||
color: fade(@text-color, 20%); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should really be a
package.json
and have a"name"
key set to__package-name__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to do an update to the templates in a separate pull.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, cool, sounds good.