-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ffc4b18
commit ad22e2c
Showing
9 changed files
with
87 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as path from 'path' | ||
import * as fs from 'fs' | ||
import { test, mkdir } from 'shelljs' | ||
import template from 'lodash.template' | ||
|
||
import { format } from './format' | ||
|
||
export const mkd = (dir: string): void => { | ||
!test('-d', dir) && mkdir('-p', dir) | ||
} | ||
|
||
export const touch = (file: string, raw: string) => | ||
new Promise(async (resolve, reject) => { | ||
const content = /jsx?$/.test(path.extname(file)) ? await format(raw) : raw | ||
const stream = fs.createWriteStream(file) | ||
|
||
stream.write(content, 'utf-8') | ||
stream.on('finish', () => resolve()) | ||
stream.on('error', err => reject(err)) | ||
stream.end() | ||
}) | ||
|
||
export const read = (filepath: string): Promise<string> => | ||
new Promise<string>((resolve, reject) => { | ||
let data = '' | ||
const stream = fs.createReadStream(filepath, { encoding: 'utf-8' }) | ||
|
||
stream.on('data', chunk => (data += chunk)) | ||
stream.on('end', () => resolve(data)) | ||
stream.on('error', err => reject(err)) | ||
}) | ||
|
||
export const compiled = async (file: string): Promise<(args: any) => string> => | ||
read(file) | ||
.then(data => template(data)) | ||
.catch(err => err) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters