Skip to content

Commit

Permalink
feat: merge branch 'master' into costumProperties
Browse files Browse the repository at this point in the history
Merge branch 'master' into costumProperties

re adobe#151
  • Loading branch information
COMLINE\Kunz committed Aug 26, 2019
2 parents 64078e2 + 52e3aea commit 36d75ea
Show file tree
Hide file tree
Showing 20 changed files with 4,529 additions and 1,307 deletions.
5 changes: 2 additions & 3 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules
coverage
out
.vscode/*
coverage/*
38 changes: 0 additions & 38 deletions .eslintrc

This file was deleted.

66 changes: 66 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2018 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

module.exports = {
'env': {
'node': true,
'es6': true
},
// this is the root project for all sub modules. stop searching for any
// eslintrc files in parent directories.
'root': true,
'parserOptions': {
'sourceType': 'script',
'ecmaVersion': 10,
},
'plugins': [
'header',
],
'extends': 'airbnb',
'rules': {
'strict': 0,

// Forbid multiple statements in one line
'max-statements-per-line': ["error", { "max": 1 }],

// Allow for-of loops
'no-restricted-syntax': ['error', 'ForInStatement', 'LabeledStatement', 'WithStatement'],

// Allow return before else & redundant else statements
'no-else-return': 'off',

// allow dangling underscores for 'fields'
'no-underscore-dangle': 'off',

// Allow marking variables unused using a underscore at the start
'no-unused-vars': ["error", {
"varsIgnorePattern": "^_.*$",
"argsIgnorePattern": "^_.*$",
"caughtErrorsIgnorePattern": "^_.*$"
}],


// enforce license header (todo: improve plugin to support patterns for multi-lines)
'header/header': [2, 'block', ['',
' * Copyright 2019 Adobe. All rights reserved.',
' * This file is licensed to you under the Apache License, Version 2.0 (the "License");',
' * you may not use this file except in compliance with the License. You may obtain a copy',
' * of the License at http://www.apache.org/licenses/LICENSE-2.0',
' *',
' * Unless required by applicable law or agreed to in writing, software distributed under',
' * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS',
' * OF ANY KIND, either express or implied. See the License for the specific language',
' * governing permissions and limitations under the License.',
' ',
]]
}
};
158 changes: 85 additions & 73 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
#! /usr/bin/env node
/**
* Copyright 2017 Adobe Systems Incorporated. All rights reserved.
/*
* Copyright 2019 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

var Promise = require('bluebird');
var path = require('path');
var _ = require('lodash');
var fs = Promise.promisifyAll(require('fs'));
var readdirp = require('readdirp');
var Ajv = require('ajv');
var logger = require('winston');
const Optimist = require('optimist');
const Promise = require('bluebird');
const path = require('path');
const _ = require('lodash');
const fs = Promise.promisifyAll(require('fs'));
const readdirp = require('readdirp');
const Ajv = require('ajv');
const i18n = require('i18n');
const logger = require('@adobe/helix-log');

const { error, info } = logger;

var Schema = require('./lib/schema');
var readSchemaFile = require('./lib/readSchemaFile');
const Schema = require('./lib/schema');
const readSchemaFile = require('./lib/readSchemaFile');

// parse/process command line arguments
var argv = require('optimist')
const { argv } = Optimist
.usage('Generate Markdown documentation from JSON Schema.\n\nUsage: $0')
.demand('d')
.alias('d', 'input')
Expand All @@ -41,12 +50,12 @@ var argv = require('optimist')
.default('v', '07')
.describe('n', 'Do not generate a README.md file in the output directory')
.describe('link-*', 'Add this file as a link the explain the * attribute, e.g. --link-abstract=abstract.md')
.check(function(args) {
.check((args) => {
if (!fs.existsSync(args.input)) {
throw 'Input file "' + args.input + '" does not exist!';
throw new Error(`Input file "${args.input}" does not exist!`);
}
if (args.s && !fs.existsSync(args.s)) {
throw 'Meta schema file "' + args.s + '" does not exist!';
throw new Error(`Meta schema file "${args.s}" does not exist!`);
}
})
.alias('i', 'i18n')
Expand All @@ -55,121 +64,124 @@ var argv = require('optimist')
.describe('p', 'A comma separated list with custom properties which should be also in the description of an element.')
.alias('h', 'header')
.describe('h', 'if the value is false the header will be skipped')
.default('h', true)
.argv;
.default('h', true);

const docs = _.fromPairs(_.toPairs(argv).filter(([ key, value ]) => { return key.startsWith('link-'); }).map(([ key, value ]) => { return [ key.substr(5), value ];}));
const i18n = require('i18n');
const docs = _.fromPairs(
_.toPairs(argv)
.filter(([key, _value]) => key.startsWith('link-'))
.map(([key, value]) => [key.substr(5), value]),
);

logger.configure({
level: 'info',
format: logger.format.combine(
logger.format.splat(),
logger.format.simple()
),
transports: [
new logger.transports.Console({})
]
const ajv = new Ajv({
allErrors: true, messages: true, schemaId: 'auto', logger,
});

var ajv = new Ajv({ allErrors: true, messages:true, schemaId: 'auto', logger: logger });
console.log(argv.v);
if (argv.v === '06'||argv.v === 6) {
console.log('enabling draft-06 support');
info(argv.v);
if (argv.v === '06' || argv.v === 6) {
info('enabling draft-06 support');
// eslint-disable-next-line global-require
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'));
} else if (argv.v === '04' || argv.v === 4) {
// eslint-disable-next-line global-require
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
}
var schemaPathMap = {};
var metaElements = {};
var schemaPath = path.resolve(argv.d);
var outDir = path.resolve(argv.o);
var schemaDir = argv.x === '-' ? '' : argv.x ? path.resolve(argv.x) : outDir;
var target = fs.statSync(schemaPath);
const schemaPathMap = {};
const metaElements = {};
const schemaPath = path.resolve(argv.d);
const outDir = path.resolve(argv.o);
// eslint-disable-next-line no-nested-ternary
const schemaDir = argv.x === '-' ? '' : (argv.x ? path.resolve(argv.x) : outDir);
const target = fs.statSync(schemaPath);
const readme = argv.n !== true;
const schemaExtension = argv.e || 'schema.json';
if (argv.s){
if (argv.s) {
// eslint-disable-next-line import/no-dynamic-require, global-require
ajv.addMetaSchema(require(path.resolve(argv.s)));
}

if (argv.m) {
if (_.isArray(argv.m)){
_.each(argv.m, function(item){
var meta=item.split('=');
if (meta.length === 2) {
metaElements[meta[0]] = meta[1];
if (_.isArray(argv.m)) {
_.each(argv.m, (item) => {
const [key, val] = item.split('=');
if (val !== undefined) {
metaElements[key] = val;
}
});
} else {
var meta=(argv.m).split('=');
if (meta.length === 2) {
metaElements[meta[0]] = meta[1];
const [key, val] = (argv.m).split('=');
if (val !== undefined) {
metaElements[key] = val;
}
}
}
let i18nPath;
if (argv !== undefined && argv.i !== undefined){
i18nPath=path.resolve(argv.i) ;
if (argv !== undefined && argv.i !== undefined) {
i18nPath = path.resolve(argv.i);
} else {
i18nPath=path.resolve(path.join(__dirname, 'lib/locales'));
i18nPath = path.resolve(path.join(__dirname, 'lib/locales'));
}
i18n.configure({
// setup some locales - other locales default to en silently
locales:[ 'en' ],
locales: ['en'],
// where to store json files - defaults to './locales' relative to modules directory
directory: i18nPath,
defaultLocale: 'en'
defaultLocale: 'en',
});

logger.info('output directory: %s', outDir);
info('output directory', outDir);
if (target.isDirectory()) {
// the ajv json validator will be passed into the main module to help with processing
var files=[];
const files = [];
readdirp(schemaPath, { root: schemaPath, fileFilter: `*.${schemaExtension}` })
.on('data', entry => {
.on('data', (entry) => {
files.push(entry.fullPath);
try {
// eslint-disable-next-line import/no-dynamic-require, global-require
ajv.addSchema(require(entry.fullPath), entry.fullPath);
} catch (e){
logger.error('Ajv processing error for schema at path %s', entry.fullPath);
logger.error(e);
} catch (e) {
error('Ajv processing error for schema at path', entry.fullPath);
error(e);
process.exit(1);
}
})
.on('end', () => {
Schema.setAjv(ajv);
Schema.setSchemaPathMap(schemaPathMap);
return Promise.reduce(files, readSchemaFile, schemaPathMap)
.then(schemaMap => {
logger.info('finished reading all *.%s files in %s, beginning processing….', schemaExtension, schemaPath);
return Schema.process(schemaMap, schemaPath, outDir, schemaDir, metaElements, readme, docs, argv);
.then((schemaMap) => {
info(`finished reading all *.${schemaExtension} files in ${schemaPath}, beginning processing….`);
return Schema.process(
schemaMap, schemaPath, outDir, schemaDir, metaElements,
readme, docs, argv,
);
})
.then(() => {
logger.info('Processing complete.');
info('Processing complete.');
})
.catch(err => {
logger.error(err);
.catch((err) => {
error(err);
process.exit(1);
});
})
.on('error', err => {
logger.error(err);
.on('error', (err) => {
error(err);
process.exit(1);
});
} else {
readSchemaFile(schemaPathMap, schemaPath)
.then(schemaMap => {
.then((schemaMap) => {
// eslint-disable-next-line import/no-dynamic-require, global-require
ajv.addSchema(require(schemaPath), schemaPath);
Schema.setAjv(ajv);
Schema.setSchemaPathMap(schemaPathMap);
logger.info('finished reading %s, beginning processing....', schemaPath);
return Schema.process(schemaMap, schemaPath, outDir, schemaDir, metaElements, false, docs, argv);
info(`finished reading ${schemaPath}, beginning processing...`);
return Schema.process(schemaMap, schemaPath, outDir, schemaDir,
metaElements, false, docs, argv);
})
.then(() => {
logger.info('Processing complete.');
info('Processing complete.');
})
.catch(err => {
logger.error(err);
.catch((err) => {
error(err);
process.exit(1);
});
}
Loading

0 comments on commit 36d75ea

Please sign in to comment.