How to use the licia.fs.writeFile 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 / es5.js View on Github external
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');
    }
})();
github liriliri / licia / lib / update.js View on Github external
async function writeOutput() {
    await fs.writeFile(
        OUTPUT_PATH,
        JSON.stringify(sortKeys(output, { deep: true }), null, 4),
        'utf8'
    );

    console.log('Index file generated: ' + OUTPUT_PATH);
}
github liriliri / licia / lib / update.js View on Github external
}
    }

    const locales = ['CN'];

    for (let i = 0, len = locales.length; i < len; i++) {
        const locale = locales[i];
        let output = doc.map(mod => {
            mod = clone(mod);
            if (i18n[locale] && i18n[locale][mod.name]) {
                mod.content = i18n[locale][mod.name];
            }
            return '## ' + mod.name + '\n\n' + mod.content;
        });
        output = output.join('\n\n');
        await fs.writeFile('DOC_' + locale + '.md', output, 'utf8');
        console.log('DOC_' + locale + '.md generated');
    }
}
github liriliri / licia / lib / pack.js View on Github external
if (pkgName !== 'licia-src') {
            data = stripCmt(data);
        }

        let outputPath = path.resolve(
            './.licia/packages/' + pkgName,
            modName + '.js'
        );
        if (pkgName === 'miniprogram-licia') {
            outputPath = path.resolve(
                `./.licia/packages/${pkgName}/miniprogram_dist`,
                modName + '.js'
            );
        }

        await fs.writeFile(outputPath, data, 'utf-8');
    }
}
github liriliri / licia / lib / pack.js View on Github external
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;
        let data = '';
        each(modNames, name => {
            data += `exports.${name} = require('./${name}');\n`;
        });
        await fs.writeFile(
            path.resolve(
                `.licia/packages/miniprogram-licia/miniprogram_dist/index.js`
            ),
            data,
github liriliri / licia / lib / pack.js View on Github external
path.resolve('./.licia/packages/' + pkgName, modName + '.js'),
            data,
            'utf-8'
        );
    } else {
        const dependencies = extractDependencies(data);
        data = transToCommonjs(data, dependencies, isEs5);

        if (pkgName === 'licia') {
            const tsDefinition = extractTsDefinition(
                data,
                modName,
                dependencies
            );
            if (tsDefinition) {
                await fs.writeFile(
                    path.resolve(
                        './.licia/packages/' + pkgName,
                        modName + '.d.ts'
                    ),
                    tsDefinition,
                    'utf-8'
                );
            }
        }

        if (pkgName !== 'licia-src') {
            data = stripCmt(data);
        }

        let outputPath = path.resolve(
            './.licia/packages/' + pkgName,
github liriliri / licia / lib / pack.js View on Github external
}
        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;
        let data = '';
        each(modNames, name => {
            data += `exports.${name} = require('./${name}');\n`;
        });
github liriliri / licia / lib / pack.js View on Github external
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(
            path.resolve('./.licia/packages/' + pkgName, modName + '.js'),
            data,
            'utf-8'
        );
    } else {
        const dependencies = extractDependencies(data);
        data = transToCommonjs(data, dependencies, isEs5);

        if (pkgName === 'licia') {
            const tsDefinition = extractTsDefinition(
                data,
                modName,
                dependencies
            );
            if (tsDefinition) {
                await fs.writeFile(
github liriliri / licia / lib / pack.js View on Github external
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'),
        JSON.stringify(packInfo, null, 2),
        'utf8'
    );
}