templates-artist
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

Template Artist

Create applications using templates

Installation

npm install template-artist # using npm

yarn add template-artist # using yarn

Usage

import { TemplateArtist } from 'templates-artist';

TemplateArtist.createApp({
  answers: {
    name: 'John',
    lastname: 'Doe',
    folder: 'thisIsMyFolder',
    fileName: 'loremIpsumFileName',
  },
  destinationApp: '/application/destination/directory',
  templatePath: '/template/path/directory',
});

Creating templates using handlebarsjs

.template-directory
├── _index.html.hbs
├── _{{folder}}
│   ├── {{fileName}}.js
│   └── otherFile.txt
├── _assets
│   ├── file1.ts
│   └── file2.cpp

file template

Hello world! My name is {{name}}, and my lastname is {{lastname}}

App Created

.application-destination-directory
├── _index.html
├── _thisIsMyFolder
│   ├── loremIpsumFileName.js
│   └── otherFile.txt
├── _assets
│   ├── file1.ts
│   └── file2.cpp

file generated

Hello world! My name is {{name}}, and my lastname is {{lastname}}

Note: more info in https://handlebarsjs.com/guide/

Create questions within the same template

Create a simple nodejs app, install "template-artist" and finally create "template" folder with html file inside

mkdir test-template && cd ./test-template
npm init -y
npm install template-artist
touch index.js
mkdir ./template
echo "{{name}}" > ./template/index.html.hbs
/*
This script will generate a json file inside the root directory of the app with your questions called template-questions.json.
*/
import { TemplateArtistQuestions } from 'templates-artist';
(() => {
  TemplateArtistQuestions.generateQuestions({
    questions: [
      {
        type: 'input',
        message: 'Type your name',
        name: 'name',
        default: 'Jhon',
        validation: {
          opts: ['required'],
          messageError: 'your name is required',
        },
      },
    ],
    jsonFileName: 'template-questions'
  });
})();

Test your template and questions and answers

/*
This script will test your template, test your answers and questions match
*/
import { TemplateArtistQuestions, TemplateArtist } from 'templates-artist';
(() => {
  const questions = TemplateArtistQuestions.readQuestions(
    // path to questions file
  );
  const errors = TemplateArtist.test({
    answers,
    questions,
    templatePath: 'templateFolderPath'
  });

  if (errors.length == 0) {
    console.log('good!', errors);
  } else {
    console.error('something wnet wrong!', errors);
  }
})();

Authors

See also the list of contributors who participated in this project.

Readme

Keywords

none

Package Sidebar

Install

npm i templates-artist

Weekly Downloads

1

Version

0.3.0

License

MIT

Unpacked Size

152 kB

Total Files

20

Last publish

Collaborators

  • vicmans