-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from cix-cdx/next
to master
- Loading branch information
Showing
54 changed files
with
1,510 additions
and
702 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ test/ | |
*.yml | ||
aftertests.js | ||
cleanup.js | ||
cix-lic.json | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"baseDir": "./lib", | ||
"beginYear": "2018" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Oops, something went wrong.