mirror of
https://github.com/chenasraf/simple-scaffold.git
synced 2026-05-18 01:29:09 +00:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f98d469a3 | ||
|
|
cd25b04886 | ||
|
|
5cd637f41f | ||
|
|
0a4467ae5f | ||
|
|
713a0ed44f | ||
|
|
edec2d1c26 | ||
|
|
2e12907412 | ||
|
|
5b7e0e30f1 | ||
|
|
09238300cd | ||
|
|
552614ca3f | ||
|
|
813f706cf0 | ||
|
|
1bc2221472 | ||
|
|
f07affa124 | ||
|
|
ce22a2c34c | ||
|
|
7c0c347002 | ||
|
|
977288ae5a | ||
|
|
4afafa5a4a | ||
|
|
7bee2a51c7 | ||
|
|
d4c049baaf | ||
|
|
06590c4b6e | ||
|
|
c4f2dfb04f | ||
|
|
a410b79195 |
3
.prettierrc
Normal file
3
.prettierrc
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"semi": false
|
||||
}
|
||||
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -1,3 +1,4 @@
|
||||
{
|
||||
"typescript.tsdk": "./node_modules/typescript/lib"
|
||||
}
|
||||
"typescript.tsdk": "./node_modules/typescript/lib",
|
||||
"npm.packageManager": "yarn"
|
||||
}
|
||||
52
.vscode/tasks.json
vendored
52
.vscode/tasks.json
vendored
@@ -1,7 +1,47 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "webpack",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"showOutput": "always"
|
||||
}
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"script": "build",
|
||||
"label": "build",
|
||||
"type": "npm",
|
||||
"problemMatcher": [],
|
||||
},
|
||||
{
|
||||
"script": "dev",
|
||||
"label": "dev",
|
||||
"type": "npm",
|
||||
"problemMatcher": [],
|
||||
},
|
||||
{
|
||||
"script": "start",
|
||||
"label": "start",
|
||||
"type": "npm",
|
||||
"problemMatcher": [],
|
||||
},
|
||||
{
|
||||
"script": "test",
|
||||
"label": "test",
|
||||
"type": "npm",
|
||||
"problemMatcher": [],
|
||||
},
|
||||
{
|
||||
"script": "cmd",
|
||||
"label": "cmd",
|
||||
"type": "npm",
|
||||
"problemMatcher": [],
|
||||
},
|
||||
{
|
||||
"script": "build-test",
|
||||
"label": "build-test",
|
||||
"type": "npm",
|
||||
"problemMatcher": [],
|
||||
},
|
||||
{
|
||||
"script": "build-cmd",
|
||||
"label": "build-cmd",
|
||||
"type": "npm",
|
||||
"problemMatcher": [],
|
||||
},
|
||||
],
|
||||
}
|
||||
110
README.md
110
README.md
@@ -1,7 +1,9 @@
|
||||
# simple-scaffold
|
||||
|
||||
Simple Scaffold allows you to create your structured files based on templates.
|
||||
|
||||
## Install
|
||||
|
||||
You can either use it as a command line tool or import into your own code and run from there.
|
||||
|
||||
```bash
|
||||
@@ -12,13 +14,31 @@ yarn [global] add simple-scaffold
|
||||
```
|
||||
|
||||
## Use as a command line tool
|
||||
The first non-token argument (that has no `--` prefix) will be used as the scaffold name.
|
||||
The rest is ignored, of course except for the available arguments below.
|
||||
|
||||
```bash
|
||||
simple-scaffold MyComponent --template scaffolds/component/**/* \
|
||||
--output src/components \
|
||||
--locals myProp="propname",myVal=123
|
||||
### Command Line Options
|
||||
|
||||
```plaintext
|
||||
Scaffold Generator
|
||||
|
||||
Generate scaffolds for your project based on file templates.
|
||||
Usage: simple-scaffold scaffold-name [options]
|
||||
|
||||
Options
|
||||
|
||||
-n, --name string Component output name
|
||||
-t, --templates File[] A glob pattern of template files to load.
|
||||
A template file may be of any type and extension, and supports Handlebars as
|
||||
a parsing engine for the file names and contents, so you may customize both
|
||||
with variables from your configuration.
|
||||
-o, --output File The output directory to put the new files in. They will attempt to maintain
|
||||
their regular structure as they are found, if possible.
|
||||
-l, --locals JSON string A JSON string for the template to use in parsing.
|
||||
-w, --overwrite Boolean Whether to overwrite files when they are found to already exist. Default=true
|
||||
-q, --quiet Boolean When set to true, logs will not output (including warnings and errors).
|
||||
Default=false
|
||||
-S, --create-sub-folder Boolean Whether to create a subdirectory with {{Name}} in the output directory.
|
||||
Default=true
|
||||
-h, --help Display this help message
|
||||
```
|
||||
|
||||
You can add this as a script in your `package.json`:
|
||||
@@ -26,69 +46,59 @@ You can add this as a script in your `package.json`:
|
||||
```json
|
||||
{
|
||||
"scripts": {
|
||||
"scaffold": "node node_modules/simple-scaffold/dist/cmd.js --template scaffolds/component/**/* --output src/components --locals myProp=\"propname\",myVal=123"
|
||||
"scaffold": "yarn simple-scaffold --template scaffolds/component/**/* --output src/components --locals myProp=\"propname\",myVal=123"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Scaffolding
|
||||
|
||||
Scaffolding will replace {{vars}} in both the file name and its contents and put the transformed files
|
||||
in `<output>/<{{Name}}`.
|
||||
in `<output>/<{{Name}}>`, as per the Handlebars formatting rules.
|
||||
|
||||
Your context will be pre-populated with the following:
|
||||
|
||||
- `{{Name}}`: CapitalizedName of the component
|
||||
- `{{name}}`: camelCasedName of the component
|
||||
|
||||
Any `locals` you add in the config will populate with their names wrapped in `{{` and `}}`.
|
||||
They are all stringified, so be sure to parse them accordingly by creating a script, if necessary.
|
||||
|
||||
### Command line options
|
||||
##### `--template glob [--template glob2 [...]]` (required) (alias: -t)
|
||||
A glob pattern of template files to load.
|
||||
|
||||
A template file may be of any type and extension, and supports [Handlebars](https://handlebarsjs.com) as a parsing engine for the file names and contents, so you may customize both with variables from your configuration.
|
||||
|
||||
You can load more than one template list by simple adding more `--template` arguments.
|
||||
|
||||
##### `--output path` (optional) (alias -o)
|
||||
The output directory to put the new files in. They will attempt to maintain their regular structure as they are found, if possible.
|
||||
|
||||
Your new scaffold will be placed under a directory with the scaffold name from the argumemts.
|
||||
|
||||
You may also pass a function to transform the output path for each file individually.
|
||||
This function takes 2 arguments: filename, and base glob path
|
||||
|
||||
##### `--locals key=value [--locals key=value [,...]]` (optional) (alias: -l)
|
||||
Pass a KV map to the template for parsing.
|
||||
|
||||
##### `--create-sub-folder [true|false]` (optional) (alias -S) (default: true)
|
||||
Whether to create a subfolder for the output with all the files inside, or simply dump them directly in the output folder.
|
||||
|
||||
#####
|
||||
|
||||
### Use in Node.js
|
||||
|
||||
You can also build the scaffold yourself, if you want to create more complex arguments or scaffold groups.
|
||||
Simply pass a config object to the constructor, and invoke `run()` when you are ready to start.
|
||||
The config takes similar arguments to the command line:
|
||||
|
||||
```javascript
|
||||
const SimpleScaffold = require('simple-scaffold').default
|
||||
const SimpleScaffold = require("simple-scaffold").default
|
||||
|
||||
const scaffold = new SimpleScaffold({
|
||||
name: 'component',
|
||||
templates: [path.join(__dirname, 'scaffolds', 'component')],
|
||||
output: path.join(__dirname, 'src', 'components'),
|
||||
name: "component",
|
||||
templates: [path.join(__dirname, "scaffolds", "component")],
|
||||
output: path.join(__dirname, "src", "components"),
|
||||
createSubFolder: true,
|
||||
locals: {
|
||||
property: 'value',
|
||||
}
|
||||
property: "value",
|
||||
},
|
||||
}).run()
|
||||
```
|
||||
|
||||
The exception in the config is that `output`, when used in Node directly, may also be passed a
|
||||
function for each input file to output into a dynamic path:
|
||||
|
||||
```javascript
|
||||
config.output = (fullPath, baseDir, baseName) => {
|
||||
console.log({ fullPath, baseDir, baseName })
|
||||
return [baseDir, baseName].join(path.sep)
|
||||
}
|
||||
```
|
||||
|
||||
## Example Scaffold Input
|
||||
|
||||
### Input Directory structure
|
||||
```
|
||||
### Input directory structure
|
||||
|
||||
```plaintext
|
||||
- project
|
||||
- scaffold
|
||||
- {{Name}}.js
|
||||
@@ -98,6 +108,7 @@ const scaffold = new SimpleScaffold({
|
||||
```
|
||||
|
||||
#### project/scaffold/{{Name}}.js
|
||||
|
||||
```js
|
||||
const React = require('react')
|
||||
|
||||
@@ -109,16 +120,19 @@ module.exports = class {{Name}} extends React.Component {
|
||||
```
|
||||
|
||||
### Run Example
|
||||
|
||||
```bash
|
||||
simple-scaffold MyComponent \
|
||||
--template project/scaffold/**/* \
|
||||
--output src/components \
|
||||
--locals 'className=my-component`
|
||||
-t project/scaffold/**/* \
|
||||
-o src/components \
|
||||
-l className=my-component
|
||||
```
|
||||
|
||||
## Example Scaffold Output
|
||||
#### Directory structure
|
||||
```
|
||||
|
||||
### Output directory structure
|
||||
|
||||
```plaintext
|
||||
- project
|
||||
- src
|
||||
- components
|
||||
@@ -128,7 +142,8 @@ simple-scaffold MyComponent \
|
||||
```
|
||||
|
||||
With `createSubfolder = false`:
|
||||
```
|
||||
|
||||
```plaintext
|
||||
- project
|
||||
- src
|
||||
- components
|
||||
@@ -137,8 +152,9 @@ With `createSubfolder = false`:
|
||||
```
|
||||
|
||||
#### project/scaffold/MyComponent/MyComponent.js
|
||||
|
||||
```js
|
||||
const React = require('react')
|
||||
const React = require("react")
|
||||
|
||||
module.exports = class MyComponent extends React.Component {
|
||||
render() {
|
||||
|
||||
122
cmd.ts
122
cmd.ts
@@ -1,55 +1,135 @@
|
||||
import SimpleScaffold from './scaffold'
|
||||
import * as fs from 'fs'
|
||||
import IScaffold from './index'
|
||||
import * as cliArgs from 'command-line-args'
|
||||
import * as cliUsage from 'command-line-usage'
|
||||
import * as path from 'path'
|
||||
import SimpleScaffold from "./scaffold"
|
||||
import * as fs from "fs"
|
||||
import { IScaffold } from "./index"
|
||||
import * as cliArgs from "command-line-args"
|
||||
import * as cliUsage from "command-line-usage"
|
||||
import * as path from "path"
|
||||
|
||||
type Def = cliArgs.OptionDefinition & { description?: string }
|
||||
type Def = cliArgs.OptionDefinition & {
|
||||
description?: string
|
||||
typeLabel?: string
|
||||
}
|
||||
|
||||
function localsParser(content: string) {
|
||||
const [key, value] = content.split('=')
|
||||
return { [key]: value }
|
||||
return JSON.parse(content)
|
||||
}
|
||||
|
||||
function filePathParser(content: string) {
|
||||
if (content.startsWith('/')) {
|
||||
if (content.startsWith("/")) {
|
||||
return content
|
||||
}
|
||||
return [process.cwd(), content].join(path.sep)
|
||||
}
|
||||
|
||||
function booleanParser(text: string) {
|
||||
return text && text.trim().length
|
||||
? ["true", "1", "on"].includes(text.trim())
|
||||
: true
|
||||
}
|
||||
|
||||
const defs: Def[] = [
|
||||
{ name: 'name', alias: 'n', type: String, description: 'Component output name', defaultOption: true },
|
||||
{ name: 'templates', alias: 't', type: filePathParser, multiple: true },
|
||||
{ name: 'output', alias: 'o', type: filePathParser, multiple: true },
|
||||
{ name: 'locals', alias: 'l', multiple: true, type: localsParser },
|
||||
{ name: 'create-sub-folder', alias: 'S', type: (text: string) => text && text.trim().length ? ['true', '1', 'on'].includes(text.trim()) : true },
|
||||
{ name: 'help', alias: 'h', type: Boolean, description: 'Display this help message' },
|
||||
{
|
||||
name: "name",
|
||||
alias: "n",
|
||||
type: String,
|
||||
description: "Component output name",
|
||||
defaultOption: true,
|
||||
},
|
||||
{
|
||||
name: "templates",
|
||||
alias: "t",
|
||||
type: filePathParser,
|
||||
typeLabel: "{underline File}[]",
|
||||
description: `A glob pattern of template files to load.\nA template file may be of any type and extension, and supports Handlebars as a parsing engine for the file names and contents, so you may customize both with variables from your configuration.`,
|
||||
multiple: true,
|
||||
},
|
||||
{
|
||||
name: "output",
|
||||
alias: "o",
|
||||
type: filePathParser,
|
||||
typeLabel: "{underline File}",
|
||||
description: `The output directory to put the new files in. They will attempt to maintain their regular structure as they are found, if possible.`,
|
||||
},
|
||||
{
|
||||
name: "locals",
|
||||
alias: "l",
|
||||
description: `A JSON string for the template to use in parsing.`,
|
||||
typeLabel: "{underline JSON string}",
|
||||
type: localsParser,
|
||||
},
|
||||
{
|
||||
name: "overwrite",
|
||||
alias: "w",
|
||||
description: `Whether to overwrite files when they are found to already exist. {bold Default=true}`,
|
||||
type: booleanParser,
|
||||
typeLabel: "{underline Boolean}",
|
||||
defaultValue: true,
|
||||
},
|
||||
{
|
||||
name: "quiet",
|
||||
alias: "q",
|
||||
description:
|
||||
"When set to {bold true}, logs will not output (including warnings and errors). {bold Default=false}",
|
||||
type: booleanParser,
|
||||
typeLabel: "{underline Boolean}",
|
||||
defaultValue: false,
|
||||
},
|
||||
{
|
||||
name: "create-sub-folder",
|
||||
alias: "S",
|
||||
typeLabel: "{underline Boolean}",
|
||||
description:
|
||||
"Whether to create a subdirectory with \\{\\{Name\\}\\} in the {underline output} directory. {bold Default=true}",
|
||||
type: booleanParser,
|
||||
defaultValue: true,
|
||||
},
|
||||
{
|
||||
name: "help",
|
||||
alias: "h",
|
||||
type: Boolean,
|
||||
description: "Display this help message",
|
||||
},
|
||||
]
|
||||
|
||||
const args = cliArgs(defs, { camelCase: true })
|
||||
const args = cliArgs(defs, { camelCase: true }) as Omit<
|
||||
IScaffold.Config,
|
||||
"createSubFolder"
|
||||
> & {
|
||||
help: boolean
|
||||
createSubFolder: boolean
|
||||
}
|
||||
|
||||
const help = [
|
||||
{ header: 'Scaffold Generator', content: 'Generate scaffolds for your project based on file templates.' },
|
||||
{ header: 'Options', optionList: defs }
|
||||
{
|
||||
header: "Scaffold Generator",
|
||||
content: `Generate scaffolds for your project based on file templates.\nUsage: {bold simple-scaffold} {underline scaffold-name} {underline [options]}`,
|
||||
},
|
||||
{ header: "Options", optionList: defs },
|
||||
]
|
||||
|
||||
args.locals = (args.locals || []).reduce((all: object, cur: object) => ({ ...all, ...cur }), {} as IScaffold.Config['locals'])
|
||||
if (args.createSubFolder === null) {
|
||||
args.createSubFolder = true
|
||||
}
|
||||
console.info('Config:', args)
|
||||
|
||||
if (args.quiet === null) {
|
||||
args.quiet = true
|
||||
}
|
||||
|
||||
if (args.help || !args.name) {
|
||||
console.log(cliUsage(help))
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
if (!args.quiet) {
|
||||
console.info("Config:", args)
|
||||
}
|
||||
|
||||
new SimpleScaffold({
|
||||
name: args.name,
|
||||
templates: args.templates,
|
||||
output: args.output,
|
||||
locals: args.locals,
|
||||
createSubfolder: args.createSubFolder,
|
||||
overwrite: args.overwrite,
|
||||
quiet: args.quiet,
|
||||
}).run()
|
||||
|
||||
0
dist/dist/cmd.d.ts → dist/cmd.d.ts
vendored
0
dist/dist/cmd.d.ts → dist/cmd.d.ts
vendored
291
dist/cmd.js
vendored
291
dist/cmd.js
vendored
File diff suppressed because one or more lines are too long
2
dist/cmd.js.map
vendored
2
dist/cmd.js.map
vendored
File diff suppressed because one or more lines are too long
13
dist/dist/scaffold.d.ts
vendored
13
dist/dist/scaffold.d.ts
vendored
@@ -1,13 +0,0 @@
|
||||
import IScaffold from './index';
|
||||
declare class SimpleScaffold {
|
||||
config: IScaffold.Config;
|
||||
locals: IScaffold.Config['locals'];
|
||||
constructor(config: IScaffold.Config);
|
||||
private parseLocals;
|
||||
private fileList;
|
||||
private getFileContents;
|
||||
private getOutputPath;
|
||||
private writeFile;
|
||||
run(): void;
|
||||
}
|
||||
export default SimpleScaffold;
|
||||
30
dist/index.d.ts
vendored
Executable file
30
dist/index.d.ts
vendored
Executable file
@@ -0,0 +1,30 @@
|
||||
declare namespace IScaffold {
|
||||
class SimpleScaffold {
|
||||
constructor(config: Config)
|
||||
run(): void
|
||||
}
|
||||
|
||||
export interface Config {
|
||||
name?: string
|
||||
templates: string[]
|
||||
output:
|
||||
| string
|
||||
| ((fullPath: string, basedir: string, basename: string) => string)
|
||||
locals?: Locals
|
||||
createSubfolder?: boolean
|
||||
overwrite?: boolean | ((path: string) => boolean)
|
||||
quiet?: boolean
|
||||
}
|
||||
|
||||
export interface Locals {
|
||||
[k: string]: string
|
||||
}
|
||||
|
||||
export interface FileRepr {
|
||||
base: string
|
||||
file: string
|
||||
}
|
||||
}
|
||||
|
||||
export default IScaffold.SimpleScaffold
|
||||
export { IScaffold }
|
||||
2
dist/index.js
vendored
Executable file
2
dist/index.js
vendored
Executable file
@@ -0,0 +1,2 @@
|
||||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.library=e():t.library=e()}(global,(function(){return(()=>{"use strict";var t={493:function(t,e,o){var r=this&&this.__assign||function(){return(r=Object.assign||function(t){for(var e,o=1,r=arguments.length;o<r;o++)for(var i in e=arguments[o])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},i=this&&this.__spreadArrays||function(){for(var t=0,e=0,o=arguments.length;e<o;e++)t+=arguments[e].length;var r=Array(t),i=0;for(e=0;e<o;e++)for(var n=arguments[e],s=0,a=n.length;s<a;s++,i++)r[i]=n[s];return r};Object.defineProperty(e,"__esModule",{value:!0});var n=o(747),s=o(622),a=o(878),l=o(778),f=function(){function t(t){this.locals={};var e={name:"scaffold",templates:[],output:process.cwd(),createSubfolder:!0,overwrite:!0,quiet:!1};this.config=r(r({},e),t);var o={Name:this.config.name[0].toUpperCase()+this.config.name.slice(1),name:this.config.name[0].toLowerCase()+this.config.name.slice(1)};this.locals=r(r({},o),t.locals)}return t.prototype.parseLocals=function(t){try{return l.compile(t,{noEscape:!0})(this.locals)}catch(e){return this.warn("Problem using Handlebars, returning unmodified content"),t}},t.prototype.fileList=function(t){for(var e=[],o=0,r=t;o<r.length;o++){var i=r[o],n=a.sync(i,{dot:!0}).map((function(t){return"/"==t[0]?t:s.join(process.cwd(),t)})),l=i.indexOf("*"),f=i;l>=0&&(f=i.slice(0,l-1));for(var c=0,p=n;c<p.length;c++){var u=p[c];e.push({base:f,file:u})}}return e},t.prototype.getFileContents=function(t){return this.log(n.readFileSync(t)),n.readFileSync(t).toString()},t.prototype.getOutputPath=function(t,e){var o;if("function"==typeof this.config.output)o=this.config.output(t,e,s.basename(t));else{var r=this.config.output+(this.config.createSubfolder?"/"+this.config.name+"/":"/"),i=t.indexOf(e),n=t;i>=0&&(n=t!==e?t.slice(i+e.length+1):s.basename(t)),o=r+n}return this.parseLocals(o)},t.prototype.writeFile=function(t,e){var o=s.dirname(t);this.writeDirectory(o,t),n.writeFile(t,e,{encoding:"utf-8"},(function(t){if(t)throw t}))},t.prototype.shouldWriteFile=function(t){var e,o,r="boolean"==typeof this.config.overwrite?this.config.overwrite:null===(o=(e=this.config).overwrite)||void 0===o?void 0:o.call(e,t);return!n.existsSync(t)||!1!==r},t.prototype.run=function(){this.log("Generating scaffold: "+this.config.name+"...");var t,e=this.fileList(this.config.templates),o=0;this.log("Template files:",e);for(var r=0,i=e;r<i.length;r++){t=i[r];var s=void 0,a=void 0,l=void 0,f=void 0,c=void 0;try{if(o++,f=t.file,c=t.base,s=this.getOutputPath(f,c),n.lstatSync(f).isDirectory()){this.writeDirectory(s,f);continue}a=this.getFileContents(f),l=this.parseLocals(a),this.shouldWriteFile(s)?(this.info("Writing:",{file:f,base:c,outputPath:s,outputContents:l.replace("\n","\\n")}),this.writeFile(s,l)):this.log("Skipping file "+s)}catch(t){throw this.error("Error while processing file:",{file:f,base:c,contents:a,outputPath:s,outputContents:l}),t}}if(!o)throw new Error("No files to scaffold!");this.log("Done")},t.prototype.writeDirectory=function(t,e){var o=s.dirname(t);n.existsSync(o)||this.writeDirectory(o,t),n.existsSync(t)||(this.info("Creating directory:",{file:e,outputPath:t}),n.mkdirSync(t))},t.prototype._log=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];if(!this.config.quiet){var r=console[t];r.apply(void 0,e)}},t.prototype.log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._log.apply(this,i(["log"],t))},t.prototype.info=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._log.apply(this,i(["info"],t))},t.prototype.warn=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._log.apply(this,i(["warn"],t))},t.prototype.error=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._log.apply(this,i(["error"],t))},t}();e.default=f},747:t=>{t.exports=require("fs")},878:t=>{t.exports=require("glob")},778:t=>{t.exports=require("handlebars")},622:t=>{t.exports=require("path")}},e={};return function o(r){if(e[r])return e[r].exports;var i=e[r]={exports:{}};return t[r].call(i.exports,i,i.exports,o),i.exports}(493)})()}));
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
dist/index.js.map
vendored
Executable file
1
dist/index.js.map
vendored
Executable file
File diff suppressed because one or more lines are too long
96
dist/main.js
vendored
96
dist/main.js
vendored
@@ -1,96 +0,0 @@
|
||||
(function webpackUniversalModuleDefinition(root, factory) {
|
||||
if(typeof exports === 'object' && typeof module === 'object')
|
||||
module.exports = factory();
|
||||
else if(typeof define === 'function' && define.amd)
|
||||
define([], factory);
|
||||
else if(typeof exports === 'object')
|
||||
exports["library"] = factory();
|
||||
else
|
||||
root["library"] = factory();
|
||||
})(this, function() {
|
||||
return /******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
/******/
|
||||
/******/ // Check if module is in cache
|
||||
/******/ if(installedModules[moduleId]) {
|
||||
/******/ return installedModules[moduleId].exports;
|
||||
/******/ }
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = installedModules[moduleId] = {
|
||||
/******/ i: moduleId,
|
||||
/******/ l: false,
|
||||
/******/ exports: {}
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||
/******/
|
||||
/******/ // Flag the module as loaded
|
||||
/******/ module.l = true;
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
/******/
|
||||
/******/
|
||||
/******/ // expose the modules object (__webpack_modules__)
|
||||
/******/ __webpack_require__.m = modules;
|
||||
/******/
|
||||
/******/ // expose the module cache
|
||||
/******/ __webpack_require__.c = installedModules;
|
||||
/******/
|
||||
/******/ // define getter function for harmony exports
|
||||
/******/ __webpack_require__.d = function(exports, name, getter) {
|
||||
/******/ if(!__webpack_require__.o(exports, name)) {
|
||||
/******/ Object.defineProperty(exports, name, {
|
||||
/******/ configurable: false,
|
||||
/******/ enumerable: true,
|
||||
/******/ get: getter
|
||||
/******/ });
|
||||
/******/ }
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||||
/******/ __webpack_require__.n = function(module) {
|
||||
/******/ var getter = module && module.__esModule ?
|
||||
/******/ function getDefault() { return module['default']; } :
|
||||
/******/ function getModuleExports() { return module; };
|
||||
/******/ __webpack_require__.d(getter, 'a', getter);
|
||||
/******/ return getter;
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Object.prototype.hasOwnProperty.call
|
||||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
||||
/******/
|
||||
/******/ // __webpack_public_path__
|
||||
/******/ __webpack_require__.p = "";
|
||||
/******/
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ return __webpack_require__(__webpack_require__.s = 7);
|
||||
/******/ })
|
||||
/************************************************************************/
|
||||
/******/ ({
|
||||
|
||||
/***/ 7:
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
(function webpackMissingModule() { throw new Error("Cannot find module \"add\""); }());
|
||||
module.exports = __webpack_require__(8);
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 8:
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
module.exports = require("jest");
|
||||
|
||||
/***/ })
|
||||
|
||||
/******/ });
|
||||
});
|
||||
//# sourceMappingURL=main.js.map
|
||||
1
dist/main.js.map
vendored
1
dist/main.js.map
vendored
@@ -1 +0,0 @@
|
||||
{"version":3,"sources":["webpack/universalModuleDefinition","webpack/bootstrap c994c2c400fa1fc61abe","external \"jest\""],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAK;AACL;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;AAEA;AACA;;;;;;;;;;;;;;;;;AC7DA,iC","file":"main.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"library\"] = factory();\n\telse\n\t\troot[\"library\"] = factory();\n})(this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 7);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap c994c2c400fa1fc61abe","module.exports = require(\"jest\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"jest\"\n// module id = 8\n// module chunks = 3"],"sourceRoot":""}
|
||||
21
dist/scaffold.d.ts
vendored
Executable file
21
dist/scaffold.d.ts
vendored
Executable file
@@ -0,0 +1,21 @@
|
||||
/// <reference types="node" />
|
||||
import { IScaffold } from "./index.d";
|
||||
declare class SimpleScaffold {
|
||||
config: IScaffold.Config;
|
||||
locals: IScaffold.Config["locals"];
|
||||
constructor(config: IScaffold.Config);
|
||||
private parseLocals;
|
||||
private fileList;
|
||||
private getFileContents;
|
||||
private getOutputPath;
|
||||
private writeFile;
|
||||
private shouldWriteFile;
|
||||
run(): void;
|
||||
private writeDirectory;
|
||||
_log(method: keyof typeof console, ...args: any[]): void;
|
||||
log(...args: any[]): void;
|
||||
info(...args: any[]): void;
|
||||
warn(...args: any[]): void;
|
||||
error(...args: any[]): void;
|
||||
}
|
||||
export default SimpleScaffold;
|
||||
217
dist/scaffold.js
vendored
217
dist/scaffold.js
vendored
@@ -1,217 +0,0 @@
|
||||
(function webpackUniversalModuleDefinition(root, factory) {
|
||||
if(typeof exports === 'object' && typeof module === 'object')
|
||||
module.exports = factory();
|
||||
else if(typeof define === 'function' && define.amd)
|
||||
define([], factory);
|
||||
else if(typeof exports === 'object')
|
||||
exports["library"] = factory();
|
||||
else
|
||||
root["library"] = factory();
|
||||
})(typeof self !== 'undefined' ? self : this, function() {
|
||||
return /******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
/******/
|
||||
/******/ // Check if module is in cache
|
||||
/******/ if(installedModules[moduleId]) {
|
||||
/******/ return installedModules[moduleId].exports;
|
||||
/******/ }
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = installedModules[moduleId] = {
|
||||
/******/ i: moduleId,
|
||||
/******/ l: false,
|
||||
/******/ exports: {}
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||
/******/
|
||||
/******/ // Flag the module as loaded
|
||||
/******/ module.l = true;
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
/******/
|
||||
/******/
|
||||
/******/ // expose the modules object (__webpack_modules__)
|
||||
/******/ __webpack_require__.m = modules;
|
||||
/******/
|
||||
/******/ // expose the module cache
|
||||
/******/ __webpack_require__.c = installedModules;
|
||||
/******/
|
||||
/******/ // define getter function for harmony exports
|
||||
/******/ __webpack_require__.d = function(exports, name, getter) {
|
||||
/******/ if(!__webpack_require__.o(exports, name)) {
|
||||
/******/ Object.defineProperty(exports, name, {
|
||||
/******/ configurable: false,
|
||||
/******/ enumerable: true,
|
||||
/******/ get: getter
|
||||
/******/ });
|
||||
/******/ }
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||||
/******/ __webpack_require__.n = function(module) {
|
||||
/******/ var getter = module && module.__esModule ?
|
||||
/******/ function getDefault() { return module['default']; } :
|
||||
/******/ function getModuleExports() { return module; };
|
||||
/******/ __webpack_require__.d(getter, 'a', getter);
|
||||
/******/ return getter;
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Object.prototype.hasOwnProperty.call
|
||||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
||||
/******/
|
||||
/******/ // __webpack_public_path__
|
||||
/******/ __webpack_require__.p = "";
|
||||
/******/
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ return __webpack_require__(__webpack_require__.s = 1);
|
||||
/******/ })
|
||||
/************************************************************************/
|
||||
/******/ ([
|
||||
/* 0 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
/* 1 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __assign = (this && this.__assign) || Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var fs = __webpack_require__(2);
|
||||
var path = __webpack_require__(0);
|
||||
var glob = __webpack_require__(3);
|
||||
var handlebars = __webpack_require__(4);
|
||||
var SimpleScaffold = /** @class */ (function () {
|
||||
function SimpleScaffold(config) {
|
||||
this.locals = {};
|
||||
var DefaultConfig = {
|
||||
name: 'scaffold',
|
||||
templates: [],
|
||||
output: process.cwd(),
|
||||
createSubfolder: true,
|
||||
};
|
||||
this.config = __assign({}, DefaultConfig, config);
|
||||
var DefaultLocals = {
|
||||
Name: this.config.name[0].toUpperCase() + this.config.name.slice(1),
|
||||
name: this.config.name[0].toLowerCase() + this.config.name.slice(1)
|
||||
};
|
||||
this.locals = __assign({}, DefaultLocals, config.locals);
|
||||
}
|
||||
SimpleScaffold.prototype.parseLocals = function (text) {
|
||||
var template = handlebars.compile(text, {
|
||||
noEscape: true
|
||||
});
|
||||
return template(this.locals);
|
||||
};
|
||||
SimpleScaffold.prototype.fileList = function (input) {
|
||||
var output = [];
|
||||
for (var _i = 0, input_1 = input; _i < input_1.length; _i++) {
|
||||
var checkPath = input_1[_i];
|
||||
var files = glob.sync(checkPath, { dot: true })
|
||||
.map(function (g) { return g[0] == '/' ? g : path.join(process.cwd(), g); });
|
||||
var idx = checkPath.indexOf('*');
|
||||
var cleanCheckPath = checkPath;
|
||||
if (idx >= 0) {
|
||||
cleanCheckPath = checkPath.slice(0, idx - 1);
|
||||
}
|
||||
for (var _a = 0, files_1 = files; _a < files_1.length; _a++) {
|
||||
var file = files_1[_a];
|
||||
output.push({ base: cleanCheckPath, file: file });
|
||||
}
|
||||
}
|
||||
return output;
|
||||
};
|
||||
SimpleScaffold.prototype.getFileContents = function (filePath) {
|
||||
console.log(fs.readFileSync(filePath));
|
||||
return fs.readFileSync(filePath).toString();
|
||||
};
|
||||
SimpleScaffold.prototype.getOutputPath = function (file, basePath) {
|
||||
var out;
|
||||
if (typeof this.config.output === 'function') {
|
||||
out = this.config.output(file, basePath);
|
||||
}
|
||||
else {
|
||||
var outputDir = this.config.output + (this.config.createSubfolder ? "/" + this.config.name + "/" : '/');
|
||||
var idx = file.indexOf(basePath);
|
||||
var relativeFilePath = file;
|
||||
if (idx >= 0) {
|
||||
relativeFilePath = file.slice(idx + basePath.length + 1);
|
||||
}
|
||||
out = outputDir + relativeFilePath;
|
||||
}
|
||||
return this.parseLocals(out);
|
||||
};
|
||||
SimpleScaffold.prototype.writeFile = function (filePath, fileContents) {
|
||||
if (!fs.existsSync(path.dirname(filePath))) {
|
||||
fs.mkdirSync(path.dirname(filePath));
|
||||
}
|
||||
console.info('Writing file:', filePath);
|
||||
fs.writeFile(filePath, fileContents, { encoding: 'utf-8' }, function (err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
};
|
||||
SimpleScaffold.prototype.run = function () {
|
||||
console.log("Generating scaffold: " + this.config.name + "...");
|
||||
var templates = this.fileList(this.config.templates);
|
||||
var fileConf, count = 0;
|
||||
for (var _i = 0, templates_1 = templates; _i < templates_1.length; _i++) {
|
||||
fileConf = templates_1[_i];
|
||||
count++;
|
||||
var file = fileConf.file, base = fileConf.base;
|
||||
var outputPath = this.getOutputPath(file, base);
|
||||
var contents = this.getFileContents(file);
|
||||
var outputContents = this.parseLocals(contents);
|
||||
this.writeFile(outputPath, outputContents);
|
||||
console.info('Parsing:', { file: file, base: base, outputPath: outputPath, outputContents: outputContents.replace("\n", "\\n") });
|
||||
}
|
||||
if (!count) {
|
||||
throw new Error('No files to scaffold!');
|
||||
}
|
||||
console.log('Done');
|
||||
};
|
||||
return SimpleScaffold;
|
||||
}());
|
||||
exports.default = SimpleScaffold;
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 2 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
/* 3 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
module.exports = require("glob");
|
||||
|
||||
/***/ }),
|
||||
/* 4 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
module.exports = require("handlebars");
|
||||
|
||||
/***/ })
|
||||
/******/ ]);
|
||||
});
|
||||
//# sourceMappingURL=scaffold.js.map
|
||||
1
dist/scaffold.js.map
vendored
1
dist/scaffold.js.map
vendored
File diff suppressed because one or more lines are too long
0
dist/dist/test.d.ts → dist/test.d.ts
vendored
0
dist/dist/test.d.ts → dist/test.d.ts
vendored
246
dist/test.js
vendored
246
dist/test.js
vendored
@@ -1,246 +1,2 @@
|
||||
(function webpackUniversalModuleDefinition(root, factory) {
|
||||
if(typeof exports === 'object' && typeof module === 'object')
|
||||
module.exports = factory();
|
||||
else if(typeof define === 'function' && define.amd)
|
||||
define([], factory);
|
||||
else if(typeof exports === 'object')
|
||||
exports["library"] = factory();
|
||||
else
|
||||
root["library"] = factory();
|
||||
})(typeof self !== 'undefined' ? self : this, function() {
|
||||
return /******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
/******/
|
||||
/******/ // Check if module is in cache
|
||||
/******/ if(installedModules[moduleId]) {
|
||||
/******/ return installedModules[moduleId].exports;
|
||||
/******/ }
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = installedModules[moduleId] = {
|
||||
/******/ i: moduleId,
|
||||
/******/ l: false,
|
||||
/******/ exports: {}
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||
/******/
|
||||
/******/ // Flag the module as loaded
|
||||
/******/ module.l = true;
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
/******/
|
||||
/******/
|
||||
/******/ // expose the modules object (__webpack_modules__)
|
||||
/******/ __webpack_require__.m = modules;
|
||||
/******/
|
||||
/******/ // expose the module cache
|
||||
/******/ __webpack_require__.c = installedModules;
|
||||
/******/
|
||||
/******/ // define getter function for harmony exports
|
||||
/******/ __webpack_require__.d = function(exports, name, getter) {
|
||||
/******/ if(!__webpack_require__.o(exports, name)) {
|
||||
/******/ Object.defineProperty(exports, name, {
|
||||
/******/ configurable: false,
|
||||
/******/ enumerable: true,
|
||||
/******/ get: getter
|
||||
/******/ });
|
||||
/******/ }
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||||
/******/ __webpack_require__.n = function(module) {
|
||||
/******/ var getter = module && module.__esModule ?
|
||||
/******/ function getDefault() { return module['default']; } :
|
||||
/******/ function getModuleExports() { return module; };
|
||||
/******/ __webpack_require__.d(getter, 'a', getter);
|
||||
/******/ return getter;
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Object.prototype.hasOwnProperty.call
|
||||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
||||
/******/
|
||||
/******/ // __webpack_public_path__
|
||||
/******/ __webpack_require__.p = "";
|
||||
/******/
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ return __webpack_require__(__webpack_require__.s = 5);
|
||||
/******/ })
|
||||
/************************************************************************/
|
||||
/******/ ([
|
||||
/* 0 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
/* 1 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __assign = (this && this.__assign) || Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var fs = __webpack_require__(2);
|
||||
var path = __webpack_require__(0);
|
||||
var glob = __webpack_require__(3);
|
||||
var handlebars = __webpack_require__(4);
|
||||
var SimpleScaffold = /** @class */ (function () {
|
||||
function SimpleScaffold(config) {
|
||||
this.locals = {};
|
||||
var DefaultConfig = {
|
||||
name: 'scaffold',
|
||||
templates: [],
|
||||
output: process.cwd(),
|
||||
createSubfolder: true,
|
||||
};
|
||||
this.config = __assign({}, DefaultConfig, config);
|
||||
var DefaultLocals = {
|
||||
Name: this.config.name[0].toUpperCase() + this.config.name.slice(1),
|
||||
name: this.config.name[0].toLowerCase() + this.config.name.slice(1)
|
||||
};
|
||||
this.locals = __assign({}, DefaultLocals, config.locals);
|
||||
}
|
||||
SimpleScaffold.prototype.parseLocals = function (text) {
|
||||
var template = handlebars.compile(text, {
|
||||
noEscape: true
|
||||
});
|
||||
return template(this.locals);
|
||||
};
|
||||
SimpleScaffold.prototype.fileList = function (input) {
|
||||
var output = [];
|
||||
for (var _i = 0, input_1 = input; _i < input_1.length; _i++) {
|
||||
var checkPath = input_1[_i];
|
||||
var files = glob.sync(checkPath, { dot: true })
|
||||
.map(function (g) { return g[0] == '/' ? g : path.join(process.cwd(), g); });
|
||||
var idx = checkPath.indexOf('*');
|
||||
var cleanCheckPath = checkPath;
|
||||
if (idx >= 0) {
|
||||
cleanCheckPath = checkPath.slice(0, idx - 1);
|
||||
}
|
||||
for (var _a = 0, files_1 = files; _a < files_1.length; _a++) {
|
||||
var file = files_1[_a];
|
||||
output.push({ base: cleanCheckPath, file: file });
|
||||
}
|
||||
}
|
||||
return output;
|
||||
};
|
||||
SimpleScaffold.prototype.getFileContents = function (filePath) {
|
||||
console.log(fs.readFileSync(filePath));
|
||||
return fs.readFileSync(filePath).toString();
|
||||
};
|
||||
SimpleScaffold.prototype.getOutputPath = function (file, basePath) {
|
||||
var out;
|
||||
if (typeof this.config.output === 'function') {
|
||||
out = this.config.output(file, basePath);
|
||||
}
|
||||
else {
|
||||
var outputDir = this.config.output + (this.config.createSubfolder ? "/" + this.config.name + "/" : '/');
|
||||
var idx = file.indexOf(basePath);
|
||||
var relativeFilePath = file;
|
||||
if (idx >= 0) {
|
||||
relativeFilePath = file.slice(idx + basePath.length + 1);
|
||||
}
|
||||
out = outputDir + relativeFilePath;
|
||||
}
|
||||
return this.parseLocals(out);
|
||||
};
|
||||
SimpleScaffold.prototype.writeFile = function (filePath, fileContents) {
|
||||
if (!fs.existsSync(path.dirname(filePath))) {
|
||||
fs.mkdirSync(path.dirname(filePath));
|
||||
}
|
||||
console.info('Writing file:', filePath);
|
||||
fs.writeFile(filePath, fileContents, { encoding: 'utf-8' }, function (err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
};
|
||||
SimpleScaffold.prototype.run = function () {
|
||||
console.log("Generating scaffold: " + this.config.name + "...");
|
||||
var templates = this.fileList(this.config.templates);
|
||||
var fileConf, count = 0;
|
||||
for (var _i = 0, templates_1 = templates; _i < templates_1.length; _i++) {
|
||||
fileConf = templates_1[_i];
|
||||
count++;
|
||||
var file = fileConf.file, base = fileConf.base;
|
||||
var outputPath = this.getOutputPath(file, base);
|
||||
var contents = this.getFileContents(file);
|
||||
var outputContents = this.parseLocals(contents);
|
||||
this.writeFile(outputPath, outputContents);
|
||||
console.info('Parsing:', { file: file, base: base, outputPath: outputPath, outputContents: outputContents.replace("\n", "\\n") });
|
||||
}
|
||||
if (!count) {
|
||||
throw new Error('No files to scaffold!');
|
||||
}
|
||||
console.log('Done');
|
||||
};
|
||||
return SimpleScaffold;
|
||||
}());
|
||||
exports.default = SimpleScaffold;
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 2 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
/* 3 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
module.exports = require("glob");
|
||||
|
||||
/***/ }),
|
||||
/* 4 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
module.exports = require("handlebars");
|
||||
|
||||
/***/ }),
|
||||
/* 5 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var scaffold_1 = __webpack_require__(1);
|
||||
var path = __webpack_require__(0);
|
||||
var templateDir = path.join(process.cwd(), 'examples');
|
||||
new scaffold_1.default({
|
||||
templates: [templateDir + '/test-input/Component/**/*'],
|
||||
output: templateDir + '/test-output/no-create-subpath',
|
||||
createSubfolder: false,
|
||||
locals: {
|
||||
property: 'myProp',
|
||||
value: '"value"'
|
||||
}
|
||||
}).run();
|
||||
new scaffold_1.default({
|
||||
templates: [templateDir + '/test-input/Component/**/*'],
|
||||
output: templateDir + '/test-output',
|
||||
locals: {
|
||||
property: 'myProp',
|
||||
value: '"value"'
|
||||
}
|
||||
}).run();
|
||||
|
||||
|
||||
/***/ })
|
||||
/******/ ]);
|
||||
});
|
||||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.library=e():t.library=e()}(global,(function(){return(()=>{"use strict";var t={493:function(t,e,o){var r=this&&this.__assign||function(){return(r=Object.assign||function(t){for(var e,o=1,r=arguments.length;o<r;o++)for(var i in e=arguments[o])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},i=this&&this.__spreadArrays||function(){for(var t=0,e=0,o=arguments.length;e<o;e++)t+=arguments[e].length;var r=Array(t),i=0;for(e=0;e<o;e++)for(var n=arguments[e],s=0,a=n.length;s<a;s++,i++)r[i]=n[s];return r};Object.defineProperty(e,"__esModule",{value:!0});var n=o(747),s=o(622),a=o(878),l=o(778),p=function(){function t(t){this.locals={};var e={name:"scaffold",templates:[],output:process.cwd(),createSubfolder:!0,overwrite:!0,quiet:!1};this.config=r(r({},e),t);var o={Name:this.config.name[0].toUpperCase()+this.config.name.slice(1),name:this.config.name[0].toLowerCase()+this.config.name.slice(1)};this.locals=r(r({},o),t.locals)}return t.prototype.parseLocals=function(t){try{return l.compile(t,{noEscape:!0})(this.locals)}catch(e){return this.warn("Problem using Handlebars, returning unmodified content"),t}},t.prototype.fileList=function(t){for(var e=[],o=0,r=t;o<r.length;o++){var i=r[o],n=a.sync(i,{dot:!0}).map((function(t){return"/"==t[0]?t:s.join(process.cwd(),t)})),l=i.indexOf("*"),p=i;l>=0&&(p=i.slice(0,l-1));for(var u=0,c=n;u<c.length;u++){var f=c[u];e.push({base:p,file:f})}}return e},t.prototype.getFileContents=function(t){return this.log(n.readFileSync(t)),n.readFileSync(t).toString()},t.prototype.getOutputPath=function(t,e){var o;if("function"==typeof this.config.output)o=this.config.output(t,e,s.basename(t));else{var r=this.config.output+(this.config.createSubfolder?"/"+this.config.name+"/":"/"),i=t.indexOf(e),n=t;i>=0&&(n=t!==e?t.slice(i+e.length+1):s.basename(t)),o=r+n}return this.parseLocals(o)},t.prototype.writeFile=function(t,e){var o=s.dirname(t);this.writeDirectory(o,t),n.writeFile(t,e,{encoding:"utf-8"},(function(t){if(t)throw t}))},t.prototype.shouldWriteFile=function(t){var e,o,r="boolean"==typeof this.config.overwrite?this.config.overwrite:null===(o=(e=this.config).overwrite)||void 0===o?void 0:o.call(e,t);return!n.existsSync(t)||!1!==r},t.prototype.run=function(){this.log("Generating scaffold: "+this.config.name+"...");var t,e=this.fileList(this.config.templates),o=0;this.log("Template files:",e);for(var r=0,i=e;r<i.length;r++){t=i[r];var s=void 0,a=void 0,l=void 0,p=void 0,u=void 0;try{if(o++,p=t.file,u=t.base,s=this.getOutputPath(p,u),n.lstatSync(p).isDirectory()){this.writeDirectory(s,p);continue}a=this.getFileContents(p),l=this.parseLocals(a),this.shouldWriteFile(s)?(this.info("Writing:",{file:p,base:u,outputPath:s,outputContents:l.replace("\n","\\n")}),this.writeFile(s,l)):this.log("Skipping file "+s)}catch(t){throw this.error("Error while processing file:",{file:p,base:u,contents:a,outputPath:s,outputContents:l}),t}}if(!o)throw new Error("No files to scaffold!");this.log("Done")},t.prototype.writeDirectory=function(t,e){var o=s.dirname(t);n.existsSync(o)||this.writeDirectory(o,t),n.existsSync(t)||(this.info("Creating directory:",{file:e,outputPath:t}),n.mkdirSync(t))},t.prototype._log=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];if(!this.config.quiet){var r=console[t];r.apply(void 0,e)}},t.prototype.log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._log.apply(this,i(["log"],t))},t.prototype.info=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._log.apply(this,i(["info"],t))},t.prototype.warn=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._log.apply(this,i(["warn"],t))},t.prototype.error=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._log.apply(this,i(["error"],t))},t}();e.default=p},743:(t,e,o)=>{Object.defineProperty(e,"__esModule",{value:!0});var r=o(493),i=o(622).join(process.cwd(),"examples");new r.default({templates:[i+"/test-input/Component/**/*"],output:i+"/test-output/no-create-subpath",createSubfolder:!1,locals:{property:"myProp",value:'"value"'}}).run(),new r.default({templates:[i+"/test-input/Component/**/*"],output:i+"/test-output",locals:{property:"myProp",value:'"value"'}}).run(),new r.default({templates:[i+"/test-input/Component/**/*"],output:function(t,e,o){return console.log({file:t,basedir:e,basename:o}),t},locals:{property:"myProp",value:'"value"'}}).run()},747:t=>{t.exports=require("fs")},878:t=>{t.exports=require("glob")},778:t=>{t.exports=require("handlebars")},622:t=>{t.exports=require("path")}},e={};return function o(r){if(e[r])return e[r].exports;var i=e[r]={exports:{}};return t[r].call(i.exports,i,i.exports,o),i.exports}(743)})()}));
|
||||
//# sourceMappingURL=test.js.map
|
||||
2
dist/test.js.map
vendored
2
dist/test.js.map
vendored
File diff suppressed because one or more lines are too long
19
examples/test-input/Component/Scaffold.tsx
Normal file
19
examples/test-input/Component/Scaffold.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as React from 'react'
|
||||
import * as css from './Scaffold.css'
|
||||
|
||||
class Scaffold extends React.Component<any> {
|
||||
private myProp
|
||||
|
||||
constructor(props: any) {
|
||||
super(props)
|
||||
this.myProp = "value"
|
||||
}
|
||||
|
||||
public render() {
|
||||
return (
|
||||
<div className={ css.Scaffold } />
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default Scaffold
|
||||
13
index.d.ts
vendored
13
index.d.ts
vendored
@@ -1,11 +1,19 @@
|
||||
declare namespace IScaffold {
|
||||
class SimpleScaffold {
|
||||
constructor(config: Config)
|
||||
run(): void
|
||||
}
|
||||
|
||||
export interface Config {
|
||||
name?: string
|
||||
templates: string[]
|
||||
output: string | ((path: string, base: string) => string)
|
||||
output:
|
||||
| string
|
||||
| ((fullPath: string, basedir: string, basename: string) => string)
|
||||
locals?: Locals
|
||||
createSubfolder?: boolean
|
||||
overwrite?: boolean | ((path: string) => boolean)
|
||||
quiet?: boolean
|
||||
}
|
||||
|
||||
export interface Locals {
|
||||
@@ -18,4 +26,5 @@ declare namespace IScaffold {
|
||||
}
|
||||
}
|
||||
|
||||
export default IScaffold
|
||||
export default IScaffold.SimpleScaffold
|
||||
export { IScaffold }
|
||||
|
||||
2
index.js
Normal file
2
index.js
Normal file
@@ -0,0 +1,2 @@
|
||||
const SimpleScaffold = require('./dist')
|
||||
module.exports = SimpleScaffold
|
||||
33
package.json
33
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "simple-scaffold",
|
||||
"version": "0.4.4",
|
||||
"version": "0.7.2",
|
||||
"description": "Create files based on templates",
|
||||
"repository": "https://github.com/chenasraf/simple-scaffold.git",
|
||||
"author": "Chen Asraf <inbox@casraf.com>",
|
||||
@@ -9,33 +9,34 @@
|
||||
"bin": "dist/cmd.js",
|
||||
"types": "index.d.ts",
|
||||
"scripts": {
|
||||
"build": "NODE_ENV=${NODE_ENV:-production} webpack -p && chmod -R +x ./dist",
|
||||
"build": "NODE_ENV=${NODE_ENV:-production} webpack && chmod -R +x ./dist",
|
||||
"prepublishOnly": "yarn build",
|
||||
"dev": "webpack --watch",
|
||||
"start": "node dist/scaffold.js",
|
||||
"test": "jest",
|
||||
"test": "node dist/test.js",
|
||||
"cmd": "dist/cmd.js",
|
||||
"build-test": "yarn build && yarn test",
|
||||
"build-cmd": "yarn build && yarn cmd"
|
||||
},
|
||||
"dependencies": {
|
||||
"command-line-args": "^5.0.2",
|
||||
"command-line-usage": "^5.0.5",
|
||||
"glob": "^7.1.2",
|
||||
"handlebars": "^4.0.11",
|
||||
"ts-loader": "^3.1.1",
|
||||
"typescript": "^2.6.1",
|
||||
"webpack": "^3.8.1",
|
||||
"webpack-dev-server": "^2.9.4",
|
||||
"webpack-node-externals": "^1.6.0"
|
||||
"command-line-usage": "^6.1.1",
|
||||
"glob": "^7.1.3",
|
||||
"handlebars": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/command-line-args": "^5.0.0",
|
||||
"@types/command-line-usage": "^5.0.1",
|
||||
"@types/glob": "^5.0.34",
|
||||
"@types/handlebars": "^4.0.36",
|
||||
"@types/node": "^8.0.50",
|
||||
"jest": "^22.0.4"
|
||||
"@types/glob": "^7.1.1",
|
||||
"@types/node": "^14.14.22",
|
||||
"copy-webpack-plugin": "^7.0.0",
|
||||
"jest": "^26.6.3",
|
||||
"ts-loader": "^8.0.14",
|
||||
"typescript": "^4.1.3",
|
||||
"webpack": "^5.19.0",
|
||||
"webpack-cli": "^4.4.0",
|
||||
"webpack-dev-server": "^3.2.1",
|
||||
"webpack-node-externals": "^2.5.2"
|
||||
},
|
||||
"jest": {
|
||||
"testPathIgnorePatterns": [
|
||||
@@ -43,4 +44,4 @@
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
160
scaffold.ts
160
scaffold.ts
@@ -1,44 +1,53 @@
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import IScaffold from './index'
|
||||
import * as glob from 'glob'
|
||||
import * as handlebars from 'handlebars'
|
||||
import * as fs from "fs"
|
||||
import * as path from "path"
|
||||
import { IScaffold } from "./index.d"
|
||||
import * as glob from "glob"
|
||||
import * as handlebars from "handlebars"
|
||||
|
||||
class SimpleScaffold {
|
||||
public config: IScaffold.Config
|
||||
public locals: IScaffold.Config['locals'] = {} as any
|
||||
public locals: IScaffold.Config["locals"] = {} as any
|
||||
|
||||
constructor(config: IScaffold.Config) {
|
||||
const DefaultConfig: IScaffold.Config = {
|
||||
name: 'scaffold',
|
||||
name: "scaffold",
|
||||
templates: [],
|
||||
output: process.cwd(),
|
||||
createSubfolder: true,
|
||||
overwrite: true,
|
||||
quiet: false,
|
||||
}
|
||||
|
||||
this.config = { ...DefaultConfig, ...config }
|
||||
|
||||
const DefaultLocals = {
|
||||
// TODO improve
|
||||
Name: this.config.name![0].toUpperCase() + this.config.name!.slice(1),
|
||||
name: this.config.name![0].toLowerCase() + this.config.name!.slice(1)
|
||||
name: this.config.name![0].toLowerCase() + this.config.name!.slice(1),
|
||||
}
|
||||
|
||||
this.locals = { ...DefaultLocals, ...config.locals }
|
||||
}
|
||||
|
||||
private parseLocals(text: string): string {
|
||||
const template = handlebars.compile(text, {
|
||||
noEscape: true
|
||||
})
|
||||
return template(this.locals)
|
||||
try {
|
||||
const template = handlebars.compile(text, {
|
||||
noEscape: true,
|
||||
})
|
||||
return template(this.locals)
|
||||
} catch (e) {
|
||||
this.warn("Problem using Handlebars, returning unmodified content")
|
||||
return text
|
||||
}
|
||||
}
|
||||
|
||||
private fileList(input: string[]): IScaffold.FileRepr[] {
|
||||
const output: IScaffold.FileRepr[] = []
|
||||
for (const checkPath of input) {
|
||||
const files = glob.sync(checkPath, { dot: true })
|
||||
.map(g => g[0] == '/' ? g : path.join(process.cwd(), g))
|
||||
const idx = checkPath.indexOf('*')
|
||||
const files = glob
|
||||
.sync(checkPath, { dot: true })
|
||||
.map((g) => (g[0] == "/" ? g : path.join(process.cwd(), g)))
|
||||
const idx = checkPath.indexOf("*")
|
||||
let cleanCheckPath = checkPath
|
||||
if (idx >= 0) {
|
||||
cleanCheckPath = checkPath.slice(0, idx - 1)
|
||||
@@ -51,21 +60,27 @@ class SimpleScaffold {
|
||||
}
|
||||
|
||||
private getFileContents(filePath: string): string {
|
||||
console.log(fs.readFileSync(filePath))
|
||||
this.log(fs.readFileSync(filePath))
|
||||
return fs.readFileSync(filePath).toString()
|
||||
}
|
||||
|
||||
private getOutputPath(file: string, basePath: string): string {
|
||||
let out: string
|
||||
|
||||
if (typeof this.config.output === 'function') {
|
||||
out = this.config.output(file, basePath)
|
||||
if (typeof this.config.output === "function") {
|
||||
out = this.config.output(file, basePath, path.basename(file))
|
||||
} else {
|
||||
const outputDir = this.config.output + (this.config.createSubfolder ? `/${this.config.name}/` : '/')
|
||||
const outputDir =
|
||||
this.config.output +
|
||||
(this.config.createSubfolder ? `/${this.config.name}/` : "/")
|
||||
const idx = file.indexOf(basePath)
|
||||
let relativeFilePath = file
|
||||
if (idx >= 0) {
|
||||
relativeFilePath = file.slice(idx + basePath.length + 1)
|
||||
if (file !== basePath) {
|
||||
relativeFilePath = file.slice(idx + basePath.length + 1)
|
||||
} else {
|
||||
relativeFilePath = path.basename(file)
|
||||
}
|
||||
}
|
||||
out = outputDir + relativeFilePath
|
||||
}
|
||||
@@ -74,38 +89,109 @@ class SimpleScaffold {
|
||||
}
|
||||
|
||||
private writeFile(filePath: string, fileContents: string): void {
|
||||
if (!fs.existsSync(path.dirname(filePath))) {
|
||||
fs.mkdirSync(path.dirname(filePath))
|
||||
}
|
||||
console.info('Writing file:', filePath)
|
||||
fs.writeFile(filePath, fileContents, { encoding: 'utf-8' }, (err) => {
|
||||
const baseDir = path.dirname(filePath)
|
||||
this.writeDirectory(baseDir, filePath)
|
||||
fs.writeFile(filePath, fileContents, { encoding: "utf-8" }, (err) => {
|
||||
if (err) {
|
||||
throw err
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private shouldWriteFile(filePath: string) {
|
||||
const overwrite =
|
||||
typeof this.config.overwrite === "boolean"
|
||||
? this.config.overwrite
|
||||
: this.config.overwrite?.(filePath)
|
||||
const exists = fs.existsSync(filePath)
|
||||
|
||||
return !exists || overwrite !== false
|
||||
}
|
||||
|
||||
public run(): void {
|
||||
console.log(`Generating scaffold: ${this.config.name}...`)
|
||||
this.log(`Generating scaffold: ${this.config.name}...`)
|
||||
const templates = this.fileList(this.config.templates)
|
||||
|
||||
let fileConf, count = 0
|
||||
for (fileConf of templates) {
|
||||
count++
|
||||
const { file, base } = fileConf
|
||||
const outputPath = this.getOutputPath(file, base)
|
||||
const contents = this.getFileContents(file)
|
||||
const outputContents = this.parseLocals(contents)
|
||||
let fileConf,
|
||||
count = 0
|
||||
|
||||
this.writeFile(outputPath, outputContents)
|
||||
console.info('Parsing:', { file, base, outputPath, outputContents: outputContents.replace("\n", "\\n") })
|
||||
this.log("Template files:", templates)
|
||||
for (fileConf of templates) {
|
||||
let outputPath, contents, outputContents, file, base
|
||||
try {
|
||||
count++
|
||||
file = fileConf.file
|
||||
base = fileConf.base
|
||||
outputPath = this.getOutputPath(file, base)
|
||||
if (fs.lstatSync(file).isDirectory()) {
|
||||
this.writeDirectory(outputPath, file)
|
||||
continue
|
||||
}
|
||||
contents = this.getFileContents(file)
|
||||
outputContents = this.parseLocals(contents)
|
||||
if (this.shouldWriteFile(outputPath)) {
|
||||
this.info("Writing:", {
|
||||
file,
|
||||
base,
|
||||
outputPath,
|
||||
outputContents: outputContents.replace("\n", "\\n"),
|
||||
})
|
||||
this.writeFile(outputPath, outputContents)
|
||||
} else {
|
||||
this.log(`Skipping file ${outputPath}`)
|
||||
}
|
||||
} catch (e) {
|
||||
this.error("Error while processing file:", {
|
||||
file,
|
||||
base,
|
||||
contents,
|
||||
outputPath,
|
||||
outputContents,
|
||||
})
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
if (!count) {
|
||||
throw new Error('No files to scaffold!')
|
||||
throw new Error("No files to scaffold!")
|
||||
}
|
||||
|
||||
console.log('Done')
|
||||
this.log("Done")
|
||||
}
|
||||
|
||||
private writeDirectory(outputPath: string, file: any): void {
|
||||
const parent = path.dirname(outputPath)
|
||||
if (!fs.existsSync(parent)) {
|
||||
this.writeDirectory(parent, outputPath)
|
||||
}
|
||||
if (!fs.existsSync(outputPath)) {
|
||||
this.info("Creating directory:", {
|
||||
file,
|
||||
outputPath,
|
||||
})
|
||||
fs.mkdirSync(outputPath)
|
||||
}
|
||||
}
|
||||
|
||||
_log(method: keyof typeof console, ...args: any[]): void {
|
||||
if (this.config.quiet) {
|
||||
return
|
||||
}
|
||||
const fn = console[method] as (...a: any[]) => void
|
||||
fn(...args)
|
||||
}
|
||||
|
||||
log(...args: any[]): void {
|
||||
this._log("log", ...args)
|
||||
}
|
||||
info(...args: any[]): void {
|
||||
this._log("info", ...args)
|
||||
}
|
||||
warn(...args: any[]): void {
|
||||
this._log("warn", ...args)
|
||||
}
|
||||
error(...args: any[]): void {
|
||||
this._log("error", ...args)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
38
test.ts
38
test.ts
@@ -1,23 +1,35 @@
|
||||
import SimpleScaffold from './scaffold'
|
||||
import * as path from 'path'
|
||||
import SimpleScaffold from "./scaffold"
|
||||
import * as path from "path"
|
||||
|
||||
const templateDir = path.join(process.cwd(), 'examples')
|
||||
const templateDir = path.join(process.cwd(), "examples")
|
||||
|
||||
new SimpleScaffold({
|
||||
templates: [templateDir + '/test-input/Component/**/*'],
|
||||
output: templateDir + '/test-output/no-create-subpath',
|
||||
templates: [templateDir + "/test-input/Component/**/*"],
|
||||
output: templateDir + "/test-output/no-create-subpath",
|
||||
createSubfolder: false,
|
||||
locals: {
|
||||
property: 'myProp',
|
||||
value: '"value"'
|
||||
}
|
||||
property: "myProp",
|
||||
value: '"value"',
|
||||
},
|
||||
}).run()
|
||||
|
||||
new SimpleScaffold({
|
||||
templates: [templateDir + '/test-input/Component/**/*'],
|
||||
output: templateDir + '/test-output',
|
||||
templates: [templateDir + "/test-input/Component/**/*"],
|
||||
output: templateDir + "/test-output",
|
||||
locals: {
|
||||
property: 'myProp',
|
||||
value: '"value"'
|
||||
}
|
||||
property: "myProp",
|
||||
value: '"value"',
|
||||
},
|
||||
}).run()
|
||||
|
||||
new SimpleScaffold({
|
||||
templates: [templateDir + "/test-input/Component/**/*"],
|
||||
output: (file, basedir, basename) => {
|
||||
console.log({ file, basedir, basename })
|
||||
return file
|
||||
},
|
||||
locals: {
|
||||
property: "myProp",
|
||||
value: '"value"',
|
||||
},
|
||||
}).run()
|
||||
|
||||
@@ -1,43 +1,46 @@
|
||||
const path = require('path')
|
||||
const webpack = require('webpack')
|
||||
const nodeExternals = require('webpack-node-externals')
|
||||
const path = require("path")
|
||||
const webpack = require("webpack")
|
||||
const nodeExternals = require("webpack-node-externals")
|
||||
const CopyPlugin = require("copy-webpack-plugin")
|
||||
|
||||
module.exports = {
|
||||
devtool: process.env.NODE_ENV === 'develop' ? 'inline-source-map' : 'source-map',
|
||||
target: 'node',
|
||||
devtool:
|
||||
process.env.NODE_ENV === "develop" ? "inline-source-map" : "source-map",
|
||||
target: "node",
|
||||
entry: {
|
||||
scaffold: './scaffold.ts',
|
||||
test: './test.ts',
|
||||
cmd: './cmd.ts',
|
||||
index: "./scaffold.ts",
|
||||
test: "./test.ts",
|
||||
cmd: "./cmd.ts",
|
||||
},
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
devtoolModuleFilenameTemplate: '[absolute-resource-path]',
|
||||
library: 'library',
|
||||
libraryTarget: 'umd',
|
||||
filename: "[name].js",
|
||||
path: path.resolve(__dirname, "dist"),
|
||||
devtoolModuleFilenameTemplate: "[absolute-resource-path]",
|
||||
library: "library",
|
||||
libraryTarget: "umd",
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.ts']
|
||||
extensions: [".ts"],
|
||||
},
|
||||
externals: [nodeExternals()],
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
loader: 'ts-loader',
|
||||
exclude: ['./examples', 'node_modules']
|
||||
}
|
||||
]
|
||||
test: [/\.tsx?$/],
|
||||
loader: "ts-loader",
|
||||
exclude: [/\/examples\//, /\/node_modules\//],
|
||||
},
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'__dirname': '__dirname'
|
||||
__dirname: "__dirname",
|
||||
}),
|
||||
new webpack.BannerPlugin({
|
||||
banner: '#!/usr/bin/env node',
|
||||
banner: "#!/usr/bin/env node",
|
||||
raw: true,
|
||||
include: /cmd\.js/,
|
||||
})
|
||||
include: [/cmd\.js/],
|
||||
}),
|
||||
new CopyPlugin({ patterns: ["index.d.ts"] }),
|
||||
],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user