Skip to content

Commit

Permalink
Feat: Added generator for utils (#262)
Browse files Browse the repository at this point in the history
* Feat: Added generator for middleware

* Feat: Added generator for utils

* Fix: Quoting quotes inside config template (#260)

* feat: added destroy command for middleware

* added util to the destroy command

* release: 1.0.0-rc.3 (#264)
  • Loading branch information
adampash authored Aug 4, 2016
1 parent 2ead12a commit d0f4f2b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/packages/cli/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export async function create(name, database) {
fs.mkdirAsync(`${project}/app/serializers`),
fs.mkdirAsync(`${project}/app/controllers`),
fs.mkdirAsync(`${project}/app/middleware`),
fs.mkdirAsync(`${project}/app/utils`),
fs.mkdirAsync(`${project}/config/environments`),
fs.mkdirAsync(`${project}/db/migrate`)
]);
Expand Down
4 changes: 4 additions & 0 deletions src/packages/cli/commands/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export async function destroyType(type, name) {
case 'middleware':
path = `app/${type}/${name}.js`;
break;

case 'util':
path = `app/${pluralize(type)}/${name}.js`;
break;
}

if (await exists(`${CWD}/${path}`)) {
Expand Down
7 changes: 6 additions & 1 deletion src/packages/cli/commands/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import controllerTemplate from '../templates/controller';
import emptyMigrationTemplate from '../templates/empty-migration';
import modelMigrationTemplate from '../templates/model-migration';
import middlewareTemplate from '../templates/middleware';
import utilTemplate from '../templates/util';

import indent from '../utils/indent';

Expand Down Expand Up @@ -54,14 +55,18 @@ export async function generateType(type, name, cwd, attrs = []) {
case 'middleware':
data = middlewareTemplate(name);
break;

case 'util':
data = utilTemplate(name);
break;
}

if (type === 'model') {
name = singularize(name);
}

if (type !== 'model' && type !== 'migration' && type !== 'middleware' &&
name !== 'application') {
type !== 'util' && name !== 'application') {
name = pluralize(name);
}

Expand Down
18 changes: 18 additions & 0 deletions src/packages/cli/templates/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @flow
import { camelize } from 'inflection';

import underscore from '../../../utils/underscore';
import template from '../../template';

/**
* @private
*/
export default (name: string): string => {
name = camelize(underscore(name), true);

return template`
export default function ${name}() {
}
`;
};

0 comments on commit d0f4f2b

Please sign in to comment.