@kjots/package-creator
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -6,2 +6,18 @@ # Change Log | ||
# [0.6.0](https://github.com/kjots/package-tools/compare/v0.5.0...v0.6.0) (2020-01-17) | ||
### Features | ||
* **package-creator:** add option for `packageCreator()` to provide context for template ([9448169](https://github.com/kjots/package-tools/commit/94481690915640c47ceef8010479ec9a8f54dbf5)) | ||
### Reverts | ||
* feat(package-creator): update `packageCreator()` to pass all provided options to template ([0d41830](https://github.com/kjots/package-tools/commit/0d418309c2d94bad3212b77c4470ab6636f5a118)) | ||
# [0.5.0](https://github.com/kjots/package-tools/compare/v0.4.0...v0.5.0) (2020-01-17) | ||
@@ -8,0 +24,0 @@ |
@@ -0,8 +1,15 @@ | ||
export declare type TemplateContextValue = undefined | null | boolean | number | string | Array<TemplateContextValue> | { | ||
[key: string]: TemplateContextValue; | ||
}; | ||
export interface TemplateContext { | ||
[key: string]: TemplateContextValue; | ||
} | ||
export interface Opts { | ||
output: string; | ||
name: string; | ||
description: string; | ||
description?: string; | ||
keywords: Array<string>; | ||
templateContext?: TemplateContext; | ||
} | ||
export declare const defaults: Partial<Opts>; | ||
export declare function packageCreator(templateZip: string, opts: Opts): void; |
@@ -21,7 +21,9 @@ "use strict"; | ||
function packageCreator(templateZip, opts) { | ||
const nameCamelCase = lodash_1.camelCase(opts.name); | ||
const { name, description } = opts; | ||
const nameCamelCase = lodash_1.camelCase(name); | ||
const nameTitleCase = lodash_1.upperFirst(nameCamelCase); | ||
const keywords = opts.keywords.map((keyword, i) => ({ keyword, first: i === 0, last: i === opts.keywords.length - 1 })); | ||
const templateContext = opts.templateContext || {}; | ||
readTemplateFiles(templateZip) | ||
.pipe(applyTemplate({ ...opts, nameCamelCase, nameTitleCase, keywords }), vinyl_fs_observable_1.dest(opts.output), operators_1.concatMap(file => rxjs_1.from(fs_1.promises.chmod(file.path, file.mode)))) | ||
.pipe(applyTemplate({ name, nameCamelCase, nameTitleCase, description, keywords, ...templateContext }), vinyl_fs_observable_1.dest(opts.output), operators_1.concatMap(file => rxjs_1.from(fs_1.promises.chmod(file.path, file.mode)))) | ||
.subscribe(); | ||
@@ -28,0 +30,0 @@ } |
{ | ||
"name": "@kjots/package-creator", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "@kjots package creator", | ||
@@ -37,3 +37,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "97cbb557e5955ab89f59f8305aff41a71cda50bd" | ||
"gitHead": "1dbe96e097261549805c1f7220f164cec56cd279" | ||
} |
@@ -16,7 +16,14 @@ import { promises as fs } from 'fs'; | ||
export type TemplateContextValue = undefined | null | boolean | number | string | Array<TemplateContextValue> | { [key: string]: TemplateContextValue }; | ||
export interface TemplateContext { | ||
[key: string]: TemplateContextValue; | ||
} | ||
export interface Opts { | ||
output: string; | ||
name: string; | ||
description: string; | ||
description?: string; | ||
keywords: Array<string>; | ||
templateContext?: TemplateContext; | ||
} | ||
@@ -30,18 +37,12 @@ | ||
interface TemplateContext { | ||
name: string; | ||
nameCamelCase: string; | ||
nameTitleCase: string; | ||
description?: string; | ||
keywords: Array<{ keyword: string, first: boolean, last: boolean }>; | ||
} | ||
export function packageCreator(templateZip: string, opts: Opts) { | ||
const nameCamelCase = camelCase(opts.name); | ||
const { name, description } = opts; | ||
const nameCamelCase = camelCase(name); | ||
const nameTitleCase = upperFirst(nameCamelCase); | ||
const keywords = opts.keywords.map((keyword, i) => ({ keyword, first: i === 0, last: i === opts.keywords.length - 1 })); | ||
const templateContext = opts.templateContext || {}; | ||
readTemplateFiles(templateZip) | ||
.pipe( | ||
applyTemplate({ ...opts, nameCamelCase, nameTitleCase, keywords }), | ||
applyTemplate({ name, nameCamelCase, nameTitleCase, description, keywords, ...templateContext }), | ||
dest(opts.output), | ||
@@ -48,0 +49,0 @@ concatMap(file => from(fs.chmod(file.path, file.mode))) |
Sorry, the diff of this file is not supported yet
24532
214