Giter Club home page Giter Club logo

code-generator's Introduction

@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!

code-generator's People

Contributors

zain-ul-din avatar

Stargazers

 avatar

code-generator's Issues

Es6 modules support

So far @randoms-pkg/code-generator is only generating files that have commonjs imports.

There are several options we could support:

  • Es6 modules imports.
  • Add an Optional field type that will describe the modules type.

Example

 # Es6 module
 import _ from 'path';

 # commonjs
 const _ = require ('path');
 "type": "commonjs" | "module"

code intelligence for config file

General Proposal

Our code-generator require randoms.config.json to read the config provided by the user.

But there is no code intelligence for that I propose to have a JS file instead of a JSON file we can use TS type annotation comment to enable code intelligence.

Example

export type from our package

export default interface ConfigType { /* Config Type */}

randoms.config.js will looks like

 /** @type {import('package').ConfigType} */
 module.exports = { /* config */ }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.