# code-injector

> A library make use of gulp to generator code to specified code block.

Latest version **0.0.3** (published 2017-06-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install code-injector
pnpm add code-injector
yarn add code-injector
bun add code-injector
```

Provides the command `code-injector`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2017-06-01 |
| First published | 2017-05-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ailun She |
| Maintainers | jf3096 |
| Keywords | gulp, code generator, generate code |

## Links

- npm: https://www.npmjs.com/package/code-injector
- npm.io page: https://npm.io/package/code-injector

## Dependencies (6)

- [gulp](https://npm.io/package/gulp.md) ^3.9.1
- [commander](https://npm.io/package/commander.md) ^2.9.0
- [invariant](https://npm.io/package/invariant.md) ^2.2.2
- [camel-case](https://npm.io/package/camel-case.md) ^3.0.0
- [gulp-inject](https://npm.io/package/gulp-inject.md) ^4.2.0
- [gulp-plumber](https://npm.io/package/gulp-plumber.md) ^1.1.0

## Recent versions

- 0.0.3 (latest) — 2017-06-01
- 0.0.2 — 2017-05-31

## README

# Code Injector

A library used to generate code and inject them in target code block so that you could feel like make use of NodeJS in 
browser side. 

People nowadays use webpack more frequently than gulp. However, webpack, most of the time, makes use of babel to transform (compile)
code in memory or build files in production stage. These transformed codes are invisible as we cannot see or use them directly. Therefore, 
babel plugins sometimes may be misleading and that's the reason why I choose gulp rather than webpack or babel to achieve the purpose of code injection.

## Quick Start

```sh
npm install code-injector -g

code-injector # wait a moment brefore you do this
```

#### Command
  Usage: index [options]

  Options:

    -h, --help         output usage information
    -V, --version      output the version number
    -c, --config-path  config file, default path is generator.config.js

## Config File

Before you run the <b>code-injector</b> command, you will need to prepare a config file at the root of your project and 
named it <b>generator.config.js</b>.

A few rules you need to code and understand in this file:

```javascript
/**
* a useful function that could be used to generator any code you want
* @type {[*]}
*/
export function generatorStart() {
    return `console.time();`;
}
/**
* a useful function that could be used to generator any code you want
* @type {[*]}
*/
export function generatorEnd() {
    return `console.timeEnd();`;
}
/**
* required
* the file you want to watch and compile
*/
export const watchSrc = [`./test/index.js`];
/**
* default: generator
* prefix used to indicate which function is going to be used
* e.g. generatorTest
*/
export const prefix = `generator`;
```

## Code Block

The previous part has defined <b>generatorStart</b> and <b>generatorEnd</b>. 
So `start` represents its function return value `console.time()`, 
whereas
`end` represents its function return value `console.endTime()`,
so you could define the <b>code block</b> like this,

```javascript
/* inject:start */
/* end-inject */

// WRITE YOU OWN CODE HERE

/* inject:end */
/* end-inject */
```

## Start Now
Now you can run the command: 

```sh
code-injector
```

## TODO List

- [ ] only compile the when the code block changed

## License

MIT

---
_Source: https://npm.io/package/code-injector · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
