-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4ab5e0
commit 67b9940
Showing
35 changed files
with
516 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ dist/* | |
# tests | ||
test/* | ||
|
||
# docs | ||
docs/* | ||
|
||
# dependencies | ||
node_modules/* | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,176 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
const PWD = process.cwd(); | ||
const VERSION = require('../package.json').version; | ||
|
||
try { | ||
require(`${PWD}/node_modules/lux-framework/dist/cli`).call(null); | ||
} catch (err) { | ||
require('../dist/cli').call(null); | ||
const cli = require('commander'); | ||
const path = require('path'); | ||
|
||
function exec(cmd, ...args) { | ||
cmd = require(path.join(__dirname, '..', 'dist', cmd))[cmd]; | ||
return cmd.apply(null, args); | ||
} | ||
|
||
function exit(code) { | ||
if (typeof code !== 'number') { | ||
code = 0; | ||
} | ||
|
||
process.exit(code); | ||
} | ||
|
||
function rescue(err) { | ||
console.error(err); | ||
exit(1); | ||
} | ||
|
||
cli.version(VERSION); | ||
|
||
cli | ||
.command('n <name>') | ||
.alias('new') | ||
.description('Create a new application') | ||
.option( | ||
'--database [database]', | ||
'Database driver', | ||
/^(postgres|sqlite|mysql|mariadb|oracle)$/i, | ||
'sqlite' | ||
) | ||
.action((name, { database }) => { | ||
exec('create', name, database) | ||
.then(exit) | ||
.catch(rescue); | ||
}); | ||
|
||
cli | ||
.command('t') | ||
.alias('test') | ||
.description('Run your app\'s tests') | ||
.action(() => { | ||
exec('test') | ||
.then(exit) | ||
.catch(rescue); | ||
}); | ||
|
||
cli | ||
.command('b') | ||
.alias('build') | ||
.description('Build your application') | ||
.option('--use-weak', 'Use weak mode') | ||
.action(({ useWeak }) => { | ||
exec('build', !useWeak) | ||
.then(exit) | ||
.catch(rescue); | ||
}); | ||
|
||
cli | ||
.command('s') | ||
.alias('serve') | ||
.description('Serve your application') | ||
.option('-e, --environment [env]', '(Default: development)', 'development') | ||
.option('-p, --port [port]', '(Default: 4000)', parseInt) | ||
.option('--hot', 'Reload when a file change is detected') | ||
.option('--use-weak', 'Use weak mode') | ||
.action(({ hot, port, environment, useWeak }) => { | ||
const useStrict = !useWeak; | ||
|
||
process.env.PORT = port; | ||
process.env.NODE_ENV = environment; | ||
|
||
exec('build', useStrict) | ||
.then(() => exec('serve', { hot, useStrict })) | ||
.catch(rescue); | ||
}); | ||
|
||
cli | ||
.command('g <type> <name> [attrs...]') | ||
.alias('generate') | ||
.description('Example: lux generate model user') | ||
.action((type, name, attrs) => { | ||
exec('generate', { type, name, attrs }) | ||
.then(exit) | ||
.catch(rescue); | ||
}); | ||
|
||
cli | ||
.command('d') | ||
.alias('destroy <type> <name>') | ||
.description('Example: lux destroy model user') | ||
.action((type, name) => { | ||
exec('destroy', { type, name }) | ||
.then(exit) | ||
.catch(rescue); | ||
}); | ||
|
||
cli | ||
.command('db:create') | ||
.description('Create your database schema') | ||
.option('--use-weak', 'Use weak mode') | ||
.action(({ useWeak }) => { | ||
exec('build', !useWeak) | ||
.then(() => exec('dbcreate')) | ||
.then(exit) | ||
.catch(rescue); | ||
}); | ||
|
||
cli | ||
.command('db:drop') | ||
.description('Drop your database schema') | ||
.option('--use-weak', 'Use weak mode') | ||
.action(({ useWeak }) => { | ||
exec('build', !useWeak) | ||
.then(() => exec('dbdrop')) | ||
.then(exit) | ||
.catch(rescue); | ||
}); | ||
|
||
cli | ||
.command('db:reset') | ||
.description('Drop your database schema and create a new schema') | ||
.option('--use-weak', 'Use weak mode') | ||
.action(({ useWeak }) => { | ||
exec('build', !useWeak) | ||
.then(() => exec('dbdrop')) | ||
.then(() => exec('dbcreate')) | ||
.then(exit) | ||
.catch(rescue); | ||
}); | ||
|
||
cli | ||
.command('db:migrate') | ||
.description('Run database migrations') | ||
.option('--use-weak', 'Use weak mode') | ||
.action(({ useWeak }) => { | ||
exec('build', !useWeak) | ||
.then(() => exec('dbmigrate')) | ||
.then(exit) | ||
.catch(rescue); | ||
}); | ||
|
||
cli | ||
.command('db:rollback') | ||
.description('Rollback the last database migration') | ||
.option('--use-weak', 'Use weak mode') | ||
.action(({ useWeak }) => { | ||
exec('build', !useWeak) | ||
.then(() => exec('dbrollback')) | ||
.then(exit) | ||
.catch(rescue); | ||
}); | ||
|
||
cli | ||
.command('db:seed') | ||
.description('Add fixtures to your db from the seed function') | ||
.option('--use-weak', 'Use weak mode') | ||
.action(({ useWeak }) => { | ||
exec('build', !useWeak) | ||
.then(() => exec('dbseed')) | ||
.then(exit) | ||
.catch(rescue); | ||
}); | ||
|
||
cli.parse(process.argv); | ||
|
||
if (!cli.args.length) { | ||
cli.help(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
// Require this module to use code in the /src dir prior to transpilation. | ||
require('babel-register')({ | ||
babelrc: false, | ||
|
||
plugins: [ | ||
'syntax-flow', | ||
'syntax-trailing-function-commas', | ||
'transform-async-to-generator', | ||
'transform-class-properties', | ||
'transform-es2015-destructuring', | ||
'transform-es2015-parameters', | ||
'transform-es2015-spread', | ||
'transform-exponentiation-operator', | ||
'transform-flow-strip-types', | ||
'transform-object-rest-spread', | ||
'transform-es2015-modules-commonjs' | ||
] | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
|
||
require('../../lib/babel-hook'); | ||
|
||
const path = require('path'); | ||
const rollup = require('rollup').rollup; | ||
|
||
const fs = require('../../src/packages/fs').default; | ||
const dist = path.join(__dirname, '..', '..', 'dist'); | ||
const config = require('./config'); | ||
const commands = path.join( | ||
__dirname, | ||
'..', | ||
'..', | ||
'src', | ||
'packages', | ||
'cli', | ||
'commands' | ||
); | ||
|
||
fs.readdirAsync(commands) | ||
.then(files => { | ||
return Promise.all( | ||
files.map(file => { | ||
const cmdConfig = { | ||
rollup: Object.assign({}, config.rollup, { | ||
entry: path.join(commands, file), | ||
}), | ||
|
||
bundle: Object.assign({}, config.bundle, { | ||
dest: path.join(dist, file) | ||
}) | ||
}; | ||
|
||
return rollup(cmdConfig.rollup).then(bundle => { | ||
return bundle.write(cmdConfig.bundle); | ||
}); | ||
}) | ||
); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
Oops, something went wrong.