Published + renamed, bugfixes

This commit is contained in:
Chen Asraf
2018-01-01 23:10:59 +02:00
parent c341fe749c
commit 1e0abf9198
7 changed files with 40 additions and 47 deletions

1
.gitignore vendored
View File

@@ -58,3 +58,4 @@ typings/
.env
dist
examples/test-output

View File

@@ -0,0 +1,13 @@
import * as React from 'react'
class {%Name%} extends React.Component {
private {%property%}
constructor() {
this.{%property%} = {%value%}
}
<div className={css.{%Name%}} />
}
export default {%Name%}

View File

@@ -1,11 +0,0 @@
import * as React from 'react'
class {{Name}} extends React.Component {
private {{property}}
constructor() {
this.{{property}} = {{value}}
}
}
export default {{Name}}

View File

@@ -1,11 +0,0 @@
import * as React from 'react'
class {{Name}} extends React.Component {
private {{property}}
constructor() {
this.{{property}} = {{value}}
}
}
export default {{Name}}

View File

@@ -1,16 +1,17 @@
{
"name": "scaffolder",
"version": "1.0.0",
"name": "simple-scaffold",
"version": "0.1.1",
"description": "Create files based on templates",
"repository": "https://github.com/chenasraf/scaffolder.git",
"author": "Chen Asraf <chen@asraf.me>",
"repository": "https://github.com/chenasraf/simple-scaffold.git",
"author": "Chen Asraf <inbox@casraf.com>",
"license": "MIT",
"main": "./dist/scaffold.js",
"bin": "./dist/scaffold.js",
"scripts": {
"build": "webpack -p",
"build": "webpack -p && chmod +x ./dist/scaffold.js",
"dev": "webpack --watch",
"start": "chmod +x ./dist/scaffold.js && node ./dist/scaffold.js"
"start": "node ./dist/scaffold.js",
"test": "yarn build && node ./scripts/test.js"
},
"devDependencies": {
"@types/node": "^8.0.50",
@@ -18,6 +19,5 @@
"typescript": "^2.6.1",
"webpack": "^3.8.1",
"webpack-dev-server": "^2.9.4"
},
"dependencies": {}
}
}

View File

@@ -2,7 +2,7 @@ import * as fs from 'fs'
import * as path from 'path'
import { IScaffold } from './index'
class Scaffold {
class SimpleScaffold {
private config: IScaffold.IConfig
private locals = {} as any
public scaffoldName = process.argv[2]
@@ -28,7 +28,7 @@ class Scaffold {
private parseLocals(text: string): string {
let out = text.toString()
const pattern = /{{\s*(.+)\s*}}/gi
const pattern = /{[%]\s*([^%{}]+)\s*[%]}/gi
return out.replace(pattern, (match: string, $1: string) => this.locals[$1])
}
@@ -60,7 +60,7 @@ class Scaffold {
if (typeof this.config.output === 'function') {
out = this.config.output(file)
} else {
out = this.config.output + '/' + path.basename(file)
out = this.config.output + `/${this.scaffoldName}/` + path.basename(file)
}
return this.parseLocals(out)
@@ -70,6 +70,7 @@ class Scaffold {
if (!fs.existsSync(path.dirname(filePath))) {
fs.mkdirSync(path.dirname(filePath))
}
console.info('Writing file:', filePath)
fs.writeFileSync(filePath, fileContents, { encoding: 'utf-8' })
}
@@ -80,21 +81,9 @@ class Scaffold {
const outputPath = this.getOutputPath(file)
const contents = this.getFileContents(file)
const outputContents = this.parseLocals(contents)
this.writeFile(outputPath, contents)
console.info({outputPath, outputContents})
this.writeFile(outputPath, outputContents)
})
}
}
const templateDir = process.cwd() + '/examples'
const scf = new Scaffold({
templates: [templateDir + '/test-input/Component'],
output: templateDir + '/test-output',
locals: {
property: 'myProp'
}
})
scf.run()
exports.default = SimpleScaffold

12
scripts/test.js Normal file
View File

@@ -0,0 +1,12 @@
const Scaffolder = require('../dist/scaffold').default
const templateDir = process.cwd() + '/examples'
const scf = new Scaffolder({
templates: [templateDir + '/test-input/Component'],
output: templateDir + '/test-output',
locals: {
property: 'myProp',
value: '"value"'
}
}).run()