Skip to content

Commit

Permalink
Merge pull request #13 from cix-cdx/next
Browse files Browse the repository at this point in the history
to master
  • Loading branch information
tpanitte committed Jan 26, 2018
2 parents df04217 + cf51ffd commit c5c7efb
Show file tree
Hide file tree
Showing 54 changed files with 1,510 additions and 702 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ test/
*.yml
aftertests.js
cleanup.js
cix-lic.json
package-lock.json
4 changes: 4 additions & 0 deletions cix-lic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"baseDir": "./lib",
"beginYear": "2018"
}
8 changes: 8 additions & 0 deletions lib/HFLicense.process.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const HFLicensor = require('./licensors/HFLicensor');

const HFLicenseProcess = {
assert: (LICProps, callback) => HFLicensor.assert(LICProps.HFLcontent, LICProps.HFLqueries, callback, LICProps.assertAll),
licensing: (LICProps, callback) => HFLicensor.process(LICProps.HFLcontent, LICProps.HFLqueries, callback),
};

module.exports = HFLicenseProcess;
42 changes: 0 additions & 42 deletions lib/argvquerier.js

This file was deleted.

52 changes: 0 additions & 52 deletions lib/assertfilelicensing.js

This file was deleted.

115 changes: 98 additions & 17 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,105 @@
#!/usr/bin/env node
const Chalk = require('chalk');
const ArgvLoader = require('./core/argv.loader');
const ConfigLoader = require('./core/config.loader');
const LICPropsBuilder = require('./licprops.builder');
const LicenseProcess = require('./license.process');
const HFLicenseProcess = require('./HFLicense.process');

const chalk = require('chalk');
const argvQuerier = require('./argvquerier');
const filesLicensing = require('./fileslicensing');
const pkgLicensing = require('./pkglicensing');
const argv = ArgvLoader.load();
const props = argv.hasOwnProperty('conf') ? ConfigLoader.load(argv.conf, argv) : argv;
const LICProps = LICPropsBuilder.build(props);

const argv = argvQuerier();
const AssertingProcess = {
LicenseProcess: () => {
console.log(Chalk.cyan('# LICENSE ASSERT : Processing..'));

if (argv.proc.indexOf('pkg') > -1) {
console.log(chalk.cyan('#Package License: Processing..'));
pkgLicensing(argv);
} else {
console.log(chalk.yellow('#Package License: Skipped!'));
}
if (LICProps.proc.indexOf('lic') > -1) {
if (LicenseProcess.assert(LICProps)) {
console.log(`\n - Assert Result : ${Chalk.green('SUCCESS')}\n`);
} else {
console.log(Chalk.red('\n - Assert Result : FAILED\n'));

if (!LICProps.assertAll) {
process.exit(1);
}
}
} else {
console.log(Chalk.yellow('\n - License Assert : Skipped!\n'));
}
},
HFLProcess: () => {
console.log(Chalk.cyan('# HFLICENSE ASSERT : Processing..'));

if (LICProps.proc.indexOf('file') > -1) {
const handler = (error, negative, positive) => {
if (negative) {
console.log(Chalk.red(` ${negative} - MISSING..`));
} else if (positive) {
console.log(` ${positive} - ${Chalk.green('FOUND..')} `);
}
};

if (HFLicenseProcess.assert(LICProps, handler)) {
console.log(`\n - Assert Result : ${Chalk.green('SUCCESS')}\n`);
} else {
console.log(Chalk.red('\n - Assert Result : FAILED\n'));
}
} else {
console.log(Chalk.yellow('\n - HFLicense Assert : Skipped!\n'));
}
}
};

const LicensingProcess = {
LicenseProcess: () => {
console.log(Chalk.cyan('# LICENSING PROCESS : Processing..'));

if (LICProps.proc.indexOf('lic') > -1) {
if (LicenseProcess.licensing(LICProps)) {
console.log(Chalk.green('\n License File ADDED..\n'));
} else {
console.log('\n - License File ALREADY EXIST..\n');
}
} else {
console.log(Chalk.yellow('\n - Licensing Process : Skipped!\n'));
}
},
HFLProcess: () => {
console.log(Chalk.cyan('# HFLICENSING PROCESS : Processing..'));

console.log('\n');
if (LICProps.proc.indexOf('file') > -1) {
const handler = (error, negative, positive) => {
if (negative) {
console.log(` ${negative} - ALREADY EXIST..`);
} else if (positive) {
console.log(` ${positive} - ${Chalk.green('ADDED..')} `);
}
};

HFLicenseProcess.licensing(LICProps, handler);
} else {
console.log(Chalk.yellow('\n - HFLicensing Process : Skipped!\n'));
}

console.log('\n - Process Completed\n');
}
};

// :: CLI Process ::

console.log(`\n:: ${Chalk.cyan('CIX-LIC')} ::\n`);

if (LICProps.assert) {
console.log(Chalk.yellow(':: ASSERT MODE ::\n'));

AssertingProcess.LicenseProcess();
console.log();
AssertingProcess.HFLProcess();

if (argv.proc.indexOf('file') > -1) {
console.log(chalk.cyan('##File License: Processing..'));
filesLicensing(argv);
} else {
console.log(chalk.yellow('##File License: Skipped!'));
console.log(Chalk.yellow(':: PROCESS MODE ::\n'));

LicensingProcess.LicenseProcess();
console.log();
LicensingProcess.HFLProcess();
}
68 changes: 68 additions & 0 deletions lib/core/argv.loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const AppEnv = require('archappenv').AppEnv;

const ArgvLoader = {
load: () => {
const v = AppEnv.Services.processArgv();
const props = {};

if (v.lic || v.l) {
props.lic = v.lic || v.l;
}

if (v.owner || v.o) {
props.owner = v.owner || v.o;
}

if (v.beginYear || v.b) {
props.beginYear = v.beginYear || v.b;
}

if (v.endYear || v.e) {
props.endYear = v.endYear || v.e;
}

if (v.proc || v.p) {
props.proc = v.proc || v.p;
}

if (v.baseDir || v.d) {
props.baseDir = v.baseDir || v.d;
}

if (v.filter || v.f) {
props.filter = v.filter || v.f;
}

if (v.HFLcontent || v.h) {
props.HFLcontent = v.HFLcontent || v.h;
}

if (v.licenseFile) {
props.licenseFile = v.licenseFile;
}

if (v.licenseContent || v.c) {
props.licenseContent = v.licenseContent || v.c;
}

if (v.hasOwnProperty('conf')) {
props.conf = v.conf;
}

if (v.hasOwnProperty('strict')) {
props.strict = true;
}

if (v.hasOwnProperty('assert')) {
props.assert = true;

if (v.assert != undefined && v.assert.toLowerCase() === 'all') {
props.assertAll = true;
}
}

return props;
}
};

module.exports = ArgvLoader;
30 changes: 30 additions & 0 deletions lib/core/config.loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const AppEnv = require('archappenv').AppEnv;
const FS = require('fs');

const ConfigLoader = {
load: (file = './cix-lic.json', argv = {}) => {
const configFile = AppEnv.Util.resolveFile(file);

if (FS.existsSync(configFile)) {
const config = require(configFile);

if (argv.assert) {
config.assert = argv.assert;
}

if (argv.assertAll) {
config.assertAll = argv.assertAll;
}

if (argv.strict) {
config.strict = argv.strict;
}

return config;
} else {
throw new Error(`NO CONFIG FILES FOUND: ${configFile}`);
}
}
};

module.exports = ConfigLoader;
32 changes: 32 additions & 0 deletions lib/core/files.resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const AppEnv = require('archappenv').AppEnv;
const FS = require('fs');
const Path = require('path');

const DefaultFilter = /\.js$/;

const FilesResolver = {
resolve: (baseDir, filter) => {
const resolved = AppEnv.Util.resolvePath(baseDir);
const subpaths = AppEnv.Util.subpathsSync(resolved);
const Filter = FilesResolver.toFilter(filter);

return subpaths.map(basepath =>
FS.readdirSync(basepath)
.map(name => ({ name, basepath }))
.filter(each => Filter.test(each.name))
.map(each => Path.join(each.basepath, each.name)))
.reduce((result, each) => result.concat(each), []);
},
toFilter: (filter) => {
if (typeof filter === 'string') {
filter = filter[0] === '*' ? filter.slice(1) : filter;
return new RegExp(`${filter}$`);
} else if (filter && typeof filter.test === 'function') {
return filter;
} else {
return DefaultFilter;
}
}
};

module.exports = FilesResolver;
11 changes: 11 additions & 0 deletions lib/core/license.map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const LicenseName = require('../data/common/license.name.json');
const HeadFileLicense = require('../data/headfile.license');
const License = require('../data/license');

const LicenseMap = {
resolveLicense: (LICProps) => LicenseName[LICProps.lic.toUpperCase()] || LICProps.lic,
resolveHFLcontent: (LICProps) => HeadFileLicense(LICProps),
resolveLicenseContent: (LICProps) => License(LICProps),
};

module.exports = LicenseMap;
6 changes: 6 additions & 0 deletions lib/data/common/license.name.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"APACHE-1.0": "Apache License 1.0",
"APACHE-1.1": "Apache License 1.1",
"APACHE-2.0": "Apache License 2.0",
"MIT": "MIT License"
}

0 comments on commit c5c7efb

Please sign in to comment.