How to use the licia.each function in licia

To help you get started, we’ve selected a few licia examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github liriliri / licia / lib / update.js View on Github external
async function detectBenchmark() {
    const files = await glob('src/*/*benchmark.js');

    let list = map(files, function(file) {
        return file
            .split('/')
            .pop()
            .replace('.benchmark.js', '');
    });

    each(list, function(modName) {
        output[modName].benchmark = true;
    });
}
github liriliri / licia / lib / update.js View on Github external
async function detectDemo() {
    const files = await glob('src/*/*.demo.html');

    let list = map(files, function(file) {
        return file
            .split('/')
            .pop()
            .replace('.demo.html', '');
    });

    each(list, function(modName) {
        output[modName].demo = true;
    });
}
github liriliri / licia / lib / update.js View on Github external
each(comments, function(comment) {
            let lines = trim(comment).split('\n');
            if (trim(lines[0]) !== 'module') return;
            lines.shift();
            each(lines, function(line) {
                let splitterPos = line.indexOf(':');
                let name = trim(line.slice(0, splitterPos));
                let val = trim(line.slice(splitterPos + 1));
                if (name === 'env') {
                    if (val === 'all') {
                        val = ['node', 'browser', 'miniprogram'];
                    } else {
                        val = val.split(/\s+/g);
                    }
                }
                if (name === 'test') {
                    if (val === 'manual') {
                        val = [];
                    } else if (val === 'all') {
                        val = ['node', 'browser'];
                    } else {
github liriliri / licia / lib / pack.js View on Github external
function extractTsDefinition(data, modName, dependencies) {
    const comments = extractBlockCmts(data);

    let tsDefinition = '';

    each(comments, comment => {
        comment = trim(comment);
        if (startWith(comment, 'typescript')) {
            tsDefinition = comment.replace(/^typescript/, '');
            tsDefinition = outdentOneSpace(tsDefinition);
            tsDefinition = tsDefinition.replace(/export declare/g, 'declare');
            tsDefinition += '\n\nexport = ' + modName;
        }
    });

    let imports = '';

    if (dependencies) {
        const len = dependencies.length;
        each(dependencies, (val, i) => {
            if (!contain(tsDefinition, val)) return;
github liriliri / licia / lib / pack.js View on Github external
async function genPackage(pkgName, files) {
    await mkdir('.licia/packages/' + pkgName);
    if (pkgName === 'miniprogram-licia') {
        await mkdir(`.licia/packages/${pkgName}/miniprogram_dist`);
    }
    for (const file of files) {
        await genFile(file, pkgName);
    }
    await cpFile('./README.md', '.licia/packages/' + pkgName + '/README.md');

    let packInfo = require('../package.json');
    packInfo.name = pkgName;
    each(['bin', 'scripts', 'devDependencies'], function(val) {
        delete packInfo[val];
    });

    if (pkgName === 'licia') {
        packInfo.main = './node.js';
        packInfo.browser = './browser.js';
        await genIndex(pkgName);
    }
    if (pkgName === 'miniprogram-licia') {
        packInfo.main = 'miniprogram_dist/index.js';
        packInfo.miniprogram = 'miniprogram_dist';
        await genIndex(pkgName);
    }

    await fs.writeFile(
        path.resolve('.licia/packages/' + pkgName + '/package.json'),
github liriliri / licia / lib / pack.js View on Github external
async function genIndex(pkgName) {
    const mods = {
        browser: [],
        node: [],
        miniprogram: []
    };

    each(modData, (mod, modName) => {
        if (contain(mod.env, 'browser')) {
            mods.browser.push(modName);
        }
        if (contain(mod.env, 'node')) {
            mods.node.push(modName);
        }
        if (contain(mod.env, 'miniprogram')) {
            mods.miniprogram.push(modName);
        }
    });

    if (pkgName === 'licia') {
        for (const type of ['browser', 'node']) {
            const modNames = mods[type];
            let data = '';
            let tsData = '';
github liriliri / licia / lib / pack.js View on Github external
mods.browser.push(modName);
        }
        if (contain(mod.env, 'node')) {
            mods.node.push(modName);
        }
        if (contain(mod.env, 'miniprogram')) {
            mods.miniprogram.push(modName);
        }
    });

    if (pkgName === 'licia') {
        for (const type of ['browser', 'node']) {
            const modNames = mods[type];
            let data = '';
            let tsData = '';
            each(modNames, name => {
                data += `exports.${name} = require('./${name}');\n`;
                tsData += `export import ${name} = require('./${name}');\n`;
            });
            await fs.writeFile(
                path.resolve(`.licia/packages/licia/${type}.js`),
                data,
                'utf8'
            );
            await fs.writeFile(
                path.resolve(`.licia/packages/licia/${type}.d.ts`),
                tsData,
                'utf8'
            );
        }
    } else {
        const modNames = mods.miniprogram;
github liriliri / licia / lib / pack.js View on Github external
each(comments, comment => {
        comment = trim(comment);
        if (startWith(comment, 'typescript')) {
            tsDefinition = comment.replace(/^typescript/, '');
            tsDefinition = outdentOneSpace(tsDefinition);
            tsDefinition = tsDefinition.replace(/export declare/g, 'declare');
            tsDefinition += '\n\nexport = ' + modName;
        }
    });

    let imports = '';

    if (dependencies) {
        const len = dependencies.length;
        each(dependencies, (val, i) => {
            if (!contain(tsDefinition, val)) return;

            imports += 'import ' + val + " = require('./" + val + "');";

            if (i !== len - 1) imports += '\n';
        });
    }

    if (imports) {
        tsDefinition = imports + '\n\n' + tsDefinition;
    }

    return tsDefinition;
}
github liriliri / licia / lib / pack.js View on Github external
function transToCommonjs(data, dependencies, isEs5) {
    data = trim(data);
    data += '\n\nmodule.exports = exports;\n';

    if (!dependencies) return data;

    let requires = '';
    const len = dependencies.length;

    each(dependencies, (val, i) => {
        requires +=
            (isEs5 ? 'var ' : 'const ') + val + " = require('./" + val + "');";

        if (i !== len - 1) requires += '\n';
    });

    if (requires) {
        requires = '\n\n' + requires;
    }

    data = data.replace(regDependence, requires);

    return data;
}