Skip to content

sinix-dev/scaffe.js

Repository files navigation

Tests workflow

Simple scaffolding utility, inspired by Sao.js

Installation

$ npm install scaffe # yarn add scaffe

Programmatic Usage

const scaffe = require("scaffe")

async function main(){
  ...

  // create a generator instance
  const s = scaffe.generate(templateDir, outDir, { overwrite: true, variables: { name: "app" } })

  // add a file from outside the templateDir
  // the source path should be relative to templateDir
  s.add("../common/logo.png", "assets/logo.png")

  // add multiple files using glob pattern to the target project directory
  // the source path should be relative to templateDir
  s.add("../common/styles/*.scss", "static/css/")

  // ignore certain files
  s.ignore("docs/**/*.scss")

  // ignore certain folder
  s.ignore("build/**/*")

  try {
    await s;
  } catch(err) {
    console.log(err)
  }
}

Template directory can have two types of files

  • starts with _: this file will be evaluated as an ejs file
  • doesn't starts with _: this type of files will be copied as it is to the output directory.

So we can use variables in our template files in ejs format.

A use case,

// _package.json

{
  "name": "<%= appName %>"
}

variables in 3rd argument (i.e. config) will contain all variable values that need to be passed on to be processed by ejs.

MORE ON USING SCAFFE