Skip to content

Commit

Permalink
feat: add windows support (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharygolba authored Jun 24, 2016
1 parent c4ab5e0 commit 67b9940
Show file tree
Hide file tree
Showing 35 changed files with 516 additions and 359 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ dist/*
# tests
test/*

# docs
docs/*

# dependencies
node_modules/*

Expand Down
4 changes: 3 additions & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
decl

[ignore]
.*/lib/.*
.*/dist/.*
.*/docs/.*
.*/test/.*
.*/scripts/.*
.*/examples/.*
.*/node_modules/.*
.*/test/.*

[options]
esproposal.class_instance_fields=enable
Expand Down
176 changes: 171 additions & 5 deletions bin/lux
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();
}
45 changes: 0 additions & 45 deletions build/config.js

This file was deleted.

20 changes: 0 additions & 20 deletions build/config.test.js

This file was deleted.

20 changes: 20 additions & 0 deletions lib/babel-hook.js
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'
]
});
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
"lux": "bin/lux"
},
"scripts": {
"build": "npm run clean && npm run flow && npm run build-cli",
"build-cli": "rollup -c build/config.js --format=cjs --output=dist/cli.js -- src/packages/cli/index.js",
"build-test": "rollup -c build/config.test.js --format=cjs --output=test/dist/index.js",
"clean": "rm -rf dist test/dist test/test-app/dist",
"docs": "rm -rf docs && documentation build src -o docs -f html",
"flow": "flow check",
"lint": "eslint src/**/*.js",
"build": "npm run clean && npm run flow && npm run lint && npm run build:cli",
"build:cli": "node scripts/build/cli.js",
"build:docs": "documentation build src -o docs -f html",
"build:test": "node scripts/build/test.js",
"clean": "node scripts/clean.js",
"docs": "npm run clean && npm run build:docs",
"flow": "node scripts/flow.js",
"lint": "eslint .",
"start": "lux serve",
"test": "npm run build && npm run build-test && mocha --timeout 60000 test/dist/index.js"
"test": "npm run build && npm run build:test && mocha --timeout 60000 test/dist/index.js"
},
"author": "Zachary Golba",
"license": "MIT",
Expand Down Expand Up @@ -53,6 +54,7 @@
},
"devDependencies": {
"babel-core": "6.10.4",
"babel-plugin-transform-es2015-modules-commonjs": "6.10.3",
"babel-preset-lux": "1.1.0",
"chai": "3.5.0",
"documentation": "4.0.0-beta5",
Expand Down
44 changes: 44 additions & 0 deletions scripts/build/cli.js
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);
});
Loading

0 comments on commit 67b9940

Please sign in to comment.