Skip to content

Commit

Permalink
v1.2.0 release major package bumps
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Oct 25, 2018
1 parent a9d76ac commit de8ac16
Show file tree
Hide file tree
Showing 17 changed files with 1,048 additions and 1,414 deletions.
16 changes: 12 additions & 4 deletions cli.js
@@ -1,15 +1,20 @@
#! /usr/bin/env node
require('babel-register')({
presets: ['env']
require = require('esm')(module);
require('@babel/register')({
presets: ['@babel/preset-env']
});

const fs = require('fs');
const util = require('util');
const child_process = require('child_process');
const chalk = require('chalk');
const chalk = require('ansi-colors');
const { classify, dasherize, underscore } = require('ember-cli-string-utils');
const { pluralize, singularize } = require('i')();

if (process.env.NODE_ENV === 'test') {
chalk.enabled = false;
}

const CLI = {
default(commandHandler) {
!process.argv[2] ? commandHandler() : null;
Expand Down Expand Up @@ -76,7 +81,10 @@ CLI.command(['version', 'v'], () => {
});

function printCommands() {
console.log(`${chalk.cyan('[MemServer CLI] Usage:')} memserver ${chalk.yellow('<command (Default: help)>')}
const config = require('./package.json');
const highlight = (text) => chalk.bold.cyan(text);

console.log(`${highlight('[MemServer CLI v' + config.version + '] Usage:')} memserver ${chalk.yellow('<command (Default: help)>')}
memserver init | new # Sets up the initial memserver folder structure
memserver generate model ${chalk.yellow('[ModelName]')} # Generates the initial files for a MemServer Model ${chalk.cyan('[alias: "memserver g model"]')}
Expand Down
8 changes: 4 additions & 4 deletions lib/index.js
@@ -1,9 +1,9 @@
require('babel-register')({
presets: ['env']
require('@babel/register')({
presets: ['@babel/preset-env']
});

const fs = require('fs');
const chalk = require('chalk');
const chalk = require('ansi-colors');
const { classify, dasherize } = require('ember-cli-string-utils');
const Inflector = require('i');

Expand All @@ -28,7 +28,7 @@ if (!fs.existsSync(`${CWD}/memserver`)) {
throw new Error(chalk.red('/memserver/server.js doesn\'t exist for this directory!'));
}

const modelFileNames = fs.readdirSync(`${process.cwd()}/memserver/models`);
const modelFileNames = fs.readdirSync(`${CWD}/memserver/models`);
const modelFixtureTree = modelFileNames.reduce((tree, fileName) => {
const modelName = fileName.slice(0, -3);
const fixturePath = `${CWD}/memserver/fixtures/${dasherize(pluralize(modelName))}.js`;
Expand Down
38 changes: 19 additions & 19 deletions lib/mem-server-cjs.js
Expand Up @@ -2,13 +2,13 @@

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var chalk = _interopDefault(require('chalk'));
var FakeXMLHttpRequest = _interopDefault(require('fake-xml-http-request'));
var RouteRecognizer = _interopDefault(require('route-recognizer'));
require('pretender');
var chalk = _interopDefault(require('ansi-colors'));
var qs = _interopDefault(require('qs'));
var Inflector = _interopDefault(require('i'));
var stringUtils = _interopDefault(require('ember-cli-string-utils'));
var FakeXMLHttpRequest = _interopDefault(require('fake-xml-http-request'));
var RouteRecognizer = _interopDefault(require('route-recognizer'));
require('pretender');

function primaryKeyTypeSafetyCheck(targetPrimaryKeyType, primaryKey, modelName) {
const primaryKeyType = typeof primaryKey;
Expand All @@ -22,12 +22,12 @@ function primaryKeyTypeSafetyCheck(targetPrimaryKeyType, primaryKey, modelName)
return targetPrimaryKeyType;
}

const targetNamespace$1 = typeof global === 'object' ? global : window;
const targetNamespace = typeof global === 'object' ? global : window;
const DEFAULT_PASSTHROUGHS = [
'http://localhost:0/chromecheckurl', 'http://localhost:30820/socket.io'
];

var startServer = function(Server, options={}) {
function startServer(Server, options={}) {
window.Pretender.prototype.namespace = options.namespace;
window.Pretender.prototype.urlPrefix = options.urlPrefix;
window.Pretender.prototype.timing = options.timing;
Expand Down Expand Up @@ -81,10 +81,10 @@ var startServer = function(Server, options={}) {
DEFAULT_PASSTHROUGHS.forEach((url) => pretender$$1.passthrough(url));
// END: Pretender this.passthrough for better UX

Server.apply(pretender$$1, [targetNamespace$1.MemServer.Models]);
Server.apply(pretender$$1, [targetNamespace.MemServer.Models]);

return pretender$$1;
};
}

function colorStatusCode(statusCode) {
if (statusCode === 200 || statusCode === 201) {
Expand All @@ -98,7 +98,7 @@ function colorStatusCode(statusCode) {

const { classify } = stringUtils;
const { singularize } = Inflector();
const targetNamespace$2 = typeof global === 'object' ? global : window;
const targetNamespace$1 = typeof global === 'object' ? global : window;

// HACK START: Pretender Request Parameter Type Casting Hack: Because types are important.
window.Pretender.prototype._handlerFor = function(verb, url, request) {
Expand Down Expand Up @@ -260,7 +260,7 @@ function getDefaultRouteHandler(verb, path) {
const lastPath = paths[paths.length - 1];
const pluralResourceName = lastPath.includes(':') ? paths[paths.length - 2] : lastPath;
const resourceName = singularize(pluralResourceName);
const ResourceModel = targetNamespace$2.MemServer.Models[classify(resourceName)];
const ResourceModel = targetNamespace$1.MemServer.Models[classify(resourceName)];

if (!ResourceModel) {
throw new Error(chalk.red(`[MemServer] ${verb} ${path} route handler cannot be generated automatically: ${classify(resourceName)} is not a valid MemServer.Model, please check that your route name matches the model reference or create a custom handler function`));
Expand Down Expand Up @@ -292,7 +292,7 @@ function getDefaultRouteHandler(verb, path) {
}

const ENVIRONMENT_IS_NODE = typeof global === 'object';
const targetNamespace = ENVIRONMENT_IS_NODE ? global : window;
const targetNamespace$2 = ENVIRONMENT_IS_NODE ? global : window;

if (ENVIRONMENT_IS_NODE) {
global.self = window.self;
Expand All @@ -301,12 +301,12 @@ if (ENVIRONMENT_IS_NODE) {
window.FakeXMLHttpRequest = FakeXMLHttpRequest;
window.RouteRecognizer = RouteRecognizer;

var memServer = function(modelFixtureTree, Server, initializer=() => {}) {
function memServer(modelFixtureTree, Server, initializer=() => {}) {
if (!Server) {
throw new Error('memserver/server.js doesnt exist! Please create a memserver/server.js to use MemServer');
}

targetNamespace.MemServer = {
targetNamespace$2.MemServer = {
DB: {},
Server: {},
Models: registerModels(modelFixtureTree),
Expand All @@ -326,8 +326,8 @@ var memServer = function(modelFixtureTree, Server, initializer=() => {}) {
}
};

return targetNamespace.MemServer;
};
return targetNamespace$2.MemServer;
}

function registerModels(modelFixtureTree) {
return Object.keys(modelFixtureTree).reduce((result, ModelName) => {
Expand Down Expand Up @@ -356,18 +356,18 @@ function resetDatabase(models, modelFixtureTree) {
throw new Error(chalk.red(`[MemServer] DATABASE ERROR: Duplication in ${modelName} fixtures with ${primaryKey}: ${model[primaryKey]}`));
}

const existingAttributes = targetNamespace.MemServer.Models[modelName].attributes;
const existingAttributes = targetNamespace$2.MemServer.Models[modelName].attributes;

Object.keys(model).forEach((key) => {
if (!existingAttributes.includes(key)) {
targetNamespace.MemServer.Models[modelName].attributes.push(key);
targetNamespace$2.MemServer.Models[modelName].attributes.push(key);
}
});

return [primaryKey, primaryKeys.concat([model[primaryKey]])];
}, [targetNamespace.MemServer.Models[modelName].primaryKey, []])[0];
}, [targetNamespace$2.MemServer.Models[modelName].primaryKey, []])[0];

targetNamespace.MemServer.Models[modelName].primaryKey = modelPrimaryKey;
targetNamespace$2.MemServer.Models[modelName].primaryKey = modelPrimaryKey;

return result;
}, {});
Expand Down
2 changes: 1 addition & 1 deletion lib/mem-server.js
@@ -1,4 +1,4 @@
import chalk from 'chalk';
import chalk from 'ansi-colors';
import { primaryKeyTypeSafetyCheck } from './utils';

const ENVIRONMENT_IS_NODE = typeof global === 'object';
Expand Down
2 changes: 1 addition & 1 deletion lib/model.js
@@ -1,5 +1,5 @@
import util from 'util';
import chalk from 'chalk';
import chalk from 'ansi-colors';
import Inflector from 'i';
import { classify, underscore } from 'ember-cli-string-utils';
import { primaryKeyTypeSafetyCheck, generateUUID } from './utils';
Expand Down
2 changes: 1 addition & 1 deletion lib/pretender-hacks.js
@@ -1,5 +1,5 @@
import qs from 'qs';
import chalk from 'chalk';
import chalk from 'ansi-colors';
import Inflector from 'i';
import stringUtils from 'ember-cli-string-utils';

Expand Down
2 changes: 1 addition & 1 deletion lib/server.js
@@ -1,4 +1,4 @@
import chalk from 'chalk';
import chalk from 'ansi-colors';

const targetNamespace = typeof global === 'object' ? global : window;
const DEFAULT_PASSTHROUGHS = [
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
@@ -1,4 +1,4 @@
import chalk from 'chalk';
import chalk from 'ansi-colors';

export function generateUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
Expand Down
6 changes: 3 additions & 3 deletions model.js
Expand Up @@ -2,8 +2,8 @@

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var chalk = _interopDefault(require('ansi-colors'));
var util = _interopDefault(require('util'));
var chalk = _interopDefault(require('chalk'));
var Inflector = _interopDefault(require('i'));
var emberCliStringUtils = require('ember-cli-string-utils');

Expand All @@ -30,7 +30,7 @@ function primaryKeyTypeSafetyCheck(targetPrimaryKeyType, primaryKey, modelName)
const { singularize, pluralize } = Inflector();
const targetNamespace = typeof global === 'object' ? global : window;

var model = function(options) {
function model(options) {
return Object.assign({}, {
modelName: null,
primaryKey: null,
Expand Down Expand Up @@ -254,7 +254,7 @@ var model = function(options) {
}
}
}, options);
};
}

function incrementId(Model) {
const ids = targetNamespace.MemServer.DB[Model.modelName];
Expand Down

0 comments on commit de8ac16

Please sign in to comment.