Back to home

schematics/

molecules

Version: 0.3.0

Last Updated: Unknown


Schematics Helper

Requires name.

Module files

1#!/usr/bin/env node
2const path = require('path');
3const fs = require('fs');
4const dir = __dirname;
5const cwd = process.cwd();
6const map = JSON.parse(
7 fs.readFileSync(path.resolve(dir, './map.json'), 'utf-8'),
8);
9
10let filesErr = [];
11
12const build = ({ dependencies, data, file, output, basedir }) => {
13 dependencies.ejs.renderFile(file, data, {}, function (err, str) {
14 // str => Rendered HTML string
15 if (err) {
16 filesErr.push(output);
17 throw err;
18 }
19
20 const outputFilePath = `${basedir}/${output}`;
21 dependencies.fs.outputFileSync(outputFilePath, str);
22 });
23};
24
25module.exports = async function (options) {
26 console.log('Bridging Atom for Schematics');
27 try {
28 // prompts for questions
29 const questions = [
30 {
31 type: 'text',
32 name: 'name',
33 message: 'What is the name of the new schematic?',
34 },
35 ];
36 const prompts = await options.dependencies.prompts(questions);
37
38 const files = await options.dependencies.recursiveReaddir(dir, ['!*.ejs']);
39 const basedir = options.data.basedir
40 ? path.resolve(cwd, options.data.basedir, prompts.name)
41 : path.resolve(cwd, '.schematics/modules', prompts.name);
42
43 options.data = {
44 ...options.data,
45 ...prompts,
46 };
47
48 for (const file of files) {
49 let filepath = file.replace(dir + '/', '');
50 console.log(`\t - Scaffolding: ${filepath}`);
51 build({ ...options, ...prompts, file, output: map[filepath], basedir });
52 }
53
54 return options;
55 } catch (err) {
56 console.error(err);
57 }
58};

Install


Lift generate


Repository

https://github.com/okeeffed/pkg-lift-schematics

Sections