Skip to content
Permalink
Browse files

Various improvements (#3)

- Upgrade the generator system
- Fix name generation
- Simplify URL parsing
- Remove `alfred-` from bundleID
  • Loading branch information...
sindresorhus authored and SamVerschueren committed Feb 8, 2017
1 parent c4c51d8 commit 18814fd50635e1817c20c04207f7babe2e59bf84
Showing with 31 additions and 38 deletions.
  1. +15 −11 app/index.js
  2. +3 −6 app/templates/_package.json
  3. +1 −1 app/templates/readme.md
  4. +7 −14 app/utils.js
  5. +2 −3 package.json
  6. +1 −1 readme.md
  7. +2 −2 test.js
@@ -2,20 +2,27 @@
const superb = require('superb');
const normalizeUrl = require('normalize-url');
const humanizeUrl = require('humanize-url');
const yeoman = require('yeoman-generator');
const Generator = require('yeoman-generator');
const _s = require('underscore.string');
const moduleName = require('./module-name');
const utils = require('./utils');

module.exports = class extends yeoman.Base {

module.exports = class extends Generator {
init() {
return this.prompt([
{
name: 'moduleName',
message: 'What do you want to name your module?',
default: _s.slugify(this.appname),
filter: x => moduleName.slugify(x)
filter: x => {
let name = moduleName.slugify(x);

if (!/^alfred-/.test(name)) {
name = `alfred-${name}`;
}

return name;
}
},
{
name: 'moduleDescription',
@@ -58,21 +65,18 @@ module.exports = class extends yeoman.Base {
filter: x => normalizeUrl(x)
}
]).then(props => {
const repoName = moduleName.repoName(props.moduleName);

const alfredName = props.moduleName.replace(/^alfred-/, '');
const alfredBundleId = utils.bundleId(props);
props.alfredName = props.moduleName.replace(/^alfred-/, '');

const tpl = {
moduleName: props.moduleName,
moduleDescription: props.moduleDescription,
alfredName,
alfredBundleId,
alfredName: props.alfredName,
alfredBundleId: utils.bundleId(props),
alfredCategory: props.alfredCategory,
alfredKeyword: props.alfredKeyword,
alfredTitle: props.alfredTitle,
githubUsername: this.options.org || props.githubUsername,
repoName,
repoName: moduleName.repoName(props.moduleName),
name: this.user.git.name(),
email: this.user.git.email(),
website: props.website,
@@ -25,17 +25,14 @@
"keywords": [
"alfred",
"workflow",
""
"alfy"
],
"dependencies": {
"alfy": "^0.6.0"
},
"devDependencies": {
"alfy-test": "^0.3.0",
"ava": "^0.15.2",
"xo": "^0.16.0"
},
"xo": {
"esnext": true
"ava": "^0.18.0",
"xo": "^0.17.0"
}
}
@@ -6,7 +6,7 @@
## Install

```
$ npm install -g <%= moduleName %>
$ npm install --global <%= moduleName %>
```

*Requires [Node.js](https://nodejs.org) 4+ and the Alfred [Powerpack](https://www.alfredapp.com/powerpack/).*
@@ -2,37 +2,30 @@
const url = require('url');
const uuid = require('uuid');

const uuids = Object.create(null);
const uuids = new Set();

exports.generateUuid = key => {
if (key && uuids[key]) {
return uuids[key];
if (key && uuids.has(key)) {
return key;
}

const id = uuid.v4().toUpperCase();

if (key) {
uuids[key] = id;
uuids.add(id);
}

return id;
};

exports.bundleId = props => {
let website = props.website;

if (!/^https?:\/\//.test(website)) {
// Make sure website starts with the protocol. `Url.parse` could not handle `test.com` for instance.
website = `http://${website}`;
}

const parsed = url.parse(website);
const parsed = url.parse(props.website);

if (parsed.hostname === 'github.com') {
return `com.${props.githubUsername.toLowerCase()}.${props.moduleName}`;
return `com.${props.githubUsername.toLowerCase()}.${props.alfredName}`;
}

// Reverse hostname
const parts = parsed.hostname.split('.');
return `${parts[1]}.${parts[0]}.${props.moduleName}`;
return `${parts[1]}.${parts[0]}.${props.alfredName}`;
};
@@ -41,8 +41,8 @@
"normalize-url": "^1.6.0",
"superb": "^1.3.0",
"underscore.string": "^3.3.4",
"uuid": "^2.0.2",
"yeoman-generator": "^0.24.1"
"uuid": "^3.0.1",
"yeoman-generator": "^1.1.0"
},
"devDependencies": {
"ava": "*",
@@ -53,7 +53,6 @@
"yeoman-test": "^1.4.0"
},
"xo": {
"esnext": true,
"ignores": [
"app/templates/**"
]
@@ -6,7 +6,7 @@
## Install

```
$ npm install --save generator-alfred
$ npm install --global generator-alfred
```


@@ -7,7 +7,7 @@ import tempfile from 'tempfile';

test.beforeEach(async t => {
await pify(helpers.testDirectory)(tempfile());
t.context.generator = helpers.createGenerator('alfred', [path.join(__dirname, '/app')], null, {skipInstall: true});
t.context.generator = helpers.createGenerator('alfred', [path.join(__dirname, 'app')], null, {skipInstall: true});
});

test.serial('generates expected files', async t => {
@@ -16,7 +16,7 @@ test.serial('generates expected files', async t => {
helpers.mockPrompt(generator, {
moduleName: 'test',
githubUsername: 'test',
website: 'test.com'
website: 'http://test.com'
});

await pify(generator.run.bind(generator))();

0 comments on commit 18814fd

Please sign in to comment.
You can’t perform that action at this time.