1.0.1 • Published 6 years ago
gulp-text-to-typescript v1.0.1
Overview
A gulp
plugin that converts text into a typescript constants file.
Installation
npm i -E gulp-text-to-typescript
# or
yarn add -E gulp-text-to-typescript
Usage
In your gulpfile.js
:
const textToTs = require('gulp-text-to-typescript')
gulp.task('parse-text-to-typescript', () => (
gulp.src('src/assets/**/*.txt')
.pipe(textToTs({
fileName: "generatedClass.ts",
className: "TextConstants",
}))
// Files destination
.pipe(gulp.dest('./src/assets'))
))
foo.txt
first text
bar-test.txt
second text
Becomes:
generatedClass.ts
export class TextConstants {
static readonly FOO = "first text";
static readonly BAR_TEST = "first text";
}
In your app, import the result like so (directory nesting depends on your build configuration):
import { TextConstants } from 'assets/generatedClass.ts';
Options
There are two available options:
fileName:
- Required.
- Name of the generated file.
className:
- Optional.
- Name of the class.
- Default name is 'TsConstants'
Credits
Base idea took from: https://github.com/Mitranim/gulp-html-to-js