Skip to content

Commit

Permalink
code->prettier->eslint--fix->formatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Balestra committed Jun 5, 2017
1 parent 92e2449 commit a3eebe5
Show file tree
Hide file tree
Showing 95 changed files with 2,829 additions and 1,913 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"oc": "./src/oc-cli.js"
},
"scripts": {
"format": "prettier-eslint --single-quote --write \"src/**/*.js\"",
"test": "grunt test"
},
"engines": {
Expand Down Expand Up @@ -45,6 +46,7 @@
"load-grunt-tasks": "^3.5.2",
"mocha": "^3.0.2",
"phantomjs-prebuilt": "^2.1.12",
"prettier-eslint-cli": "^4.0.3",
"semver-sort": "0.0.4",
"sinon": "^1.17.5"
},
Expand Down
31 changes: 20 additions & 11 deletions src/cli/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
module.exports = {
usage: 'Usage: $0 <command> [options]',
commands: {

dev: {
cmd: 'dev <dirPath> [port] [baseUrl]',
example: {
cmd: '$0 dev ../all-components 3001 127.0.0.1:3001 --fallbackRegistryUrl=http://anotherhost:anotherport/'
cmd:
'$0 dev ../all-components 3001 127.0.0.1:3001 --fallbackRegistryUrl=http://anotherhost:anotherport/'
},
description: 'Runs a local oc test registry in order to develop and test components',
description:
'Runs a local oc test registry in order to develop and test components',
options: {
fallbackRegistryUrl: {
description: 'Url to another registry which will be used by dev registry when component cannot be found in local registry',
description:
'Url to another registry which will be used by dev registry when component cannot be found in local registry'
},
hotReloading: {
boolean: true,
description: 'Enables hot reloading. Note: when hot reloading is set to true, each request to the component will make the registry to create a new instance for the javascript closures to be loaded, while when false the instance will be recycled between components executions',
description:
'Enables hot reloading. Note: when hot reloading is set to true, each request to the component will make the registry to create a new instance for the javascript closures to be loaded, while when false the instance will be recycled between components executions',
default: true
},
verbose: {
Expand All @@ -34,24 +37,28 @@ module.exports = {
example: {
cmd: '$0 init test-component jade'
},
description: 'Creates a new empty component [of either jade or handlebars template type] in the current folder',
description:
'Creates a new empty component [of either jade or handlebars template type] in the current folder',
usage: 'Usage: $0 init <componentName> [templateType]'
},

mock: {
cmd: 'mock <targetType> <targetName> <targetValue>',
example: {
cmd: '$0 mock plugin hash "always-returned-value"',
description: 'Creates static mock for a "hash" plugin which always returns "always-returned-value" value'
description:
'Creates static mock for a "hash" plugin which always returns "always-returned-value" value'
},
description: 'Allows to mock configuration in order to facilitate local development',
description:
'Allows to mock configuration in order to facilitate local development',
usage: 'Usage: $0 mock <targetType> <targetName> <targetValue>'
},

preview: {
cmd: 'preview <componentHref>',
example: {
cmd: '$0 preview "http://localhost:3000/my-new-component/1.0.0/?param1=hello&name=Arthur"'
cmd:
'$0 preview "http://localhost:3000/my-new-component/1.0.0/?param1=hello&name=Arthur"'
},
description: 'Runs a test page consuming a component',
usage: 'Usage: $0 preview <componentHref>'
Expand Down Expand Up @@ -80,10 +87,12 @@ module.exports = {
},
options: {
password: {
description: 'password used to authenticate when publishing to registry'
description:
'password used to authenticate when publishing to registry'
},
username: {
description: 'username used to authenticate when publishing to registry'
description:
'username used to authenticate when publishing to registry'
}
},
description: 'Publish a component',
Expand Down
19 changes: 8 additions & 11 deletions src/cli/domain/get-components-by-dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@ const fs = require('fs-extra');
const path = require('path');
const _ = require('lodash');

module.exports = function(){

return function(componentsDir, callback){

const isOcComponent = function(file){

module.exports = function() {
return function(componentsDir, callback) {
const isOcComponent = function(file) {
const filePath = path.resolve(componentsDir, file),
packagePath = path.join(filePath, 'package.json');
let content;

try {
content = fs.readJsonSync(packagePath);
}
catch(err)
{
} catch (err) {
return false;
}

Expand All @@ -35,11 +30,13 @@ module.exports = function(){

try {
dirContent = fs.readdirSync(componentsDir);
} catch(err){
} catch (err) {
return callback(null, []);
}

const components = dirContent.filter(isOcComponent).map((component) => path.resolve(componentsDir, component));
const components = dirContent
.filter(isOcComponent)
.map(component => path.resolve(componentsDir, component));

callback(null, components);
};
Expand Down
14 changes: 7 additions & 7 deletions src/cli/domain/get-components-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ const coreModules = require('builtin-modules');
const format = require('stringformat');
const fs = require('fs-extra');
const path = require('path');
const _ = require('lodash');
const _ = require('lodash');

const settings = require('../../resources');

module.exports = function(components){
const deps = { modules: {}, withVersions: {}, templates: {} };
module.exports = function(components) {
const deps = {modules: {}, withVersions: {}, templates: {}};

const legacyTemplates = {
'jade': true,
'handlebars': true
jade: true,
handlebars: true
};

components.forEach((c) => {
components.forEach(c => {
const pkg = fs.readJsonSync(path.join(c, 'package.json'));
const type = pkg.oc.files.template.type;
const dependencies = pkg.dependencies || {};
Expand All @@ -28,7 +28,7 @@ module.exports = function(components){
deps.templates[type] = true;
}

_.keys(dependencies).forEach((name) => {
_.keys(dependencies).forEach(name => {
const version = dependencies[name];
const depToInstall = version.length > 0 ? `${name}@${version}` : name;

Expand Down
10 changes: 4 additions & 6 deletions src/cli/domain/get-local-npm-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
const fs = require('fs-extra');
const path = require('path');

module.exports = function(){
return function(componentsDir){

module.exports = function() {
return function(componentsDir) {
const nodeFolder = path.join(componentsDir, 'node_modules');

if(!fs.existsSync(nodeFolder)){
if (!fs.existsSync(nodeFolder)) {
return [];
}

return fs.readdirSync(nodeFolder).filter((file) => {

return fs.readdirSync(nodeFolder).filter(file => {
const filePath = path.resolve(nodeFolder, file),
isBin = file === '.bin',
isDir = fs.lstatSync(filePath).isDirectory();
Expand Down
8 changes: 3 additions & 5 deletions src/cli/domain/get-missing-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
const path = require('path');
const _ = require('lodash');

module.exports = (dependencies) => {

module.exports = dependencies => {
const missing = [];

_.forEach(dependencies, (npmModule) => {

_.forEach(dependencies, npmModule => {
const index = npmModule.indexOf('@');
let moduleName = npmModule;

Expand All @@ -19,7 +17,7 @@ module.exports = (dependencies) => {
const pathToModule = path.resolve('node_modules/', moduleName);

try {
if(require.cache[pathToModule]){
if (require.cache[pathToModule]) {
delete require.cache[pathToModule];
}

Expand Down
36 changes: 20 additions & 16 deletions src/cli/domain/get-mocked-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,34 @@ const _ = require('lodash');
const settings = require('../../resources/settings');
const strings = require('../../resources/');

const registerStaticMocks = function(mocks, logger){
const registerStaticMocks = function(mocks, logger) {
return _.map(mocks, (mockedValue, pluginName) => {
logger.log(colors.green('├── ' + pluginName + ' () => ' + mockedValue));
return {
name: pluginName,
register: {
register: function(options, dependencies, next){
register: function(options, dependencies, next) {
return next();
},
execute: function(){
execute: function() {
return mockedValue;
}
}
};
});
};

const registerDynamicMocks = function(ocJsonLocation, mocks, logger){
const registerDynamicMocks = function(ocJsonLocation, mocks, logger) {
return _.map(mocks, (source, pluginName) => {

let p;
try {
p = require(path.resolve(ocJsonLocation, source));
} catch(er) {
} catch (er) {
logger.err(er.toString());
return;
}

if(!_.isFunction(p)){
if (!_.isFunction(p)) {
logger.err(strings.errors.cli.MOCK_PLUGIN_IS_NOT_A_FUNCTION);
return;
}
Expand All @@ -45,25 +44,26 @@ const registerDynamicMocks = function(ocJsonLocation, mocks, logger){
return {
name: pluginName,
register: {
register: function(options, dependencies, next){
register: function(options, dependencies, next) {
return next();
},
execute: p
}
};
}).filter((p) => p);
}).filter(p => p);
};

const findPath = function(pathToResolve, fileName) {

const rootDir = fs.realpathSync('.'),
fileToResolve = path.join(pathToResolve, fileName);

if (!fs.existsSync(fileToResolve)) {
if (pathToResolve === rootDir) {
return undefined;
} else {
const getParent = function(x){ return x.split('/').slice(0, -1).join('/'); },
const getParent = function(x) {
return x.split('/').slice(0, -1).join('/');
},
parentDir = pathToResolve ? getParent(pathToResolve) : rootDir;

return findPath(parentDir, fileName);
Expand All @@ -73,28 +73,32 @@ const findPath = function(pathToResolve, fileName) {
return fileToResolve;
};

module.exports = function(logger, componentsDir){
module.exports = function(logger, componentsDir) {
componentsDir = path.resolve(componentsDir || '.');

let plugins = [];
const ocJsonFileName = settings.configFile.src.replace('./', ''),
ocJsonPath = findPath(componentsDir, ocJsonFileName);

if(!ocJsonPath){
if (!ocJsonPath) {
return plugins;
}

const content = fs.readJsonSync(ocJsonPath),
ocJsonLocation = ocJsonPath.slice(0, -ocJsonFileName.length);

if(!content.mocks || !content.mocks.plugins){
if (!content.mocks || !content.mocks.plugins) {
return plugins;
}

logger.warn(strings.messages.cli.REGISTERING_MOCKED_PLUGINS);

plugins = plugins.concat(registerStaticMocks(content.mocks.plugins.static, logger));
plugins = plugins.concat(registerDynamicMocks(ocJsonLocation, content.mocks.plugins.dynamic, logger));
plugins = plugins.concat(
registerStaticMocks(content.mocks.plugins.static, logger)
);
plugins = plugins.concat(
registerDynamicMocks(ocJsonLocation, content.mocks.plugins.dynamic, logger)
);

return plugins;
};
42 changes: 21 additions & 21 deletions src/cli/domain/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,39 @@ const packageComponents = require('./package-components');
const mock = require('./mock');
const validator = require('../../registry/domain/validators');

module.exports = function(){

module.exports = function() {
return _.extend(this, {
cleanup: function(compressedPackagePath, callback){
cleanup: function(compressedPackagePath, callback) {
return fs.unlink(compressedPackagePath, callback);
},
compress: function(input, output, callback){
return targz.compress({
src: input,
dest: output,
tar: {
map: function(file){
return _.extend(file, {
name: '_package/' + file.name
});
compress: function(input, output, callback) {
return targz.compress(
{
src: input,
dest: output,
tar: {
map: function(file) {
return _.extend(file, {
name: '_package/' + file.name
});
}
}
}
}, callback);
},
callback
);
},
getComponentsByDir: getComponentsByDir(),
getLocalNpmModules: getLocalNpmModules(),
init: function(componentName, templateType, callback){

if(!validator.validateComponentName(componentName)){
init: function(componentName, templateType, callback) {
if (!validator.validateComponentName(componentName)) {
return callback('name not valid');
}

if(!validator.validateTemplateType(templateType)){
if (!validator.validateTemplateType(templateType)) {
return callback('template type not valid');
}

try {

const pathDir = '../../components/base-component-' + templateType,
baseComponentDir = path.resolve(__dirname, pathDir),
npmIgnorePath = path.resolve(__dirname, pathDir + '/.npmignore');
Expand All @@ -59,8 +59,8 @@ module.exports = function(){

fs.outputJsonSync(componentPath, component);

return callback(null, { ok: true });
} catch(e){
return callback(null, {ok: true});
} catch (e) {
return callback(e);
}
},
Expand Down
Loading

0 comments on commit a3eebe5

Please sign in to comment.