diff --git a/.eslintrc b/.eslintrc index 8e4039e4..c7876ed7 100644 --- a/.eslintrc +++ b/.eslintrc @@ -14,7 +14,8 @@ "before": true, "after": true, "describe": true, - "it": true + "it": true, + "external": true }, "parser": "babel-eslint", "rules": { diff --git a/.npmignore b/.npmignore index f61a83c8..bd32bede 100644 --- a/.npmignore +++ b/.npmignore @@ -7,11 +7,17 @@ # misc .git .babelrc -.eslint +.eslintrc +.editorconfig +.travis.yml *.DS_Store -gulpfile.babel.js +webpack.config.babel.js /examples +# docs +CHANGELOG.md +ROADMAP.md + # logs /log npm-debug.log diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..2d4970af --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,76 @@ +# Lux Changelog + +### 0.0.1-beta.9 (May 18, 2016) + +* [[`4002a5a64d`](https://github.com/postlight/lux/commit/4002a5a64d)] - **chore**: bump version to 0.0.1-beta.9 (#97) (Zachary Golba) +* [[`a7e54aa4da`](https://github.com/postlight/lux/commit/a7e54aa4da)] - **fix**: middleware functions added in 'beforeAction' not executing (#95) (Zachary Golba) +* [[`b16557647e`](https://github.com/postlight/lux/commit/b16557647e)] - **fix**: migration generator does not change - to _ (#96) (Zachary Golba) +* [[`81cdd2108b`](https://github.com/postlight/lux/commit/81cdd2108b)] - **fix**: remove short -db flag from lux new cmd (#93) (Zachary Golba) +* [[`71f4593fbb`](https://github.com/postlight/lux/commit/71f4593fbb)] - **refactor**: use chalk instead of colors (#92) (Zachary Golba) +* [[`786872becb`](https://github.com/postlight/lux/commit/786872becb)] - **fix**: config generator uses double quotes (#89) (Zachary Golba) +* [[`2fb314ad1b`](https://github.com/postlight/lux/commit/2fb314ad1b)] - **deps**: update bluebird to version 3.4.0 (#91) (Zachary Golba) +* [[`d95fb392c2`](https://github.com/postlight/lux/commit/d95fb392c2)] - **deps**: update babel-preset-es2015 to version 6.9.0 (#90) (Zachary Golba) +* [[`6c7b42ddad`](https://github.com/postlight/lux/commit/6c7b42ddad)] - **deps**: update babel-runtime to version 6.9.0 (#88) (Greenkeeper) +* [[`095d12a100`](https://github.com/postlight/lux/commit/095d12a100)] - **deps**: update babel-plugin-transform-runtime to version 6.9.0 (#87) (Greenkeeper) +* [[`9ef804ecd9`](https://github.com/postlight/lux/commit/9ef804ecd9)] - **deps**: update babel-core to version 6.9.0 (#86) (Greenkeeper) +* [[`23251651e9`](https://github.com/postlight/lux/commit/23251651e9)] - **chore**: add keywords to package.json (#81) (Zachary Golba) +* [[`418cadb662`](https://github.com/postlight/lux/commit/418cadb662)] - **chore**: add dependencies badge to README.md (#80) (Zachary Golba) +* [[`af3e72b73e`](https://github.com/postlight/lux/commit/af3e72b73e)] - **deps**: Update all dependencies 🌴 (#79) (Greenkeeper) +* [[`2560584a4f`](https://github.com/postlight/lux/commit/2560584a4f)] - **chore**: update roadmap to reflect changes in #65 (#78) (Zachary Golba) + +### 0.0.1-beta.8 (May 14, 2016) + +* [[`6416c6c309`](https://github.com/postlight/lux/commit/6416c6c309)] - **feat**: implement custom orm on top of knex.js (#65) (Zachary Golba) +* [[`d117376a46`](https://github.com/postlight/lux/commit/d117376a46)] - **test**: add sudo and correct g++ version for node 4+ in .travis.yml (#70) (Zachary Golba) +* [[`9a293bd117`](https://github.com/postlight/lux/commit/9a293bd117)] - **feat**: use js instead of json for config files (#67) (John-Henry Liberty) +* [[`720f0e1323`](https://github.com/postlight/lux/commit/720f0e1323)] - **test**: update travis to use npm link (#68) (John-Henry Liberty) +* [[`2fc214c045`](https://github.com/postlight/lux/commit/2fc214c045)] - **feat**: use local lux install if one exists (#66) (Zachary Golba) + +### 0.0.1-beta.7 (May 01, 2016) + +* [[`e35c430cdc`](https://github.com/postlight/lux/commit/e35c430cdc)] - **chore**: bump version to 0.0.1-beta.7 (#64) (Zachary Golba) +* [[`ec0b60b191`](https://github.com/postlight/lux/commit/ec0b60b191)] - **fix**: HEAD and OPTIONS request result in a 404 (#63) (Zachary Golba) + +### 0.0.1-beta.6 (April 28, 2016) + +* [[`4079b07269`](https://github.com/postlight/lux/commit/4079b07269)] - **chore**: bump version to 0.0.1-beta.6 (#61) (Zachary Golba) +* [[`b94c526e87`](https://github.com/postlight/lux/commit/b94c526e87)] - **fix**: serialize hasMany relationships (#60) (Zachary Golba) +* [[`2f5aa41c1a`](https://github.com/postlight/lux/commit/2f5aa41c1a)] - **chore**: test on node 6 (#58) (Zachary Golba) +* [[`e26a900e43`](https://github.com/postlight/lux/commit/e26a900e43)] - **docs**: add ROADMAP.md (#57) (Zachary Golba) + +### 0.0.1-beta.5 (April 22, 2016) + +* [[`8a21b472e0`](https://github.com/postlight/lux/commit/8a21b472e0)] - **chore**: bump version to 0.0.1-beta.5 (#55) (Zachary Golba) +* [[`909e732b9a`](https://github.com/postlight/lux/commit/909e732b9a)] - **chore**: update dependencies (#54) (Zachary Golba) +* [[`47ef4b87a8`](https://github.com/postlight/lux/commit/47ef4b87a8)] - **fix**: miss-match session key/secret error (#53) (Zachary Golba) +* [[`e70a032c0f`](https://github.com/postlight/lux/commit/e70a032c0f)] - **fix**: strings w/ commas interpreted as an array for POST/PATCH (#49) (Zachary Golba) +* [[`23da23d74d`](https://github.com/postlight/lux/commit/23da23d74d)] - **docs**: add npm package badge to README (#47) (Zachary Golba) +* [[`0788e468a6`](https://github.com/postlight/lux/commit/0788e468a6)] - **test**: add unit/integration tests (#39) (Zachary Golba) +* [[`498c951917`](https://github.com/postlight/lux/commit/498c951917)] - **chore**: add Gitter badge (#46) (The Gitter Badger) + +### 0.0.1-beta.4 (April 21, 2016) + +* [[`77dcdbe03b`](https://github.com/postlight/lux/commit/77dcdbe03b)] - **chore**: bump version to 0.0.1-beta.4 (#45) (Zachary Golba) +* [[`7c529fa235`](https://github.com/postlight/lux/commit/7c529fa235)] - **fix**: correct typo in README (#44) (Nic Young) +* [[`0880a71d89`](https://github.com/postlight/lux/commit/0880a71d89)] - **fix**: globally disable orm2 cache (Zachary Golba) +* [[`0bd7c8dfde`](https://github.com/postlight/lux/commit/0bd7c8dfde)] - **fix**: make ora a runtime dependency (#40) (Zachary Golba) +* [[`30ca0c27d5`](https://github.com/postlight/lux/commit/30ca0c27d5)] - **feat**: add spinner for long running task (#38) (Albert Yu) + +### 0.0.1-beta.3 (April 18, 2016) + +* [[`03958b98d1`](https://github.com/postlight/lux/commit/03958b98d1)] - **chore**: bump version to 0.0.1-beta.3 (#37) (Zachary Golba) +* [[`18199d6993`](https://github.com/postlight/lux/commit/18199d6993)] - Merge pull request #36 from postlight/database-missing-port (kev5873) +* [[`10b782be1f`](https://github.com/postlight/lux/commit/10b782be1f)] - **fix**: logger date incorrect (#35) (kev5873) +* [[`e9897371be`](https://github.com/postlight/lux/commit/e9897371be)] - **chore**: Link to Medium Article in Readme (#33) (Zachary Golba) + +### 0.0.1-beta.2 (April 18, 2016) + +* [[`c073253cd0`](https://github.com/postlight/lux/commit/c073253cd0)] - **fix**: listening message dispatched before workers are ready (#34) (Zachary Golba) + +### 0.0.1-beta.1 (April 17, 2016) + +* [[`5a734e79ce`](https://github.com/postlight/lux/commit/5a734e79ce)] - **fix**: shebang line not finding node on linux (#32) (Zachary Golba) + +### 0.0.1-beta (April 07, 2016) + +* [[`4a193b86d2`](https://github.com/postlight/lux/commit/4a193b86d2)] - Initial Commit (Zachary Golba) diff --git a/README.md b/README.md index 9e19d4db..a095d2a1 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ With Lux your code from before can now look like this: class PostsController extends Controller { @action index(req, res) { - return this.store.query('post', req.params); + return Post.findAll(); } } ``` diff --git a/bin/lux b/bin/lux index 39b3dba5..50fa9d00 100755 --- a/bin/lux +++ b/bin/lux @@ -1,6 +1,16 @@ #!/usr/bin/env node +'use strict'; + +const PWD = process.env.PWD; + try { - require(`${process.env.PWD}/node_modules/lux-framework/dist/packages/cli`); + const Lux = require(`${PWD}/node_modules/lux-framework`); + + if (typeof Lux.CLI === 'function') { + Lux.CLI(); + } else { + require(`${PWD}/node_modules/lux-framework/dist/packages/cli`); + } } catch (err) { - require('../dist/packages/cli'); + require('../dist').CLI(); } diff --git a/gulpfile.babel.js b/gulpfile.babel.js deleted file mode 100644 index 873a9698..00000000 --- a/gulpfile.babel.js +++ /dev/null @@ -1,38 +0,0 @@ -import gulp from 'gulp'; -import babel from 'gulp-babel'; -import mocha from 'gulp-mocha'; -import uglify from 'gulp-uglify'; - -import { rmrf } from './src/packages/fs'; - -gulp.task('clean', () => { - return rmrf('dist'); -}); - -gulp.task('build', ['clean'], () => { - return gulp.src('src/**/*.js') - .pipe(babel()) - .pipe(uglify()) - .pipe(gulp.dest('dist')); -}); - -gulp.task('test', ['build'], () => { - return gulp.src([ - 'test/helper.js', - 'test/unit/**/*.js', - 'test/integration/**/*.js' - ], { read: false }) - .pipe( - mocha({ - bail: true, - timeout: 60000, - require: [ - 'babel-core/register' - ] - }) - ) - .once('error', () => process.exit(1)) - .once('end', () => process.exit()); -}); - -gulp.task('default', ['build']); diff --git a/package.json b/package.json index fd1b0583..3ee5fd4a 100644 --- a/package.json +++ b/package.json @@ -17,10 +17,11 @@ "lux": "bin/lux" }, "scripts": { - "build": "npm run lint && gulp build", - "lint": "eslint ./src/**", + "build": "npm run lint && npm run clean && webpack", + "clean": "rm -rf dist", + "lint": "eslint src/**", "start": "lux serve", - "test": "npm run lint && gulp test" + "test": "npm run build && mocha --timeout 60000 --compilers=js:babel-core/register test/helper.js test/unit/**/*.js test/integration/**/*.js" }, "author": "Zachary Golba", "license": "MIT", @@ -35,22 +36,22 @@ "commander": "2.9.0", "inflection": "1.10.0", "moment": "2.13.0", - "ora": "0.2.3" + "ora": "0.2.3", + "source-map-support": "0.4.0" }, "devDependencies": { "babel-core": "6.9.0", "babel-eslint": "6.0.4", + "babel-loader": "6.2.4", "babel-plugin-transform-decorators-legacy": "1.3.4", "babel-plugin-transform-runtime": "6.9.0", "babel-preset-es2015": "6.9.0", "babel-preset-stage-1": "6.5.0", "chai": "3.5.0", - "gulp": "3.9.1", - "gulp-babel": "6.1.2", - "gulp-eslint": "2.0.0", - "gulp-mocha": "2.2.0", - "gulp-uglify": "1.5.3", + "eslint": "2.10.2", "isomorphic-fetch": "2.2.1", - "mocha": "2.4.5" + "json-loader": "0.5.4", + "mocha": "2.4.5", + "webpack": "1.13.1" } } diff --git a/src/index.js b/src/index.js index aa327eef..27f4ca40 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,5 @@ +export CLI from './packages/cli'; + export { Model } from './packages/database'; export Serializer from './packages/serializer'; export Controller, { action } from './packages/controller'; diff --git a/src/packages/application/index.js b/src/packages/application/index.js index 50c1357f..4fe3cb66 100644 --- a/src/packages/application/index.js +++ b/src/packages/application/index.js @@ -46,7 +46,7 @@ class Application { const store = new Database({ path, logger, - config: require(`${path}/config/database`).default + config: external(`${path}/config/database`).default }); defineProperties(this, { diff --git a/src/packages/cli/commands/db-create.js b/src/packages/cli/commands/db-create.js index f7847bb2..738e7f9f 100644 --- a/src/packages/cli/commands/db-create.js +++ b/src/packages/cli/commands/db-create.js @@ -4,7 +4,7 @@ import { connect } from '../../database'; const { env: { PWD, NODE_ENV = 'development' } } = process; export default async function dbCreate() { - require(`${PWD}/node_modules/babel-core/register`); + external(`${PWD}/node_modules/babel-core/register`); const { default: { @@ -14,7 +14,7 @@ export default async function dbCreate() { ...config } } - } = require(`${PWD}/config/database`); + } = external(`${PWD}/config/database`); if (driver === 'sqlite3') { await fs.writeFileAsync(`${PWD}/db/${database}_${NODE_ENV}.sqlite`, ''); diff --git a/src/packages/cli/commands/db-drop.js b/src/packages/cli/commands/db-drop.js index b9e6cd95..51d397a6 100644 --- a/src/packages/cli/commands/db-drop.js +++ b/src/packages/cli/commands/db-drop.js @@ -4,7 +4,7 @@ import { rmrf } from '../../fs'; const { env: { PWD, NODE_ENV = 'development' } } = process; export default async function dbDrop() { - require(`${PWD}/node_modules/babel-core/register`); + external(`${PWD}/node_modules/babel-core/register`); const { default: { @@ -14,7 +14,7 @@ export default async function dbDrop() { ...config } } - } = require(`${PWD}/config/database`); + } = external(`${PWD}/config/database`); if (driver === 'sqlite3') { await rmrf(`${PWD}/db/${database}_${NODE_ENV}.sqlite`); diff --git a/src/packages/cli/commands/db-migrate.js b/src/packages/cli/commands/db-migrate.js index 73c56e43..c7b65d30 100644 --- a/src/packages/cli/commands/db-migrate.js +++ b/src/packages/cli/commands/db-migrate.js @@ -6,11 +6,11 @@ import Logger, { sql } from '../../logger'; const { env: { PWD } } = process; export default async function dbMigrate() { - require(`${PWD}/node_modules/babel-core/register`); + external(`${PWD}/node_modules/babel-core/register`); const { connection, schema } = new Database({ path: PWD, - config: require(`${PWD}/config/database`).default, + config: external(`${PWD}/config/database`).default, logger: await Logger.create({ appPath: PWD, @@ -25,7 +25,7 @@ export default async function dbMigrate() { await Promise.all( pending.map(async (migration) => { const version = migration.replace(/^(\d{16})-.+$/g, '$1'); - let { up } = require(`${PWD}/db/migrate/${migration}`); + let { up } = external(`${PWD}/db/migrate/${migration}`); up = up(schema()); diff --git a/src/packages/cli/commands/db-rollback.js b/src/packages/cli/commands/db-rollback.js index 075cc0c5..95ca51a7 100644 --- a/src/packages/cli/commands/db-rollback.js +++ b/src/packages/cli/commands/db-rollback.js @@ -5,11 +5,11 @@ import fs from '../../fs'; const { env: { PWD } } = process; export default async function dbRollback() { - require(`${PWD}/node_modules/babel-core/register`); + external(`${PWD}/node_modules/babel-core/register`); const { connection, schema } = new Database({ path: PWD, - config: require(`${PWD}/config/database`).default, + config: external(`${PWD}/config/database`).default, logger: await Logger.create({ appPath: PWD, @@ -35,7 +35,7 @@ export default async function dbRollback() { }); if (target) { - let { down } = require(`${PWD}/db/migrate/${target}`); + let { down } = external(`${PWD}/db/migrate/${target}`); down = down(schema()); diff --git a/src/packages/cli/commands/db-seed.js b/src/packages/cli/commands/db-seed.js index d9d364b8..7f1d628c 100644 --- a/src/packages/cli/commands/db-seed.js +++ b/src/packages/cli/commands/db-seed.js @@ -5,11 +5,11 @@ import loader from '../../loader'; const { env: { PWD } } = process; export default async function dbSeed() { - require(`${PWD}/node_modules/babel-core/register`); + external(`${PWD}/node_modules/babel-core/register`); await new Database({ path: PWD, - config: require(`${PWD}/config/database`).default, + config: external(`${PWD}/config/database`).default, logger: await Logger.create({ appPath: PWD, @@ -17,5 +17,5 @@ export default async function dbSeed() { }) }).define(await loader(PWD, 'models')); - await require(`${PWD}/db/seed`).default(); + await external(`${PWD}/db/seed`).default(); } diff --git a/src/packages/cli/commands/serve.js b/src/packages/cli/commands/serve.js index e21f5e02..f7acf3af 100644 --- a/src/packages/cli/commands/serve.js +++ b/src/packages/cli/commands/serve.js @@ -13,8 +13,8 @@ const { } = process; export default async function serve(port = 4000) { - const Application = require(`${PWD}/bin/app`); - const config = require(`${PWD}/config/environments/${NODE_ENV}`).default; + const Application = external(`${PWD}/bin/app`); + const config = external(`${PWD}/config/environments/${NODE_ENV}`).default; const logger = await Logger.create({ enabled: config.log, @@ -32,7 +32,7 @@ export default async function serve(port = 4000) { logger.log(`Starting Lux Server with ${cyan(`${total}`)} worker processes`); for (let i = 0; i < total; i++) { - cluster.fork().once('message', msg => { + cluster.fork({ NODE_ENV }).once('message', msg => { if (msg === 'ready') { current++; if (current === total) { diff --git a/src/packages/cli/index.js b/src/packages/cli/index.js index f58e3430..facbb8b5 100644 --- a/src/packages/cli/index.js +++ b/src/packages/cli/index.js @@ -18,177 +18,179 @@ import { import tryCatch from '../../utils/try-catch'; import { version as VERSION } from '../../../package.json'; -const { argv, exit, env: { PWD } } = process; - -cli.version(VERSION); - -cli - .command('n ') - .alias('new') - .description('Create a new application') - .option('--database [database]', '(Default: sqlite)') - .action(async (name, { database = 'sqlite' } = {}) => { - await tryCatch(async () => { - if (VALID_DATABASES.indexOf(database) < 0) { - database = 'sqlite'; - } - - await create(name, database); - exit(0); - }, err => { - console.error(err); - exit(1); +export default function CLI() { + const { argv, exit, env: { PWD } } = process; + + cli.version(VERSION); + + cli + .command('n ') + .alias('new') + .description('Create a new application') + .option('--database [database]', '(Default: sqlite)') + .action(async (name, { database = 'sqlite' } = {}) => { + await tryCatch(async () => { + if (VALID_DATABASES.indexOf(database) < 0) { + database = 'sqlite'; + } + + await create(name, database); + exit(0); + }, err => { + console.error(err); + exit(1); + }); }); - }); - -cli - .command('t') - .alias('test') - .description('Run your app\'s tests') - .action(async (...args) => { - await tryCatch(async () => { - await test(); - exit(0); - }, err => { - console.error(err); - exit(1); + + cli + .command('t') + .alias('test') + .description('Run your app\'s tests') + .action(async (...args) => { + await tryCatch(async () => { + await test(); + exit(0); + }, err => { + console.error(err); + exit(1); + }); }); - }); - -cli - .command('s') - .alias('serve') - .description('Serve your application') - .option('-e, --environment [env]', '(Default: development)') - .option('-p, --port [port]', '(Default: 4000)') - .action(async ({ environment = 'development', port = 4000 } = {}) => { - await tryCatch(async () => { - process.env.NODE_ENV = environment; - await serve(port); - }, err => { - console.error(err); - exit(1); + + cli + .command('s') + .alias('serve') + .description('Serve your application') + .option('-e, --environment [env]', '(Default: development)') + .option('-p, --port [port]', '(Default: 4000)') + .action(async ({ environment = 'development', port = 4000 } = {}) => { + await tryCatch(async () => { + process.env.NODE_ENV = environment; + await serve(port); + }, err => { + console.error(err); + exit(1); + }); }); - }); - -cli - .command('g') - .alias('generate') - .description('Example: lux generate model user') - .option('type') - .option('name') - .action(async (type, name, ...args) => { - await tryCatch(async () => { - if (typeof type === 'string' && typeof name === 'string') { - args = args.filter(a => typeof a === 'string'); - await generate(type, name, PWD, args); - exit(0); - } else { - throw new TypeError('Invalid arguements for type or name'); - } - }, err => { - console.error(err); - exit(1); + + cli + .command('g') + .alias('generate') + .description('Example: lux generate model user') + .option('type') + .option('name') + .action(async (type, name, ...args) => { + await tryCatch(async () => { + if (typeof type === 'string' && typeof name === 'string') { + args = args.filter(a => typeof a === 'string'); + await generate(type, name, PWD, args); + exit(0); + } else { + throw new TypeError('Invalid arguements for type or name'); + } + }, err => { + console.error(err); + exit(1); + }); }); - }); - -cli - .command('d') - .alias('destroy') - .description('Example: lux destroy model user') - .option('type') - .option('name') - .action(async (type, name) => { - await tryCatch(async () => { - if (typeof type === 'string' && typeof name === 'string') { - await destroy(type, name); - exit(0); - } else { - throw new TypeError('Invalid arguements for type or name'); - } - }, err => { - console.error(err); - exit(1); + + cli + .command('d') + .alias('destroy') + .description('Example: lux destroy model user') + .option('type') + .option('name') + .action(async (type, name) => { + await tryCatch(async () => { + if (typeof type === 'string' && typeof name === 'string') { + await destroy(type, name); + exit(0); + } else { + throw new TypeError('Invalid arguements for type or name'); + } + }, err => { + console.error(err); + exit(1); + }); }); - }); - -cli - .command('db:create') - .description('Create your database schema') - .action(async () => { - await tryCatch(async () => { - await dbCreate(); - exit(0); - }, err => { - console.error(err); - exit(1); + + cli + .command('db:create') + .description('Create your database schema') + .action(async () => { + await tryCatch(async () => { + await dbCreate(); + exit(0); + }, err => { + console.error(err); + exit(1); + }); }); - }); - -cli - .command('db:drop') - .description('Drop your database schema') - .action(async () => { - await tryCatch(async () => { - await dbDrop(); - exit(0); - }, err => { - console.error(err); - exit(1); + + cli + .command('db:drop') + .description('Drop your database schema') + .action(async () => { + await tryCatch(async () => { + await dbDrop(); + exit(0); + }, err => { + console.error(err); + exit(1); + }); }); - }); - -cli - .command('db:reset') - .description('Drop your database schema and create a new schema') - .action(async () => { - await tryCatch(async () => { - await dbDrop(); - await dbCreate(); - exit(0); - }, err => { - console.error(err); - exit(1); + + cli + .command('db:reset') + .description('Drop your database schema and create a new schema') + .action(async () => { + await tryCatch(async () => { + await dbDrop(); + await dbCreate(); + exit(0); + }, err => { + console.error(err); + exit(1); + }); }); - }); - -cli - .command('db:migrate') - .description('Run database migrations') - .action(async () => { - await tryCatch(async () => { - await dbMigrate(); - exit(0); - }, err => { - console.error(err); - exit(1); + + cli + .command('db:migrate') + .description('Run database migrations') + .action(async () => { + await tryCatch(async () => { + await dbMigrate(); + exit(0); + }, err => { + console.error(err); + exit(1); + }); }); - }); - -cli - .command('db:rollback') - .description('Rollback the last database migration') - .action(async () => { - await tryCatch(async () => { - await dbRollback(); - exit(0); - }, err => { - console.error(err); - exit(1); + + cli + .command('db:rollback') + .description('Rollback the last database migration') + .action(async () => { + await tryCatch(async () => { + await dbRollback(); + exit(0); + }, err => { + console.error(err); + exit(1); + }); }); - }); - -cli - .command('db:seed') - .description('Add fixtures to your db from the seed function') - .action(async () => { - await tryCatch(async () => { - await dbSeed(); - exit(0); - }, err => { - console.error(err); - exit(1); + + cli + .command('db:seed') + .description('Add fixtures to your db from the seed function') + .action(async () => { + await tryCatch(async () => { + await dbSeed(); + exit(0); + }, err => { + console.error(err); + exit(1); + }); }); - }); -cli.parse(argv); + cli.parse(argv); +} diff --git a/src/packages/database/utils/connect.js b/src/packages/database/utils/connect.js index 65a66ddc..098666a3 100644 --- a/src/packages/database/utils/connect.js +++ b/src/packages/database/utils/connect.js @@ -31,7 +31,7 @@ export default function connect(appPath, config = {}) { } tryCatchSync(() => { - knex = require(`${appPath}/node_modules/knex`); + knex = external(`${appPath}/node_modules/knex`); }, () => { throw new ModuleMissingError('knex'); }); diff --git a/src/packages/loader/index.js b/src/packages/loader/index.js index 8f0f0708..fcf1e01f 100644 --- a/src/packages/loader/index.js +++ b/src/packages/loader/index.js @@ -3,7 +3,7 @@ import fs, { isJSFile } from '../fs'; export default async function loader(appPath, type) { if (type === 'routes') { return new Map([ - ['routes', require(`${appPath}/app/routes`).default] + ['routes', external(`${appPath}/app/routes`).default] ]); } else { return new Map( @@ -12,7 +12,7 @@ export default async function loader(appPath, type) { .map(file => { return [ file.replace('.js', ''), - require(`${appPath}/app/${type}/${file}`).default + external(`${appPath}/app/${type}/${file}`).default ]; }) ); diff --git a/test/helper.js b/test/helper.js index 23d1a068..b0dc2512 100644 --- a/test/helper.js +++ b/test/helper.js @@ -1,9 +1,10 @@ -import path from 'path'; +global.external = require; -import Logger from '../dist/packages/logger'; +import path from 'path'; +import Logger from '../src/packages/logger'; -import exec from '../dist/packages/cli/utils/exec'; -import tryCatch from '../dist/utils/try-catch'; +import exec from '../src/packages/cli/utils/exec'; +import tryCatch from '../src/utils/try-catch'; const { assign } = Object; diff --git a/webpack.config.babel.js b/webpack.config.babel.js new file mode 100644 index 00000000..841be9ac --- /dev/null +++ b/webpack.config.babel.js @@ -0,0 +1,60 @@ +import path from 'path'; +import webpack from 'webpack'; +import { readdirSync } from 'fs'; + +const externals = readdirSync('node_modules') + .filter(pkg => !/\.bin/g.test(pkg)) + .reduce((hash, pkg) => { + return { + ...hash, + [pkg]: `commonjs ${pkg}` + }; + }, {}); + +export default { + externals, + entry: './src/index.js', + target: 'node', + devtool: 'sourcemap', + + output: { + path: path.join(__dirname, 'dist'), + filename: 'index.js', + libraryTarget: 'commonjs2' + }, + + plugins: [ + new webpack.BannerPlugin('var external = require;', { + raw: true, + entryOnly: true + }), + + new webpack.BannerPlugin('require(\'source-map-support\').install();', { + raw: true, + entryOnly: true + }), + + new webpack.optimize.UglifyJsPlugin({ + compressor: { + screw_ie8: true, + warnings: false + } + }) + ], + + module: { + loaders: [ + { + test: /\.js$/, + loader: 'babel-loader', + include: path.join(__dirname, 'src'), + exclude: path.join(__dirname, 'lib') + }, + + { + test: /\.json$/, + loader: 'json-loader' + } + ] + } +};