Skip to content

Latest commit

 

History

History
160 lines (121 loc) · 3.58 KB

readme.md

File metadata and controls

160 lines (121 loc) · 3.58 KB

@randomsts/code-generator package

A lightweight CLI to recursively include all file from a directory in a single source file.

USAGE:-

  • install package
  ~ npm i @randomsts/code-generator
  # or
  ~ yarn add @randomsts/code-generator 
import CodeGenerator from '@randomsts/code-generator';
const codeGenerator = new CodeGenerator ();
codeGenerator.writeToFile ();
  • Add randoms.config.json file in the root of the project
{
  "target":  "./src",
  "include":  "^(?:[a-zA-Z0-9]+|\\[(?:\\.{3})?[a-zA-Z0-9]+\\])\\.js$",
  "outputDir": "./dist",
  "outputFile": "output.js"
}

OR

  • install package as a dev dependency
  ~ npm i @randomsts/code-generator -D
  # or
  ~ yarn add @randomsts/code-generator -D
  • Add randoms.config.json file in the root of the project
{
  "target":  "./src",
  "include":  "^(?:[a-zA-Z0-9]+|\\[(?:\\.{3})?[a-zA-Z0-9]+\\])\\.js$",
  "outputDir": "./dist",
  "outputFile": "output.js"
}
  • Add CLI in scripts
 "scripts": {
   "dev": "randoms-generator"
 },
  • test
  ~ npm run dev
  # or
  ~ yarn dev


Docs

Advance Usage

{
  "target":  "./src",
  "include":  "^(?:[a-zA-Z0-9]+|\\[(?:\\.{3})?[a-zA-Z0-9]+\\])\\.js$",
  "outputDir": "./dist",
  "outputFile": "output.js",
  "preservedFiles": {
    "./_index.js":  ["getProps"],
    "./server/_server.js": ["getServerSideProps"]
  }
}

randoms.config.json

Key DESCRIPTION
target Target folder from where to include files E.g ./src
include determines which files to include in the target folder. E.g Regex Exp.
outputDir Assign folder where to create output file. E.g ./dist
outputFile output file name. E.g ./output.js
preservedFiles Optional field!

Preserved Files:-

Key Expected named import
file relative path E.g ./_index.js arrays of expected import name E.g ["getProps"]

Example:-

/// file: randoms.config.json
"preservedFiles": {
    "./_index.js":  ["getProps"]
}

/// file: output.js // outut file
const _ = require ("./index.js");
module.exports = {
	getProps: _.getProps,
} 

Sample Output file:-

// output.js

const _ = require ("./index.js");
const __ = require ("./products/apis/mine.js");
const ___ = require ("./products/index.js");
const ____ = require ("./products/products.js");
const _____ = require ("./products/store/index.js");
const ______ = require ("./server/_server.js");
const _______ = require ("./server.js");
const ________ = require ("./tester/index.js");
const _________ = require ("./[...index].js");
const __________ = require ("./_index.js");

module.exports = { 
    default: [_,__,___,____,_____,_______,________,_________],
    /* preserved exports */
    getServerSideProps: ______.getServerSideProps,
    getProps: __________.getProps
};

contribute to this project on Github

This repository is maintained by Zain-Ul-Din

Show some ❤️ by starring this awesome repository!