diff --git a/src/packages/cli/commands/create.js b/src/packages/cli/commands/create.js index 13f411fa..af83df7d 100644 --- a/src/packages/cli/commands/create.js +++ b/src/packages/cli/commands/create.js @@ -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`) ]); diff --git a/src/packages/cli/commands/destroy.js b/src/packages/cli/commands/destroy.js index d45ca9bc..01bb4475 100644 --- a/src/packages/cli/commands/destroy.js +++ b/src/packages/cli/commands/destroy.js @@ -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}`)) { diff --git a/src/packages/cli/commands/generate.js b/src/packages/cli/commands/generate.js index 5e1d148b..46dfc84c 100644 --- a/src/packages/cli/commands/generate.js +++ b/src/packages/cli/commands/generate.js @@ -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'; @@ -54,6 +55,10 @@ export async function generateType(type, name, cwd, attrs = []) { case 'middleware': data = middlewareTemplate(name); break; + + case 'util': + data = utilTemplate(name); + break; } if (type === 'model') { @@ -61,7 +66,7 @@ export async function generateType(type, name, cwd, attrs = []) { } if (type !== 'model' && type !== 'migration' && type !== 'middleware' && - name !== 'application') { + type !== 'util' && name !== 'application') { name = pluralize(name); } diff --git a/src/packages/cli/templates/util.js b/src/packages/cli/templates/util.js new file mode 100644 index 00000000..d4c23034 --- /dev/null +++ b/src/packages/cli/templates/util.js @@ -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}() { + + } + `; +};