Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let defaultDirectoryMeta = JSON.parse(fs.readFileSync(path.join(resources, common.defaultLang, directoryMetaFile)));
let defaultCaption = JSON.parse(fs.readFileSync(path.join(resources, common.defaultLang, captionFile)));
let defaultGuides = Enumerable(fs.readdirSync(path.join(resources, common.defaultLang, 'guides'))).where(name => path.extname(name) === jsonExt).orderBy(element => path.basename(element, jsonExt), Enumerable.comparers.array([
"instance", "use", "config", "selector", "predicate", "comparer", "action", "setter", "iterator"
], true)).toArray();
let defaultApis = Enumerable(fs.readdirSync(path.join(resources, common.defaultLang, 'apis'))).where(name => path.extname(name) === jsonExt).orderBy(element => path.basename(element, jsonExt)).toArray();
// let defaultChanges = Enumerable(fs.readdirSync(path.join(resources, common.defaultLang, 'change'))).where(name => path.extname(name) === jsonExt).orderBy(element => path.basename(element, jsonExt), (element, other) => {
// if (element === other) {
// return 0;
// } else if (common.isNewer(element, other)) {
// return -1;
// } else {
// return 1;
// }
// }).toArray();
let defaultChanges = Enumerable(fs.readdirSync(path.join(resources, common.defaultLang, 'change'))).where(name => path.extname(name) === jsonExt).orderBy(element => path.basename(element, jsonExt), Enumerable.comparers.less(common.isNewer)).toArray();
common.versions = Enumerable.select(defaultChanges, change => path.basename(change, jsonExt)).toArray();
fs.writeFileSync(path.join(resources, 'versions.json'), JSON.stringify(common.versions));
let versions = [...common.versions];
if (!versions[versions.length - 1].endsWith('pre')) versions.push(common.preVersion(versions[versions.length - 1]));
fs.writeFileSync(path.join(scripts, 'histroy.js'), 'module.exports = (version, callback, pre, post) => { ' + versions.reverse().map(version => `if (version === '${ version }') return require.ensure([], function(require) { if (callback) { pre && pre(); callback(require('${ common.module(version) }')); post && post(); } }, '${ common.module(version) }');`).join(' else ') + ' };');
console.log('apis:' + defaultApis);
let langNames = fs.readdirSync(resources);
for (let langName of langNames) {
if (typeof refreshLangName !== 'undefined' && common.defaultLang !== refreshLangName && langName !== refreshLangName) {
continue;
}
let langPath = path.join(resources, langName);
if (fs.statSync(langPath).isDirectory()) {
let defaultGuides = Enumerable(fs.readdirSync(path.join(resources, common.defaultLang, 'guides'))).where(name => path.extname(name) === jsonExt).orderBy(element => path.basename(element, jsonExt), Enumerable.comparers.array([
"instance", "use", "config", "selector", "predicate", "comparer", "action", "setter", "iterator"
], true)).toArray();
let defaultApis = Enumerable(fs.readdirSync(path.join(resources, common.defaultLang, 'apis'))).where(name => path.extname(name) === jsonExt).orderBy(element => path.basename(element, jsonExt)).toArray();
// let defaultChanges = Enumerable(fs.readdirSync(path.join(resources, common.defaultLang, 'change'))).where(name => path.extname(name) === jsonExt).orderBy(element => path.basename(element, jsonExt), (element, other) => {
// if (element === other) {
// return 0;
// } else if (common.isNewer(element, other)) {
// return -1;
// } else {
// return 1;
// }
// }).toArray();
let defaultChanges = Enumerable(fs.readdirSync(path.join(resources, common.defaultLang, 'change'))).where(name => path.extname(name) === jsonExt).orderBy(element => path.basename(element, jsonExt), Enumerable.comparers.less(common.isNewer)).toArray();
common.versions = Enumerable.select(defaultChanges, change => path.basename(change, jsonExt)).toArray();
fs.writeFileSync(path.join(resources, 'versions.json'), JSON.stringify(common.versions));
let versions = [...common.versions];
if (!versions[versions.length - 1].endsWith('pre')) versions.push(common.preVersion(versions[versions.length - 1]));
fs.writeFileSync(path.join(scripts, 'histroy.js'), 'module.exports = (version, callback, pre, post) => { ' + versions.reverse().map(version => `if (version === '${ version }') return require.ensure([], function(require) { if (callback) { pre && pre(); callback(require('${ common.module(version) }')); post && post(); } }, '${ common.module(version) }');`).join(' else ') + ' };');
console.log('apis:' + defaultApis);
let langNames = fs.readdirSync(resources);
for (let langName of langNames) {
if (typeof refreshLangName !== 'undefined' && common.defaultLang !== refreshLangName && langName !== refreshLangName) {
continue;
}
let langPath = path.join(resources, langName);
if (fs.statSync(langPath).isDirectory()) {
let caption = defaultCaption;
let captionPath = path.join(langPath, captionFile);
const createDirectory = refreshLangName => {
let defaultDirectoryMeta = JSON.parse(fs.readFileSync(path.join(resources, common.defaultLang, directoryMetaFile)));
let defaultCaption = JSON.parse(fs.readFileSync(path.join(resources, common.defaultLang, captionFile)));
let defaultGuides = Enumerable(fs.readdirSync(path.join(resources, common.defaultLang, 'guides'))).where(name => path.extname(name) === jsonExt).orderBy(element => path.basename(element, jsonExt), Enumerable.comparers.array([
"instance", "use", "config", "selector", "predicate", "comparer", "action", "setter", "iterator"
], true)).toArray();
let defaultApis = Enumerable(fs.readdirSync(path.join(resources, common.defaultLang, 'apis'))).where(name => path.extname(name) === jsonExt).orderBy(element => path.basename(element, jsonExt)).toArray();
// let defaultChanges = Enumerable(fs.readdirSync(path.join(resources, common.defaultLang, 'change'))).where(name => path.extname(name) === jsonExt).orderBy(element => path.basename(element, jsonExt), (element, other) => {
// if (element === other) {
// return 0;
// } else if (common.isNewer(element, other)) {
// return -1;
// } else {
// return 1;
// }
// }).toArray();
let defaultChanges = Enumerable(fs.readdirSync(path.join(resources, common.defaultLang, 'change'))).where(name => path.extname(name) === jsonExt).orderBy(element => path.basename(element, jsonExt), Enumerable.comparers.less(common.isNewer)).toArray();
common.versions = Enumerable.select(defaultChanges, change => path.basename(change, jsonExt)).toArray();
fs.writeFileSync(path.join(resources, 'versions.json'), JSON.stringify(common.versions));
}
for (let api of defaultApis) {
let apiPath = path.join(apisPath, api);
try {
let apiContent = JSON.parse(fs.readFileSync(path.join(resources, common.defaultLang, 'apis', api)));
if (fs.existsSync(apiPath)) {
apiContent = extend(true, [], apiContent, JSON.parse(fs.readFileSync(apiPath)));
}
let since = apiContent.since || common.lastest, deprecated = apiContent.deprecated || common.newest;
for (let method of (apiContent.methods || [])) {
since = common.minVersion(Enumerable.min(common.histroys(method.histroys), histroy => histroy.since, common.versionComparer), since);
deprecated = common.maxVersion(Enumerable.max(common.histroys(method.histroys), histroy => histroy.deprecated || common.lastest, common.versionComparer), deprecated);
}
for (let property of (apiContent.properties || [])) {
since = common.minVersion(Enumerable.min(common.histroys(property.histroys), histroy => histroy.since, common.versionComparer), since);
deprecated = common.maxVersion(Enumerable.max(common.histroys(property.histroys), histroy => histroy.deprecated || common.lastest, common.versionComparer), deprecated);
}
apis.children.push({
code: path.basename(api, jsonExt),
title: `${ apiContent.name || path.basename(api, jsonExt) } ${ common.capitalize(caption[apiContent.type]) }`,
since: since,
deprecated: deprecated
});
} catch(e) {
console.error(e);
}
}
directorys.splice(directorys.indexOf("apis"), 1, apis);
fs.writeFileSync(path.join(langPath, directoryFile), JSON.stringify(directorys, null, '\t'));
console.log(`Directory file for language ${ langName } is created`);
}
});
}
for (let api of defaultApis) {
let apiPath = path.join(apisPath, api);
try {
let apiContent = JSON.parse(fs.readFileSync(path.join(resources, common.defaultLang, 'apis', api)));
if (fs.existsSync(apiPath)) {
apiContent = extend(true, [], apiContent, JSON.parse(fs.readFileSync(apiPath)));
}
let since = apiContent.since || common.lastest, deprecated = apiContent.deprecated || common.newest;
for (let method of (apiContent.methods || [])) {
since = common.minVersion(Enumerable.min(common.histroys(method.histroys), histroy => histroy.since, common.versionComparer), since);
deprecated = common.maxVersion(Enumerable.max(common.histroys(method.histroys), histroy => histroy.deprecated || common.lastest, common.versionComparer), deprecated);
}
for (let property of (apiContent.properties || [])) {
since = common.minVersion(Enumerable.min(common.histroys(property.histroys), histroy => histroy.since, common.versionComparer), since);
deprecated = common.maxVersion(Enumerable.max(common.histroys(property.histroys), histroy => histroy.deprecated || common.lastest, common.versionComparer), deprecated);
}
apis.children.push({
code: path.basename(api, jsonExt),
title: `${ apiContent.name || path.basename(api, jsonExt) } ${ common.capitalize(caption[apiContent.type]) }`,
since: since,
deprecated: deprecated
});
} catch(e) {
console.error(e);
}
}
directorys.splice(directorys.indexOf("apis"), 1, apis);
fs.writeFileSync(path.join(langPath, directoryFile), JSON.stringify(directorys, null, '\t'));
console.log(`Directory file for language ${ langName } is created`);
isOlder(version, basaVersion) {
let v = Enumerable.zip(asVersion(version || this.newest).split('.'), asVersion(basaVersion).split('.'), (ver, baseVer) => ({ ver, baseVer })).firstOrDefault({ ver: 0, baseVer: 0 }, v => v.ver !== v.baseVer);
return parseInt(v.ver) >= parseInt(v.baseVer);
},
capitalize(value) {
get lastest() {
return Enumerable.last(this.versions, version => !isPre.test(version));
},
get newest() {
}, () => {
delete Object.prototype.asEnumerable;
delete Array.prototype.asEnumerable;
delete String.prototype.asEnumerable;
delete Map.prototype.asEnumerable;
delete Set.prototype.asEnumerable;
Enumerable.config.extends.array = false;
}, () => {
delete Object.prototype.asEnumerable;
maxVersion(...versions) {
return Enumerable.max(versions, '', this.versionComparer);
},
minVersion(...versions) {
minVersion(...versions) {
return Enumerable.min(versions, '', this.versionComparer);
},
isNewer(version, basaVersion) {