Skip to content

Commit

Permalink
Update lint and fix code (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
nightskylark authored Nov 9, 2018
1 parent 6dba80b commit b6fa2a3
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 220 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"node": true
},
"parserOptions": {
"ecmaVersion": 6,
"ecmaVersion": 2018,
"sourceType": "module",
"ecmaFeatures": {
"globalReturn": true
Expand Down Expand Up @@ -40,6 +40,7 @@
}
}
],
"linebreak-style": ["error", "unix"],
"no-multiple-empty-lines": [ "error", { "max": 2 } ],
"no-irregular-whitespace": "error",
"no-multi-spaces": "error",
Expand Down
12 changes: 6 additions & 6 deletions commands/application.angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function runSchematicCommand(schematicCommand, options, evaluatingOptions) {
}

function localPackageExists(packageName) {
const nodeModulesPath = path.join(process.cwd(), `node_modules`);
const nodeModulesPath = path.join(process.cwd(), 'node_modules');
if(!fs.existsSync(nodeModulesPath)) {
return;
}
Expand All @@ -49,22 +49,22 @@ function localPackageExists(packageName) {

function optimizeNgCommandArguments(args) {
return new Promise((resolve, reject) => {
hasSutableNgCli().then(() => resolve(args), () => resolve(['-p', '@angular/cli', ...args]));
hasSutableNgCli().then(() => resolve(args), () => resolve(['-p', '@angular/cli', ...args]));
});
}

function hasSutableNgCli() {
return new Promise((resolve, reject) => {
exec('ng v', (err, stdout, stderr) => {
stderr || parseNgCliVersion(stdout).compare(minNgCliVersion) < 0
? reject()
: resolve();
? reject()
: resolve();
});
});
}

function parseNgCliVersion(stdout) {
return new semver(stdout.toString().match(/(?<=angular.cli: )(\S+)/ig)[0]);
return new semver(/angular.cli:\s*(\S+)/ig.exec(stdout.toString())[1]);
}

const install = (options) => {
Expand All @@ -84,7 +84,7 @@ const create = (appName, options) => {
};

const addTemplate = (appName, options, evaluatingOptions) => {
const schematicOptions = {...(appName && {project: appName}), ...options};
const schematicOptions = { ...(appName && { project: appName }), ...options };
runSchematicCommand('add-app-template', schematicOptions, evaluatingOptions);
};

Expand Down
103 changes: 52 additions & 51 deletions commands/application.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
const angularApplication = require('./application.angular');
const printHelp = require('./help').printHelp;

const isApplicationCommand = (command) => {
return [ 'new', 'add' ].indexOf(command) > -1;
};

const run = (commands, options, devextremeConfig) => {
if(!commands[1]) {
console.error('No parameters found.');
printHelp(commands[0]);
return;
}

if(commands[0] === 'new') {
if(commands[1] === 'angular-app') {
angularApplication.create(commands[2] || 'my-app', options);
} else {
console.error(`The '${commands[1]}' application type is not valid`);
printHelp(commands[0]);
}
} else {
if(commands[0] === 'add') {
if(commands[1] === 'devextreme-angular') {
angularApplication.install(options);
return;
}

if(commands[1] === 'angular-template') {
angularApplication.addTemplate(commands[2], options);
return;
}

if(devextremeConfig.applicationEngine === 'angular') {
if(commands[1] === 'view') {
angularApplication.addView(commands[2], options);
} else {
console.error('Invalid command');
printHelp(commands[0]);
}
} else {
console.log('The DevExtreme application cannot be found');
}
}
}
};

module.exports = {
isApplicationCommand,
run
};
const angularApplication = require('./application.angular');
const printHelp = require('./help').printHelp;

const isApplicationCommand = (command) => {
return [ 'new', 'add' ].indexOf(command) > -1;
};

const run = (commands, options, devextremeConfig) => {
if(!commands[1]) {
console.error('No parameters found.');
printHelp(commands[0]);
return;
}

if(commands[0] === 'new') {
if(commands[1] === 'angular-app') {
angularApplication.create(commands[2] || 'my-app', options);
return;
}

console.error(`The '${commands[1]}' application type is not valid`);
printHelp(commands[0]);
} else {
if(commands[0] === 'add') {
if(commands[1] === 'devextreme-angular') {
angularApplication.install(options);
return;
}

if(commands[1] === 'angular-template') {
angularApplication.addTemplate(commands[2], options);
return;
}

if(devextremeConfig.applicationEngine === 'angular') {
if(commands[1] === 'view') {
angularApplication.addView(commands[2], options);
} else {
console.error('Invalid command');
printHelp(commands[0]);
}
} else {
console.log('The DevExtreme application cannot be found');
}
}
}
};

module.exports = {
isApplicationCommand,
run
};
1 change: 0 additions & 1 deletion commands/help.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const commands = require('./commands.json').commands;

const textColor = '\x1b[36m%s\x1b[0m';

const findCommand = (commandName) => {
Expand Down
Loading

0 comments on commit b6fa2a3

Please sign in to comment.