Back to home

schematics/

file

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 type: 'select',
37 name: 'tier',
38 message: 'What tier schematic is this?',
39 choices: [
40 { title: 'atoms', value: 'atoms' },
41 { title: 'molecules', value: 'molecules' },
42 { title: 'organisms', value: 'organisms' },
43 { title: 'templates', value: 'templates' },
44 ],
45 },
46 ];
47 const prompts = await options.dependencies.prompts(questions);
48
49 const files = await options.dependencies.recursiveReaddir(dir, ['!*.ejs']);
50 const basedir = options.data.basedir
51 ? path.resolve(cwd, options.data.basedir, prompts.name)
52 : path.resolve(cwd, `.schematics/${prompts.tier}`, prompts.name);
53
54 options.data = {
55 ...options.data,
56 ...prompts,
57 };
58
59 for (const file of files) {
60 let filepath = file.replace(dir + '/', '');
61 console.log(`\t - Scaffolding: ${filepath}`);
62 build({ ...options, ...prompts, file, output: map[filepath], basedir });
63 }
64
65 return options;
66 } catch (err) {
67 console.error(err);
68 }
69};

Install


Lift generate


Repository

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

Sections