Skip to content

Commit

Permalink
feat: Fix a lot of test a lot of code added and some deleted
Browse files Browse the repository at this point in the history
Remove dead code and debuging code. Refactor some code to mathc latest koaton. Enable serve test.
All working locally.
  • Loading branch information
gerard2perez committed Feb 1, 2017
1 parent 6a45baa commit a9d3d93
Show file tree
Hide file tree
Showing 51 changed files with 94,336 additions and 548 deletions.
6 changes: 5 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ insert_final_newline = true
[*.md]
trim_trailing_whitespace = true

[*.yml]
indent_style = space
indent_size = 2

[*.json]
indent_style = space
indent_size = 2

[.*]
[.eslintrc]
indent_style = space
indent_size = 2
18 changes: 9 additions & 9 deletions koaton
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env node
process.env.NODE_ENV = process.argv.indexOf('-p') > -1 || process.argv.indexOf('--production') > -1 ? 'production' : 'development';
process.env.port = parseInt(process.argv[process.argv.indexOf('--port') + 1], 10) || 62626;
require('babel-register')({
babelrc: false,
plugins: [
'babel-plugin-transform-koaton-es6-modules',
'babel-plugin-transform-koa2-async-to-generator'
]
});
require('./src');
// require('./lib');
// require('babel-register')({
// babelrc: false,
// plugins: [
// 'babel-plugin-transform-koaton-es6-modules',
// 'babel-plugin-transform-koa2-async-to-generator'
// ]
// });
// require('./src');
require('./lib');
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"mocha": "^3.2.0",
"npm-run-all": "^3.1.2",
"nyc": "^10.0.0",
"ps-tree": "^1.1.0",
"semantic-release": "^6.3.2"
},
"config": {
Expand Down
9 changes: 2 additions & 7 deletions src/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@ export default class Command {
}
Action (fn) {
let that = this;
console.log(fn.constructor.name);
this.action = function (...args) {
if (args[args.length - 1].H) {
console.log(that.Help);
return 0;
}
if (fn.constructor.name === 'GeneratorFunction') {

} else {
return fn.apply(this, args);
return Promise.resolve(0);
}
return fn.apply(this, args);
};
return this;
}
Expand Down
11 changes: 1 addition & 10 deletions src/commands/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ const handleGenerate = async function handleGenerate (driver, options) {
delete require.cache[path.resolve() + '/package.json'];
console.log(`${driver}@${require(path.resolve() + '/package.json').dependencies[adapters[driver].package]} installed`);
}
console.log(utils.compile(template, {
adapter: driver,
driver: adapters[driver].package,
user: options.user || '',
password: options.pass || '',
host: options.host || 'localhost',
port: options.port || adapters[driver].port,
application: options.db || path.basename(process.cwd())
}));
let adapterCFG = JSON.parse(utils.compile(template, {
adapter: driver,
driver: adapters[driver].package,
Expand Down Expand Up @@ -82,7 +73,7 @@ export default (new Command(
if (!driver && options.list) {
renderdriverlist(installed, available);
} else if (driver && !adapters[driver]) {
console.log(' The driver you especied is not available please check: '.yellow+'\n');
console.log(' The driver you especied is not available please check: '.yellow + '\n');
renderdriverlist(installed, available);
} else if (options.uninstall) {
await utils.shell(`Uninstalling ${adapters[driver].green}`, ['npm', 'uninstall', adapters[driver].package], process.cwd());
Expand Down
37 changes: 31 additions & 6 deletions src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const compressImages = function (files, dest) {
});
};
const buildcss = async function buildBundleCSS (target, bundle, development, onlypaths, logger) {
let error = [];
process.stdout.write(`Building ${target} `);
let start = process.hrtime();
const ITEM = scfg.bundles[target] || new BundleItem(target, []);
Expand Down Expand Up @@ -103,10 +104,13 @@ const buildcss = async function buildBundleCSS (target, bundle, development, onl
}
} else if (file.indexOf('.css')) {
watchinFiles[index + target] = glob(file);
if (watchinFiles[index + target].length === 0) {
error.push(`${__nok.red} Pattern ${file} ${'not found'.red}`);
}
const concatCSS = new Concat(true, path.join('css', index + target + '.css'), '\n');
if (!development || !onlypaths) {
for (const url in watchinFiles[index + target]) {
concatCSS.add(target, fs.readFileSync(watchinFiles[index + target][url]));
for (const url of watchinFiles[index + target]) {
concatCSS.add(target, fs.readFileSync(url));
}
}
if (development && !onlypaths) {
Expand All @@ -131,9 +135,13 @@ const buildcss = async function buildBundleCSS (target, bundle, development, onl
utils.writeuseslog = undefined;
let [seconds, nanoseconds] = process.hrtime(start);
console.log(`${(seconds * 1000) + Math.ceil(nanoseconds / 1e6)} ms`);
if (error.length > 0) {
console.log(error.join('\n'));
}
return watchinFiles;
};
const buildjs = function buildJS (target, bundle, development, onlypaths, logger) {
let error = [];
return new Promise(function (resolve) {
process.stdout.write(`Building ${target} `);
let start = process.hrtime();
Expand All @@ -142,7 +150,11 @@ const buildjs = function buildJS (target, bundle, development, onlypaths, logger
utils.writeuseslog = logger;
let AllFiles = [];
for (const pattern of bundle) {
AllFiles = AllFiles.concat(glob(ProyPath(pattern)));
let bundle = glob(ProyPath(pattern));
if (bundle.length === 0) {
error.push(`${__nok.red} Pattern ${pattern} ${'not found'.red}`);
}
AllFiles = AllFiles.concat(bundle);
}
process.stdout.write(`(${AllFiles.length} files) `);
if (onlypaths) {
Expand Down Expand Up @@ -174,6 +186,9 @@ const buildjs = function buildJS (target, bundle, development, onlypaths, logger
scfg.bundles.remove(ITEM).add(ITEM);
let [seconds, nanoseconds] = process.hrtime(start);
console.log(`${(seconds * 1000) + Math.ceil(nanoseconds / 1e6)} ms`);
if (error.length > 0) {
console.log(error.join('\n'));
}
resolve(AllFiles);
});
};
Expand Down Expand Up @@ -241,21 +256,22 @@ const postbuildember = async function postBuildEmber (application, options) {
const transformlinks = function transformlinks (text, expresion) {
return text.match(expresion).join('\n')
.replace(/="[^=]*?assets/igm, `="/${options.directory}/assets`);
// .replace(new RegExp(application + '/', 'gm'), options.directory + '/')
};
text = utils.compile(indextemplate, {
title: options.title || application,
layout: options.layout || 'main',
path: options.directory,
mount: options.mount,
appName: application,
app_name: application,
meta: text.match(meta)[0],
cssfiles: transformlinks(text, links),
jsfiles: transformlinks(text, scripts)
});
for (const file of glob(ProyPath('public', options.directory, '*.*'))) {
fs.unlink(file);
}
await utils.mkdir(ProyPath('views', 'ember_apps'), -1);
return utils.write(ProyPath('views', 'ember_apps', `${options.directory}.handlebars`), text, 1);
// }
};

const buildCSS = co.wrap(buildcss);
Expand Down Expand Up @@ -303,6 +319,10 @@ export default (new Command(
await buildJS(key, configuration.bundles[key], options.prod === 'development');
}
}
for (const postember of glob('events/pre_ember_build.js').concat(glob('koaton_modules/**/pre_ember_build.js'))) {
let guest = path.dirname(postember);
await require(ProyPath(postember)).default(ProyPath(guest, '..'));
}
const embercfg = configuration.ember;
for (const emberAPP in embercfg) {
let configuration = {
Expand All @@ -315,6 +335,11 @@ export default (new Command(
await buildEmber(emberAPP, configuration);
await postBuildEmber(emberAPP, configuration);
}

for (const postember of glob('events/post_ember_build.js').concat(glob('koaton_modules/**/post_ember_build.js'))) {
let guest = path.dirname(postember);
await require(ProyPath(postember)).default(ProyPath(guest, '..'));
}
spinner.start(50, 'Compressing Images', undefined, process.stdout.columns);
await compressImages([path.join('assets', 'img', '*.{jpg,png}')], path.join('public', 'img'));
spinner.end('Images Compressed'.green);
Expand Down
119 changes: 0 additions & 119 deletions src/commands/forever.js

This file was deleted.

3 changes: 1 addition & 2 deletions src/commands/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
import read from '../utils/.include_base';

import read from '../utils/importindex';
module.exports = read(__dirname);
5 changes: 5 additions & 0 deletions src/commands/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default (new Command(__filename, description))
}
let model = scfg.database[modelname] || scfg.database.add(modelname, fields)[modelname],
override = await utils.challenge(ProyPath('models', `${modelname.toLowerCase()}.js`), `The model ${modelname.green} already exits,do you want to override it?`, options.force);
/* istanbul ignore else */
if (override) {
utils.write(ProyPath('models', modelname + '.js'), model.toCaminte());
if (options.rest) {
Expand All @@ -57,11 +58,13 @@ export default (new Command(__filename, description))
}
}
if (override && options.ember) {
/* istanbul ignore next */
if (!fs.existsSync(ProyPath('/ember/', options.ember))) {
console.log(`The app ${options.ember} does not exists.`.red);
return 1;
}
utils.write(ProyPath('ember', options.ember, 'app', 'models', modelname + '.js'), model.toEmberModel());
/* istanbul ignore else */
if (options.rest) {
utils.write(ProyPath('ember', options.ember, 'app', 'controllers', `${modelname}.js`), model.toCRUDTable());
utils.write(
Expand All @@ -71,12 +74,14 @@ export default (new Command(__filename, description))
let router = await utils.read(path.join(process.cwd(), 'ember', options.ember, 'app', 'router.js'), {
encoding: 'utf-8'
});
/* istanbul ignore else */
if (router.indexOf(`this.route('${modelname}')`) === -1) {
router = router.replace(/Router.map\(.*?function\(.*?\).*?{/igm, `Router.map(function() {\n\tthis.route('${modelname}');\n`);
utils.write(ProyPath('ember', options.ember, 'app', 'router.js'), router, 1);
}
}
}
/* istanbul ignore else */
if (scfg.database.has(model)) {
scfg.database.remove(model);
}
Expand Down
Loading

0 comments on commit a9d3d93

Please sign in to comment.