Skip to content

Commit 1e0abf9

Browse files
author
Chen Asraf
committed
Published + renamed, bugfixes
1 parent c341fe7 commit 1e0abf9

7 files changed

Lines changed: 40 additions & 47 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ typings/
5858
.env
5959

6060
dist
61+
examples/test-output
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from 'react'
2+
3+
class {%Name%} extends React.Component {
4+
private {%property%}
5+
6+
constructor() {
7+
this.{%property%} = {%value%}
8+
}
9+
10+
<div className={css.{%Name%}} />
11+
}
12+
13+
export default {%Name%}

examples/test-input/Component/{{Name}}.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

examples/test-output/MyComponent.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
2-
"name": "scaffolder",
3-
"version": "1.0.0",
2+
"name": "simple-scaffold",
3+
"version": "0.1.1",
44
"description": "Create files based on templates",
5-
"repository": "https://github.com/chenasraf/scaffolder.git",
6-
"author": "Chen Asraf <chen@asraf.me>",
5+
"repository": "https://github.com/chenasraf/simple-scaffold.git",
6+
"author": "Chen Asraf <inbox@casraf.com>",
77
"license": "MIT",
88
"main": "./dist/scaffold.js",
99
"bin": "./dist/scaffold.js",
1010
"scripts": {
11-
"build": "webpack -p",
11+
"build": "webpack -p && chmod +x ./dist/scaffold.js",
1212
"dev": "webpack --watch",
13-
"start": "chmod +x ./dist/scaffold.js && node ./dist/scaffold.js"
13+
"start": "node ./dist/scaffold.js",
14+
"test": "yarn build && node ./scripts/test.js"
1415
},
1516
"devDependencies": {
1617
"@types/node": "^8.0.50",
1718
"ts-loader": "^3.1.1",
1819
"typescript": "^2.6.1",
1920
"webpack": "^3.8.1",
2021
"webpack-dev-server": "^2.9.4"
21-
},
22-
"dependencies": {}
22+
}
2323
}

scaffold.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from 'fs'
22
import * as path from 'path'
33
import { IScaffold } from './index'
44

5-
class Scaffold {
5+
class SimpleScaffold {
66
private config: IScaffold.IConfig
77
private locals = {} as any
88
public scaffoldName = process.argv[2]
@@ -28,7 +28,7 @@ class Scaffold {
2828

2929
private parseLocals(text: string): string {
3030
let out = text.toString()
31-
const pattern = /{{\s*(.+)\s*}}/gi
31+
const pattern = /{[%]\s*([^%{}]+)\s*[%]}/gi
3232
return out.replace(pattern, (match: string, $1: string) => this.locals[$1])
3333
}
3434

@@ -60,7 +60,7 @@ class Scaffold {
6060
if (typeof this.config.output === 'function') {
6161
out = this.config.output(file)
6262
} else {
63-
out = this.config.output + '/' + path.basename(file)
63+
out = this.config.output + `/${this.scaffoldName}/` + path.basename(file)
6464
}
6565

6666
return this.parseLocals(out)
@@ -70,6 +70,7 @@ class Scaffold {
7070
if (!fs.existsSync(path.dirname(filePath))) {
7171
fs.mkdirSync(path.dirname(filePath))
7272
}
73+
console.info('Writing file:', filePath)
7374
fs.writeFileSync(filePath, fileContents, { encoding: 'utf-8' })
7475
}
7576

@@ -80,21 +81,9 @@ class Scaffold {
8081
const outputPath = this.getOutputPath(file)
8182
const contents = this.getFileContents(file)
8283
const outputContents = this.parseLocals(contents)
83-
84-
this.writeFile(outputPath, contents)
85-
86-
console.info({outputPath, outputContents})
84+
this.writeFile(outputPath, outputContents)
8785
})
8886
}
8987
}
9088

91-
const templateDir = process.cwd() + '/examples'
92-
const scf = new Scaffold({
93-
templates: [templateDir + '/test-input/Component'],
94-
output: templateDir + '/test-output',
95-
locals: {
96-
property: 'myProp'
97-
}
98-
})
99-
100-
scf.run()
89+
exports.default = SimpleScaffold

scripts/test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const Scaffolder = require('../dist/scaffold').default
2+
3+
const templateDir = process.cwd() + '/examples'
4+
5+
const scf = new Scaffolder({
6+
templates: [templateDir + '/test-input/Component'],
7+
output: templateDir + '/test-output',
8+
locals: {
9+
property: 'myProp',
10+
value: '"value"'
11+
}
12+
}).run()

0 commit comments

Comments
 (0)