Skip to content

Add blueprints for typescript files #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import test from 'ava';
import { appAcceptanceTest } from 'denali';

appAcceptanceTest(test);

test.todo('<%= humanizedName %>');
30 changes: 30 additions & 0 deletions blueprints/acceptance-test/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
lowerCase
} from 'lodash';
import { Blueprint, unwrap } from 'denali-cli';

/**
* Generates a model, serializer, CRUD actions, and tests for a resource
*
* @package blueprints
*/
export default class ResourceBlueprint extends Blueprint {

/* tslint:disable:completed-docs typedef */
static blueprintName = 'acceptance-test';
static description = 'Generates a blank acceptance test';
static longDescription = unwrap`
Usage: denali generate acceptance-test <name>

Generates a blank acceptance test, suitable for testing your app end-to-end with simulated HTTP
requests and responses.
`;

static params = '<name>';

locals(argv: any) {
let name = argv.name;
return { name, humanizedName: lowerCase(name) };
}

}
10 changes: 10 additions & 0 deletions blueprints/action/files/app/actions/__name__.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ApplicationAction from '<%= nesting %>/application';
import { ResponderParams } from 'denali';

export default class <%= className %>Action extends ApplicationAction {

async respond(/*{ body, params, query, headers }: ResponderParams */) {

}

}
3 changes: 3 additions & 0 deletions blueprints/action/files/test/unit/actions/__name__-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import test from 'ava';

test.todo('<%= className %>Action');
66 changes: 66 additions & 0 deletions blueprints/action/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {
upperFirst,
camelCase
} from 'lodash';
import { Blueprint, unwrap } from 'denali-cli';

/**
* Generate an new action class + tests.
*
* @package blueprints
*/
export default class ActionBlueprint extends Blueprint {

/* tslint:disable:completed-docs typedef */
static blueprintName = 'action';
static description = 'Generates a new action class & unit tests';
static longDescription = unwrap`
Usage: denali generate action <name> [options]

Generates an action with the given name (can be a deeply nested path), along with unit test
stubs.

Guides: http://denalijs.org/master/guides/application/actions/
`;

static params = '<name>';

static flags = {
method: {
description: 'The HTTP method to use for the route to this action',
default: 'post',
type: <any> 'string'
}
};

static runsInApp = true;

locals(argv: any): any {
let name = argv.name;
let levels = name.split('/').map(() => '..');
levels.pop();
let nesting: string;
if (levels.length > 0) {
nesting = levels.join('/');
} else {
nesting = '.';
}
return {
name,
className: upperFirst(camelCase(name)),
nesting
};
}

async postInstall(argv: any): Promise<void> {
let name = argv.name;
let method = argv.method || 'post';
this.addRoute(method.toLowerCase(), `/${ name }`, name);
}

async postUninstall(argv: any): Promise<void> {
let name = argv.name;
let method = argv.method || 'post';
this.removeRoute(method.toLowerCase(), `/${ name }`, name);
}
}
11 changes: 11 additions & 0 deletions blueprints/migration/files/config/migrations/__filename__.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as Knex from 'knex';

export async function up(knex: Knex) {
return knex.schema.createTable('posts', (post) => {
post.text('title');
});
}

export async function down(knex: Knex) {
return knex.schema.dropTable('posts');
}
33 changes: 33 additions & 0 deletions blueprints/migration/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Blueprint, unwrap } from 'denali-cli';
import * as moment from 'moment';
import * as assert from 'assert';

/**
* Generates a database schema migration
*
* @package blueprints
*/
export default class MigrationBlueprint extends Blueprint {

/* tslint:disable:completed-docs typedef */
static blueprintName = 'migration';
static description = 'Generates a database schema migration';
static longDescription = unwrap`
Usage: denali generate migration <name> [options]

Generates a new blank migration. The filename will include the current Unix timestamp to ensure
proper sorting and execution order when running migrations.

Guides: http://denalijs.org/master/guides/data/migrations/
`;

static params = '<name>';

locals(argv: any) {
let name = argv.name;
assert(name, 'You must provide a name for this migration');
let filename = `${ moment().format('X') }-${ name }`;
return { name, filename };
}

}
5 changes: 5 additions & 0 deletions blueprints/model/files/app/models/__name__.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// import { attr, hasOne, hasMany } from 'denali';
import ApplicationModel from './application';

export default class <%= className %>Model extends ApplicationModel {
}
9 changes: 9 additions & 0 deletions blueprints/model/files/app/serializers/__name__.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import ApplicationSerializer from './application';

export default class <%= className %>Serializer extends ApplicationSerializer {

attributes: string[] = [];

relationships: any = {};

}
3 changes: 3 additions & 0 deletions blueprints/model/files/test/unit/models/__name__-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import test from 'ava';

test.todo('<%= className %>Model');
3 changes: 3 additions & 0 deletions blueprints/model/files/test/unit/serializers/__name__-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import test from 'ava';

test.todo('<%= className %>Serializer');
35 changes: 35 additions & 0 deletions blueprints/model/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
upperFirst,
camelCase
} from 'lodash';
import { Blueprint, unwrap } from 'denali-cli';

/**
* Generates a blank model
*
* @package blueprints
*/
export default class ModelBlueprint extends Blueprint {

/* tslint:disable:completed-docs typedef */
static blueprintName = 'model';
static description = 'Generates a blank model';
static longDescription = unwrap`
Usage: denali generate model <name> [options]

Generates a blank model, along with a serializer for that model, and unit tests for both.

Guides: http://denalijs.org/master/guides/data/models/
`;

static params = '<name>';

locals(argv: any) {
let name = argv.name;
return {
name,
className: upperFirst(camelCase(name))
};
}

}
165 changes: 165 additions & 0 deletions blueprints/orm-adapter/files/app/orm-adapters/__name__.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import { ORMAdapter } from 'denali';

export default class <%= className %>Adapter extends ORMAdapter {

/**
* Find a record by id.
*/
async find(type, id, options) {
}

/**
* Find a single record that matches the given query.
*/
async queryOne(type, query, options) {
}

/**
* Find all records of this type.
*/
async all(type, options) {
}

/**
* Find all records that match the given query.
*/
async query(type, query, options) {
}

/**
* Return the id for the given model.
*/
idFor(model) {
}

/**
* Set the id for the given model.
*/
setId(model, value) {
}

/**
* Build an internal record instance of the given type with the given data. Note that this method
* should return the internal, ORM representation of the record, not a Denali Model.
*/
buildRecord(type, data, options) {
}

/**
* Return the value for the given attribute on the given record.
*/
getAttribute(model, attribute) {
}

/**
* Set the value for the given attribute on the given record.
*
* @returns returns true if set operation was successful
*/
setAttribute(model, attribute, value) {
}

/**
* Delete the value for the given attribute on the given record. The semantics of this may behave
* slightly differently depending on backend - SQL databases may NULL out the value, while
* document stores like Mongo may actually delete the key from the document (rather than just
* nulling it out)
*
* @returns returns true if delete operation was successful
*/
deleteAttribute(model, attribute) {
}

/**
* Return the related record(s) for the given relationship.
*
* @param model The model whose related records are being fetched
* @param relationship The name of the relationship on the model that should be fetched
* @param descriptor The RelationshipDescriptor of the relationship being fetch
* @param query An optional query to filter the related records by
*/
async getRelated(model, relationship, descriptor, query, options) {
}

/**
* Set the related record(s) for the given relationship. Note: for has-many relationships, the
* entire set of existing related records should be replaced by the supplied records. The old
* related records should be "unlinked" in their relationship. Whether that results in the
* deletion of those old records is up to the ORM adapter, although it is recommended that they
* not be deleted unless the user has explicitly expressed that intent.
*
* @param model The model whose related records are being altered
* @param relationship The name of the relationship on the model that should be altered
* @param descriptor The RelationshipDescriptor of the relationship being altered
* @param related The related record(s) that should be linked to the given relationship
*/
async setRelated(model, relationship, descriptor, related, options) {
}

/**
* Add related record(s) to a hasMany relationship. Existing related records should remain
* unaltered.
*
* @param model The model whose related records are being altered
* @param relationship The name of the relationship on the model that should be altered
* @param descriptor The RelationshipDescriptor of the relationship being altered
* @param related The related record(s) that should be linked to the given relationship
*/
async addRelated(model, relationship, descriptor, related, options) {
}

/**
* Remove related record(s) from a hasMany relationship. Note: The removed related records should
* be "unlinked" in their relationship. Whether that results in the deletion of those old records
* is up to the ORM adapter, although it is recommended that they not be deleted unless the user
* has explicitly expressed that intent.
*
* @param model The model whose related records are being altered
* @param relationship The name of the relationship on the model that should be altered
* @param descriptor The RelationshipDescriptor of the relationship being altered
* @param related The related record(s) that should be removed from the relationship; if not
* provided, then all related records should be removed
*/
async removeRelated(model, relationship, descriptor, related, options) {
}

/**
* Persist the supplied model.
*/
async saveRecord(model, options) {
}

/**
* Delete the supplied model from the persistent data store.
*/
async deleteRecord(model, options) {
}

/**
* Takes an array of Denali Models and defines an ORM specific model class, and/or any other ORM
* specific setup that might be required for that Model.
*/
// async defineModels(models) {
// };

/**
* Start a transaction that will wrap a test, and be rolled back afterwards. If the data store
* doesn't support transactions, just omit this method. Only one test transaction will be opened
* per process, and the ORM adapter is responsible for keeping track of that transaction so it
* can later be rolled back.
*/
// async startTestTransaction() {
// }

/**
* Roll back the test transaction.
*/
// async rollbackTestTransaction() {
// }

/**
* The current test transaction, if applicable
*/
// testTransaction;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import test from 'ava';

test.todo('<%= className %> ORM Adapter');
Loading