Skip to content

Commit

Permalink
refactor: use streams for Logger
Browse files Browse the repository at this point in the history
deps: update outdated packages

fix: do not check if log file exists before boot

chore: update cli templates to reflect api changes
  • Loading branch information
zacharygolba committed Jun 12, 2016
1 parent 4341f5c commit 2512e85
Show file tree
Hide file tree
Showing 44 changed files with 562 additions and 351 deletions.
1 change: 1 addition & 0 deletions build/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { join as joinPath } from 'path';

export default {
external: readdirSync(joinPath(__dirname, '../node_modules')),
sourceMap: true,

banner:
'require(\'source-map-support\').install();\n' +
Expand Down
3 changes: 3 additions & 0 deletions build/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { readdirSync } from 'fs';
import { join as joinPath } from 'path';

export default {
banner: 'require(\'source-map-support\').install();\n',
sourceMap: true,

entry: [
joinPath(__dirname, '../test/index.js'),
joinPath(__dirname, '../test/unit/**/*.js'),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"babel-plugin-transform-flow-strip-types": "6.8.0",
"babel-plugin-transform-object-rest-spread": "6.8.0",
"chai": "3.5.0",
"documentation": "4.0.0-beta4",
"documentation": "4.0.0-beta5",
"flow-bin": "0.26.0",
"isomorphic-fetch": "2.2.1",
"mocha": "2.5.3",
Expand Down
38 changes: 22 additions & 16 deletions src/packages/cli/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Ora from 'ora';
import { green } from 'chalk';

import fs from '../../fs';
import template from '../../template';

import exec from '../../../utils/exec';
import driverFor from '../utils/driver-for';
Expand All @@ -19,6 +20,9 @@ import readmeTemplate from '../templates/readme';
import licenseTemplate from '../templates/license';
import gitignoreTemplate from '../templates/gitignore';

/**
* @private
*/
export default async function create(name, database) {
const driver = driverFor(database);
const project = `${process.env.PWD}/${name}`;
Expand Down Expand Up @@ -113,22 +117,24 @@ export default async function create(name, database) {
)
]);

console.log(`
${green('create')} app/index.js
${green('create')} app/routes.js
${green('create')} bin/app.js
${green('create')} config/environments/development.js
${green('create')} config/environments/test.js
${green('create')} config/environments/production.js
${green('create')} config/database.js
${green('create')} db/migrate
${green('create')} db/seed.js
${green('create')} README.md
${green('create')} LICENSE
${green('create')} package.json
${green('create')} .babelrc
${green('create')} .gitignore
`.substr(1).trim());
const logOutput = template`
${green('create')} app/index.js
${green('create')} app/routes.js
${green('create')} bin/app.js
${green('create')} config/environments/development.js
${green('create')} config/environments/test.js
${green('create')} config/environments/production.js
${green('create')} config/database.js
${green('create')} db/migrate
${green('create')} db/seed.js
${green('create')} README.md
${green('create')} LICENSE
${green('create')} package.json
${green('create')} .babelrc
${green('create')} .gitignore
`;

console.log(logOutput.substr(0, logOutput.length - 1));

await Promise.all([
generate('serializer', 'application', project),
Expand Down
3 changes: 3 additions & 0 deletions src/packages/cli/commands/db-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { connect } from '../../database';

const { env: { PWD, NODE_ENV = 'development' } } = process;

/**
* @private
*/
export default async function dbCreate() {
const {
database: {
Expand Down
3 changes: 3 additions & 0 deletions src/packages/cli/commands/db-drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import loader from '../../loader';

const { env: { PWD, NODE_ENV = 'development' } } = process;

/**
* @private
*/
export default async function dbDrop() {
const {
database: {
Expand Down
3 changes: 3 additions & 0 deletions src/packages/cli/commands/db-migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import loader from '../../loader';

const { env: { PWD } } = process;

/**
* @private
*/
export default async function dbMigrate() {
const { database: config } = loader(PWD, 'config');
const migrations = loader(PWD, 'migrations');
Expand Down
3 changes: 3 additions & 0 deletions src/packages/cli/commands/db-rollback.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import loader from '../../loader';

const { env: { PWD } } = process;

/**
* @private
*/
export default async function dbRollback() {
const { database: config } = loader(PWD, 'config');
const migrations = loader(PWD, 'migrations');
Expand Down
3 changes: 3 additions & 0 deletions src/packages/cli/commands/db-seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import loader from '../../loader';

const { env: { PWD } } = process;

/**
* @private
*/
export default async function dbSeed() {
const { database: config } = loader(PWD, 'config');
const seed = loader(PWD, 'seed');
Expand Down
6 changes: 6 additions & 0 deletions src/packages/cli/commands/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import fs, { rmrf, exists } from '../../fs';

const { env: { PWD } } = process;

/**
* @private
*/
export async function destroyType(type, name) {
let path;

Expand Down Expand Up @@ -35,6 +38,9 @@ export async function destroyType(type, name) {
}
}

/**
* @private
*/
export default async function destroy(type, name) {
if (type === 'resource') {
const routes = (await fs.readFileAsync(`${PWD}/app/routes.js`, 'utf8'))
Expand Down
20 changes: 14 additions & 6 deletions src/packages/cli/commands/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import indent from '../utils/indent';

const { env: { PWD } } = process;

/**
* @private
*/
export async function generateType(type, name, pwd, attrs = []) {
const rl = createInterface({
input: process.stdin,
Expand Down Expand Up @@ -101,33 +104,38 @@ export async function generateType(type, name, pwd, attrs = []) {
console.log(`${red('remove')} ${oldPath}`);
}

await fs.writeFileAsync(`${pwd}/${path}`, `${data}\n`, 'utf8');
await fs.writeFileAsync(`${pwd}/${path}`, data, 'utf8');
console.log(`${green('create')} ${path}`);
} else {
await fs.writeFileAsync(`${pwd}/${path}`, `${data}\n`, 'utf8');
await fs.writeFileAsync(`${pwd}/${path}`, data, 'utf8');
console.log(`${yellow('overwrite')} ${path}`);
}
} else {
console.log(`${yellow('skip')} ${path}`);
}
} else {
await fs.writeFileAsync(`${pwd}/${path}`, `${data}\n`, 'utf8');
await fs.writeFileAsync(`${pwd}/${path}`, data, 'utf8');
console.log(`${green('create')} ${path}`);
}

rl.close();
}

/**
* @private
*/
export default async function generate(type, name, pwd = PWD, attrs = []) {
if (type === 'resource') {
const routes = (await fs.readFileAsync(`${pwd}/app/routes.js`, 'utf8'))
.split('\n')
.reduce((str, line, index, array) => {
const closeIndex = array.lastIndexOf('};');
const closeIndex = array.lastIndexOf('}');

if (index <= closeIndex) {
if (line.length && index <= closeIndex) {
str += `${line}\n`;
} if (index + 1 === closeIndex) {
}

if (index + 1 === closeIndex) {
str += `${indent(2)}resource('${pluralize(name)}');\n`;
}

Expand Down
4 changes: 2 additions & 2 deletions src/packages/cli/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export default async function serve(

const { maxWorkers: count } = cluster;

logger.log(`Starting Lux Server with ${cyan(`${count}`)} worker processes`);
logger.info(`Starting Lux Server with ${cyan(`${count}`)} worker processes`);

cluster.once('ready', () => {
logger.log(`Lux Server listening on port: ${cyan(`${port}`)}`);
logger.info(`Lux Server listening on port: ${cyan(`${port}`)}`);
});
}
7 changes: 6 additions & 1 deletion src/packages/cli/commands/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export default async function test() {
// @flow

/**
* @private
*/
export default async function test(): Promise<void> {
console.log('Coming Soon!');
}
3 changes: 3 additions & 0 deletions src/packages/cli/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @private
*/
export const VALID_DATABASES = [
'postgres',
'sqlite',
Expand Down
3 changes: 3 additions & 0 deletions src/packages/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import {
dbRollback
} from './commands/index';

/**
* @private
*/
export default function CLI() {
const {
argv,
Expand Down
20 changes: 13 additions & 7 deletions src/packages/cli/templates/application.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
// @flow
import { classify } from 'inflection';

export default (name) => {
import template from '../../template';

/**
* @private
*/
export default (name: string): string => {
name = classify(name.replace('-', '_'));

return `
import Lux from 'lux-framework';
return template`
import { Application } from 'lux-framework';
class ${name} extends Lux {
class ${name} extends Application {
}
}
export default ${name};
`.substr(1).trim();
export default ${name};
`;
};
43 changes: 23 additions & 20 deletions src/packages/cli/templates/babel-rc.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
export default (name) => {
return `
{
"plugins": [
"transform-es2015-modules-commonjs",
"transform-decorators-legacy",
"transform-class-properties",
"transform-es2015-classes",
"transform-es2015-destructuring",
"transform-es2015-parameters",
"transform-es2015-spread",
"transform-decorators",
"syntax-trailing-function-commas",
"transform-object-rest-spread",
"transform-async-to-generator",
"transform-exponentiation-operator"
]
}
`.substr(1).trim();
};
// @flow
import template from '../../template';

/**
* @private
*/
export default (): string => template`
{
"plugins": [
"external-helpers-2",
"syntax-trailing-function-commas",
"transform-decorators-legacy",
"transform-class-properties",
"transform-decorators",
"transform-es2015-destructuring",
"transform-es2015-parameters",
"transform-es2015-spread",
"transform-object-rest-spread",
"transform-async-to-generator",
"transform-exponentiation-operator"
]
}
`;
20 changes: 13 additions & 7 deletions src/packages/cli/templates/config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
export default (name, env) => {
// @flow
import template from '../../template';

/**
* @private
*/
export default (name: string, env: string): string => {
const isProdENV = env === 'production';
let keyPrefix = `${name}`;

if (!isProdENV) {
keyPrefix += `::${env}`;
}

return `
export default {
log: ${!isProdENV},
domain: 'http://localhost:4000'
};
`.substr(1).trim();
return template`
export default {
log: ${!isProdENV},
domain: 'http://localhost:4000'
};
`;
};
Loading

0 comments on commit 2512e85

Please sign in to comment.