Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(async function() {
await mkdir(path.resolve(`.licia/packages/licia-uglify`));
const _keys = keys(modData);
for (let i = 0, len = _keys.length; i < len; i++) {
const key = _keys[i];
const data = modData[key];
if (!contain(data.env, 'browser') && !contain(data.env, 'miniprogram'))
continue;
const srcPath = path.resolve(`.licia/packages/licia/${key}.js`);
const output = uglifyJs.minify(await fs.readFile(srcPath, 'utf8'));
if (output.error) {
console.log(`Something wrong with ${key}: ${output.error}`);
process.exit(1);
}
const outputPath = path.resolve(
`.licia/packages/licia-uglify/${key}.js`
);
await fs.writeFile(outputPath, output.code, 'utf8');
}
})();
async function extractInfo() {
const files = await glob('src/*/*.js', {
ignore: ['src/*/*.*.js']
});
const regDependency = /\s*\b_\(\s*['"]([\w\s$]+)['"]\s*\);?/m;
for (const file of files) {
let modName = last(file.split('/')).slice(0, -3);
const data = await fs.readFile(file, 'utf8');
let desc = 'No description.';
let comments = extractBlockCmts(data);
if (comments.length > 0) {
desc = trim(comments[0]).split('\n')[0];
}
let modInfo = extend(
{
description: desc,
dependencies: extractDependencies(data)
},
extractCmts(comments)
);
output[modName] = modInfo;
async function genFile(file, pkgName) {
let modName = last(file.split('/')).slice(0, -3);
let data = await fs.readFile(file, 'utf8');
const env = modData[modName].env;
const isEs5 = contain(env, 'browser') || contain(env, 'miniprogram');
if (isEs5 && pkgName !== 'licia-src') {
data = await transBabel(data);
}
if (pkgName === 'miniprogram-licia') {
if (!contain(env, 'miniprogram')) {
return;
}
}
data = data.replace(/\/\* module[\s\S]*?\*\//m, '');
if (pkgName === 'eustia-module') {
await fs.writeFile(
await eustiaBuild({
include: keys(output),
enableLog: true,
library: '$_abcdefghijklmnopqrstuvwxyz'
.split('')
.map(val => 'src/' + val),
output: '.licia/testUtil/doc.js',
ts: true
});
await eustiaDoc({
input: '.licia/testUtil/doc.js',
format: 'md',
title: 'Licia Documentation',
output: OUTPUT_DOC_PATH
});
let doc = await fs.readFile(OUTPUT_DOC_PATH, 'utf8');
doc = doc.replace(regTsIgnore, '');
await fs.writeFile(OUTPUT_DOC_PATH, doc, 'utf8');
genI18n();
}
async function genI18n() {
let doc = await fs.readFile(OUTPUT_DOC_PATH, 'utf8');
doc = splitH2(doc);
const i18n = {};
for (let i = 0, len = doc.length; i < len; i++) {
const name = doc[i].name;
const i18nPath =
'src/' + name[0].toLowerCase() + '/' + name + '.i18n.md';
if (await fs.exists(i18nPath)) {
let doc = await fs.readFile(i18nPath, 'utf8');
let code = await fs.readFile(
i18nPath.replace('.i18n.md', '.js'),
'utf8'
);
let comments = extractBlockCmts(code);
let example = '';
comments.forEach(comment => {
comment = trim(comment);
if (startWith(comment, 'example')) {
example = comment.replace(/^example/, '');
example = outdentOneSpace(example);
example = example.replace(regTsIgnore, '');
example = '```javascript\n' + trim(example) + '\n```';
}
});
doc = splitH2(doc);
async function genI18n() {
let doc = await fs.readFile(OUTPUT_DOC_PATH, 'utf8');
doc = splitH2(doc);
const i18n = {};
for (let i = 0, len = doc.length; i < len; i++) {
const name = doc[i].name;
const i18nPath =
'src/' + name[0].toLowerCase() + '/' + name + '.i18n.md';
if (await fs.exists(i18nPath)) {
let doc = await fs.readFile(i18nPath, 'utf8');
let code = await fs.readFile(
i18nPath.replace('.i18n.md', '.js'),
'utf8'
);
let comments = extractBlockCmts(code);
let example = '';
exports.readTpl = async function(name, cb) {
const data = await fs.readFile(
path.resolve(__dirname, './tpl/' + name + '.hbs'),
'utf-8'
);
return handlebars.compile(data, { noEscape: true });
};