Version: 0.2.0
Last Updated: Unknown
Use this tempalate to generate locales for LandPad Projects
Scaffolds the locale files through locale.ejs and then finally a barrel file though barrel.ejs.
Places them as expected in a LandPad project at content/locales/[...files].
1<%_ locales.forEach(function(locale){ -%>2export * from './<%= locale %>'3<%_ }); _%>
1#!/usr/bin/env node2const path = require('path');3const dir = __dirname;4const cwd = process.cwd();56let filesErr = [];78const build = ({ dependencies, data, file, output, basedir }) => {9 dependencies.ejs.renderFile(`${dir}/${file}.ejs`, data, {}, function (10 err,11 str12 ) {13 // str => Rendered HTML string14 if (err) {15 filesErr.push(output);16 throw err;17 }1819 // output should be a mix of the Lift folder20 const outputFilePath = `${basedir}/content/locale/${output}`;21 dependencies.fs.outputFileSync(outputFilePath, str);22 });23};2425module.exports = async function (options) {26 console.log('Bridging LandPad Copy');27 try {28 const basedir = options.data.basedir29 ? path.resolve(cwd, options.data.basedir)30 : cwd;3132 const locales = Object.keys(options.data);3334 // 1. Build out the locale content files35 for (const locale of locales) {36 console.log(`\t - Scaffolding: ${locale}`);37 build({38 ...options,39 file: 'locale',40 output: `${locale}.ts`,41 basedir,42 data: {43 locale,44 copy: options.data[locale],45 },46 });47 }4849 // 2. Build out the barrel file50 console.log(`\t - Scaffolding: Locales barrel file`);51 build({52 ...options,53 file: 'barrel',54 output: `index.ts`,55 basedir,56 data: {57 locales,58 },59 });6061 return options;62 } catch (err) {63 console.error(err);64 }65};
1export const <%= locale %> = <%- JSON.stringify(copy) %>