Skip to content

Commit

Permalink
fix: Fixing test to make it compatible with koaton 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gerard2perez committed Jan 18, 2017
1 parent 885fb90 commit 0042101
Show file tree
Hide file tree
Showing 49 changed files with 268 additions and 353 deletions.
1 change: 0 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{

"env": {
"koaton": {
"plugins": [
Expand Down
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ parserOptions:
ecmaVersion: 2017

globals:
describe: true
it: true
ProyPath: true
scfg: true
readDir: true
Expand All @@ -19,6 +21,7 @@ globals:
__nok: true
skipshell: true
cleanString: true
configuration: true

rules:
one-var: [0, never]
Expand Down
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ env:
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- ubuntu-toolchain-r-test
packages:
- gcc-4.8
- g++-4.8
- nginx
- gcc-4.8
- g++-4.8
- nginx
cache:
directories:
- node_modules
Expand Down
18 changes: 9 additions & 9 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if you write `koaton` `koaton -h` in your terminal you will get this output.
--pass --pass <password> Password to login in your database default is ''. Use this with -g
```

## koaton build <config_file> [options] <a name="build"/>
## koaton build <configFile> [options] <a name="build"/>
> Make bundles of your .js .scss .css files and output to public folder.
Default value is ./config/bundles.js

Expand All @@ -40,7 +40,7 @@ if you write `koaton` `koaton -h` in your terminal you will get this output.
-p --prod builds for production
```

## koaton ember <app_name> [options] <a name="ember"/>
## koaton ember <appName> [options] <a name="ember"/>
> Creates a new ember app with the especified named.
*[options]*:
Expand Down Expand Up @@ -75,12 +75,12 @@ if you write `koaton` `koaton -h` in your terminal you will get this output.
-h -h Show the help for this command
```

## koaton model <name> <fields|linkaction> <[destmodel]> <as> <[relation_property]> <[foreign_key]> [options] <a name="model"/>
> Creates a new model. fields must be sourrounded by "".
Fields syntax:
field_name:type [ mongoose | mysql | postgres | redis | sqlite3 | couchdb | neo4j | riak | firebird | tingodb | rethinkdb | mongo | couch | mariadb ]
example:
koaton model User "active:integer name email password note:text created:date"
## koaton model <name> <fields|linkaction> <[destmodel]> <as> <[relationProperty]> <[foreignKey]> [options] <a name="model"/>
> Creates a new model. fields must be sourrounded by ''.
Fields syntax:
field_name:type [ mongoose | mysql | postgres | redis | sqlite3 | couchdb | neo4j | riak | firebird | tingodb | rethinkdb | mongo | couch | mariadb ]
example:
koaton model User 'active:integer name email password note:text created:date'
koaton model User hasmany Phone as Phones
koaton model User hasmany Phone phones phoneId

Expand All @@ -101,7 +101,7 @@ koaton model User hasmany Phone phones phoneId
-h -h Show the help for this command
```

## koaton new <app_name> [options] <a name="new"/>
## koaton new <AppName> [options] <a name="new"/>
> Creates a new koaton aplication.
*[options]*:
Expand Down
7 changes: 4 additions & 3 deletions koaton
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/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('./lib');
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('./lib');
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "koaton-cli",
"version": "0.0.0-semantic-release",
"version": "0.0.0-development",
"description": "Koaton is a CLI tool that provides a nice starting point for full stack JavaScript Web development with Koa, Ember, and Node.js along with CaminateJS and WebSockets.",
"main": "./koaton",
"scripts": {
Expand All @@ -16,8 +16,8 @@
"cover:watch": "npm run cover & chokidar src test -c \"cls & npm run cover\"",
"cover:live": "npm-run-all --parallel cover:watch cover:reload",
"codeclimate": "codeclimate analyze -f html -e duplication > duplication.html",
"commit": "git-cz",
"commit:push": "git-cz & git push",
"commit": "git add -A & git-cz",
"commit:push": "npm run commit & git push",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"tandlint": "npm-run-all --parallel export:live eslint:live",
"make-help": "node help2md.js"
Expand Down Expand Up @@ -50,7 +50,8 @@
"lib",
"README.md",
"LICENSE.md",
"commands.md"
"commands.md",
"koaton"
],
"author": "Gerardo Pérez Pérez <gerard2perez@outlook.com>",
"license": "MPL-2.0",
Expand Down Expand Up @@ -96,6 +97,8 @@
"eslint-config-airbnb-base": "^11.0.0",
"eslint-config-happiness": "^5.3.1",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^2.0.1",
"ghooks": "^1.3.2",
"mocha": "^3.2.0",
"npm-run-all": "^3.1.2",
Expand Down
12 changes: 11 additions & 1 deletion src/commands/adapter.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import * as path from 'path';
import 'colors';
import Command from '../Command';
import { adapters, template } from '../support/Adapters';
import adapters from '../support/Adapters';
import utils from '../utils';
const template = '{"driver": "{{driver}}","user": "{{user}}","database": "{{application}}","password": "{{password}}","port": {{port}},"host": "{{host}}","pool": false,"ssl": false}';

const handleGenerate = async function handleGenerate (driver, options) {
if (!options.generate) {
await utils.shell(`Installing ${adapters[driver].package.green}`, ['npm', 'i', adapters[driver].package, '--save'], process.cwd());
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
8 changes: 4 additions & 4 deletions src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ const getInflections = async function getInflections (appName) {
uncontable = (inflections.uncountable || []).map((inflection) => {
return `/${inflection}/`;
});
utils.render(TemplatePath('emberAPPs', 'inflector.js'), ProyPath('ember', appName, 'app', 'initializers', 'inflector.js'), {
utils.render(TemplatePath('ember_apps', 'inflector.js'), ProyPath('ember', appName, 'app', 'initializers', 'inflector.js'), {
irregular: JSON.stringify(irregular),
uncontable: JSON.stringify(uncontable)
});
Expand Down Expand Up @@ -243,7 +243,7 @@ const postBuildEmber = async function postBuildEmber (application, options) {
let text = await utils.read(ProyPath('public', options.directory, 'index.html'), {
encoding: 'utf-8'
}),
indextemplate = await utils.read(TemplatePath('emberAPPs', 'index.handlebars'), 'utf-8'),
indextemplate = await utils.read(TemplatePath('ember_apps', 'index.handlebars'), 'utf-8'),
meta = new RegExp(`<meta ?name='${emberinternalname}.*' ?content='.*' ?/>`);

const links = new RegExp("<link rel='stylesheet' href='.*?assets/.*.css.*>", 'gm');
Expand All @@ -263,8 +263,8 @@ const postBuildEmber = async function postBuildEmber (application, options) {
cssfiles: transformlinks(text, links),
jsfiles: transformlinks(text, scripts)
});
await utils.mkdir(ProyPath('views', 'emberAPPs'), -1);
return utils.write(ProyPath('views', 'emberAPPs', `${options.directory}.handlebars`), text, 1);
await utils.mkdir(ProyPath('views', 'ember_apps'), -1);
return utils.write(ProyPath('views', 'ember_apps', `${options.directory}.handlebars`), text, 1);
// }
};
export {
Expand Down
8 changes: 2 additions & 6 deletions src/commands/ember.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,12 @@ export default (new Command(__filename, 'Creates a new ember app with the especi
}) &&
await buildcmd.postBuildEmber(appName, embercfg));
} else {
const connections = require(ProyPath('config', 'connections'));
const connection = require(ProyPath('config', 'models')).connection;
const port = require(ProyPath('config', 'server')).port;
const host = connections[connection].host;
options.mount = path.join('/', options.mount || '').replace(/\\/igm, '/');
res = await newproyect(appName, options);
res &= !((await utils.mkdir(ProyPath('ember', appName, 'app', 'adapters'))) &&
utils.render(TemplatePath('ember_apps', 'adapter.js'), ProyPath('ember', appName, 'app', 'adapters', 'application.js'), {
localhost: host,
port: port
localhost: configuration.server.host,
port: configuration.server.port
}));
var emberjs = require(ProyPath('config', 'ember.js'));
emberjs[appName] = {
Expand Down
32 changes: 15 additions & 17 deletions src/commands/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@ const setupInit = async function setupInit () {
};
const setupConfig = async function setupConfig (app) {
await utils.mkdir(Project('config'));
utils.render(TemplatePath('config/models.js'), Project('config/models.js'));
utils.render(TemplatePath('config/views.js'), Project('config/views.js'));
utils.render(TemplatePath('config/inflections.js'), Project('config/inflections.js'));
utils.render(TemplatePath('config/ember.js'), Project('config/ember.js'));
utils.render(TemplatePath('config/copy.js'), Project('config/copy.js'));
utils.render(TemplatePath('config/server.js'), Project('config/server.js'), {
key: `'${(await secret(48)).toString('hex')}'`
});
utils.render(TemplatePath('config/bundles.js'), Project('config/bundles.js'));
utils.render(TemplatePath('config/connections.js'), Project('config/connections.js'), {
database: app
});
utils.render(TemplatePath('config/bundles.js'), Project('config/bundles.js'));
utils.render(TemplatePath('config/ember.js'), Project('config/ember.js'));
utils.render(TemplatePath('config/inflections.js'), Project('config/inflections.js'));
utils.render(TemplatePath('config/security.js'), Project('config/security.js'));
utils.render(TemplatePath('config/server.js'), Project('config/server.js'), {
key: `'${(await secret(48)).toString('hex')}'`
});
utils.render(TemplatePath('config/static.js'), Project('config/static.js'));
utils.render(TemplatePath('config/views.js'), Project('config/views.js'));
};
const setupAssets = async function setupAssets () {
await utils.mkdir(Project('assets', 'img'));
Expand All @@ -53,9 +52,6 @@ const setupOthers = async function setupOthers () {
utils.render(TemplatePath('/views/index.html'), Project('/views/index.html'), {
application: application
});
utils.render(TemplatePath('bower.json'), Project('bower.json'), {
application: application
});
};
const setupDependencies = async function setupDependencies (options, db, eg) {
const shell = utils.shell;
Expand All @@ -76,9 +72,9 @@ const setupDependencies = async function setupDependencies (options, db, eg) {
await shell('Installing engine ' + 'handlebars-layouts'.green, ['npm', 'install', 'handlebars-layouts', '--save', '--loglevel', 'info'], proypath);
// }
}
if (!options.skipBower) {
await shell('Installing bower dependencies', ['bower', 'install'], proypath);
}
// if (!options.skipBower) {
// await shell('Installing bower dependencies', ['bower', 'install'], proypath);
// }
pk = requireNoCache(Project('package.json'));
utils.write(Project('package.json'), JSON.stringify(pk, null, '\t'), null);
};
Expand All @@ -98,8 +94,9 @@ export default (new Command(__filename, 'Creates a new koaton aplication.'))
ArrayToDescription(engines)
],
['-f', '--force', 'Overrides the existing directory.'],
['-n', '--skip-npm', 'Omits npm install'],
['-b', '--skip-bower', 'Omits bower install']
// ['-b', '--skip-bower', 'Omits bower install'],
['-n', '--skip-npm', 'Omits npm install']

])
.Action(async function (AppName, options) {
if (!AppName) {
Expand All @@ -114,6 +111,7 @@ export default (new Command(__filename, 'Creates a new koaton aplication.'))
await setupConfig(AppName);
await setupOthers(AppName);
await setupDependencies(options, adapters.isOrDef(options.db), engines.isOrDef(options.viewEngine));
console.log('reaches');
await utils.shell('Initializing git'.green, ['git', 'init'], proypath);
welcome.line1(true);
console.log(' To run your app first: ');
Expand Down
8 changes: 5 additions & 3 deletions src/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ const deleted = function (file) {
});
return Promise.all(promises);
},
WatchModels = function WatchModels (Watch) {
WatchModels = function WatchModels () {
const addmodelfn = function addmodelfn (file) {
let model = path.basename(file).replace('.js', '');
let Model = ModelManager(model, requireNoCache(file)).toMeta();
Expand Down Expand Up @@ -431,7 +431,7 @@ export default (new Command(__filename, 'Runs your awsome Koaton applicaction us
}
}));
await checkAssetsToBuild(chokidar.watch);
WatchModels(chokidar);
WatchModels();
}
await TriggerEvent('pre', 'serve');
seedKoatonModules();
Expand Down Expand Up @@ -460,6 +460,7 @@ export default (new Command(__filename, 'Runs your awsome Koaton applicaction us
})
.once('start', function () {
co(async function () {
console.log('Start');
await TriggerEvent('pre', 'serve');
screen.line1(true);
let ignoreemberdirs = [];
Expand Down Expand Up @@ -534,7 +535,8 @@ export default (new Command(__filename, 'Runs your awsome Koaton applicaction us
sound: 'Basso'
});
}).on('crash', (e) => {
console.log(e);
console.log('CRASH', e);
nodemon.emit('exit');
resolve(1);
});
const exitHandler = function () {
Expand Down
7 changes: 5 additions & 2 deletions src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ global.TemplatePath = function (...args) {
if (process.env.isproyect === 'true') {
const Server = require('./support/Server').default;
global.scfg = new Server();
// require(ProyPath('node_modules','koaton/lib/support','globals'));
require(ProyPath('node_modules', 'koaton/lib/support', 'globals'));
} else {
global.scfg = {version: '0.0.0'};
global.scfg = {
version: '0.0.0',
database: {}
};
}
3 changes: 0 additions & 3 deletions src/support/Adapters.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import ExtendedStrings from './ExtendedStrings';

const template = "{'driver': '{{driver}}','user': '{{user}}','database': '{{application}}','password': '{{password}}','port': {{port}},'host': '{{host}}','pool': false,'ssl': false}";

let adapters = new ExtendedStrings('package');

adapters.add('mongoose', 'port:27017');
Expand Down Expand Up @@ -31,5 +29,4 @@ Object.defineProperty(adapters, 'isOrDef', {
});

Object.freeze(adapters);
export {template, adapters};
export default adapters;
10 changes: 8 additions & 2 deletions src/support/BundleItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ const bundletemplates = {
}
};

/**
* Represents a Bundle Item used by the template engines to render .css or .js files.
* @class BundleItem
* @alias module:support/BundleItem.default
* @param {string} target Identifier that will be use as name of the bundle.
* @param {string|string[]} source File(s) that will be bundled.
*/
export default class BundleItem {
valueOf () {
return this.file;
Expand Down Expand Up @@ -53,7 +60,7 @@ export default class BundleItem {
}
return res;
}
[Symbol.iterator] () {
[ Symbol.iterator] () {
let index = -1;
return {
next: () => ({
Expand All @@ -62,5 +69,4 @@ export default class BundleItem {
})
};
}

}
10 changes: 5 additions & 5 deletions src/support/ORMModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import datatypes from './DataTypes';
import compile from '../utils/compile';
import inflector from './inflector';

const compileCaminte = compile.bind(null, '\'use strict\';\nmodule.exports = function(schema,relation) {\n\treturn {\n\t\tmodel: {\n\t\t\t{{model}}\n\t\t},\n\t\textra: {},\n\t\trelations: {\n\t\t\t{{relations}}\n\t\t}\n\t};\n};');
const compileCaminte = compile.bind(null, "'use strict';\nexports.default = function(schema,relation) {\n\treturn {\n\t\tmodel: {\n\t\t\t{{model}}\n\t\t},\n\t\textra: {},\n\t\trelations: {\n\t\t\t{{relations}}\n\t\t}\n\t};\n};");
const compileEmber = compile.bind(null, "import Model from 'ember-data/model';\nimport attr from 'ember-data/attr';\nimport { hasMany, belongsTo } from 'ember-data/relationships';\nexport default Model.extend({\n\t{{definition}}\n});");
const compileCRUDTable = compile.bind(null, "import Ember from 'ember';\nimport crud from 'ember-cli-crudtable/mixins/crud-controller';\nexport default Ember.Controller.extend(crud('{{model}}'), {\n\tactions: {\n\t\t{{actions}}\n\t},\n\tfieldDefinition: {\n\t\t{{definition}}\n\t}\n});");
export default class ORMModel {
Expand Down Expand Up @@ -115,16 +115,16 @@ export default class ORMModel {
}
entity[key].Type = type;
entity = JSON.stringify(entity);
definition.push(entity.substr(1, entity.length - 2));
definition.push(entity.substr(1, entity.length - 2).replace(/"/igm, '\''));
});
Object.keys(this._relations).forEach((property) => {
let opts = this._relations[property];
let display;
Object.keys(scfg.database[opts[1]]).some((key) => {
let display = property;
Object.keys(scfg.database[opts[1]] || {}).some((key) => {
display = key;
return true;
});
let rel = `${property}:{Type:'${opts[0]}',Display:'${display}',Source:'_${property}'}`;
let rel = `'${property}':{Type:'${opts[0]}',Display:'${display}',Source:'_${property}'}`;
definition.push(rel);
actions.push(`_${property}(deferred){this.store.findAll('${opts[1]}').then(deferred.resolve,deferred.reject);}`);
});
Expand Down
Loading

0 comments on commit 0042101

Please sign in to comment.