forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added types declarations to handlebars-webpack-plugin (DefinitelyType…
…d#51425) * Added haldebars-webpack-plugin types * Fixed errors * Fixed errors * Fixed errors * Update types/handlebars-webpack-plugin/package.json Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <[email protected]> Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <[email protected]>
- Loading branch information
1 parent
f14df1f
commit ac48cb0
Showing
5 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
types/handlebars-webpack-plugin/handlebars-webpack-plugin-tests.ts
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,54 @@ | ||
import path = require('path'); | ||
import HandlebarsPlugin = require('handlebars-webpack-plugin'); | ||
import HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
|
||
module.exports = { | ||
plugins: [ | ||
new HandlebarsPlugin(), | ||
new HandlebarsPlugin({}), | ||
new HandlebarsPlugin({ | ||
htmlWebpackPlugin: { | ||
title: 'hey', | ||
}, | ||
}), | ||
new HandlebarsPlugin({ | ||
htmlWebpackPlugin: { | ||
title: 'hey', | ||
HtmlWebpackPlugin, | ||
}, | ||
}), | ||
new HandlebarsPlugin({ | ||
entry: path.join(process.cwd(), 'app', 'src', '*.hbs'), | ||
output: path.join(process.cwd(), 'build', '[name].html'), | ||
data: require('package.json'), | ||
partials: [path.join(process.cwd(), 'app', 'src', 'components', '*', '*.hbs')], | ||
helpers: { | ||
hi: (arg1, arg2, options) => {}, | ||
hey: (arg1, arg2, options) => {}, | ||
}, | ||
getTargetFilepath: (filepath, outputTemplate, rootFolder) => { | ||
const fileName = path.basename(filepath).replace(path.extname(filepath), ''); | ||
return outputTemplate.replace('[name]', fileName); | ||
}, | ||
getPartialId: filePath => { | ||
return filePath.match(/\/([^/]+\/[^/]+)\.[^.]+$/)?.pop(); | ||
}, | ||
}), | ||
new HandlebarsPlugin({ | ||
entry: path.join(process.cwd(), 'app', 'src', '*.hbs'), | ||
output: path.join(process.cwd(), 'build', '[name].html'), | ||
data: path.join(__dirname, 'app/data/project.json'), | ||
partials: [path.join(process.cwd(), 'app', 'src', 'components', '*', '*.hbs')], | ||
helpers: { | ||
is: (arg1, arg2, options) => {}, | ||
projectHelpers: path.join(process.cwd(), 'app', 'helpers', '*.helper.js'), | ||
}, | ||
onBeforeSetup: Handlebars => {}, | ||
onBeforeAddPartials: (Handlebars, partialsMap) => {}, | ||
onBeforeCompile: (Handlebars, templateContent) => {}, | ||
onBeforeRender: (Handlebars, data, filename) => {}, | ||
onBeforeSave: (Handlebars, resultHtml, filename) => {}, | ||
onDone: (Handlebars, filename) => {}, | ||
}), | ||
], | ||
}; |
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,114 @@ | ||
// Type definitions for handlebars-webpack-plugin 2.2 | ||
// Project: https://github.com/sagold/handlebars-webpack-plugin | ||
// Definitions by: odas0R <https://github.com/Odas0R> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// Minimum TypeScript Version: 3.7 | ||
|
||
import { Compiler, WebpackPluginInstance } from 'webpack'; | ||
import { HelperDeclareSpec } from 'handlebars'; | ||
import { Options } from 'html-webpack-plugin'; | ||
|
||
import HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
|
||
declare class HandlebarsWebpackPlugin implements WebpackPluginInstance { | ||
constructor(options?: HandlebarsWebpackPlugin.PluginOptions); | ||
|
||
/** | ||
* Apply the plugin | ||
*/ | ||
apply(compiler: Compiler): void; | ||
} | ||
|
||
declare namespace HandlebarsWebpackPlugin { | ||
/** | ||
* Type for the object partials that the plugin creates in other to process all partials | ||
*/ | ||
interface PartialsMap { | ||
[partial: string]: string; | ||
} | ||
|
||
/** | ||
* Handlebars Webpack Plugin Options | ||
*/ | ||
interface PluginOptions { | ||
/** | ||
* Path to hbs entry file(s). | ||
* Also supports nested directories if write | ||
* path.join(process.cwd(), "app", "src", "**", "*.hbs"), | ||
*/ | ||
entry?: string; | ||
|
||
/** | ||
* Output path and filename(s). | ||
* This should lie within the webpacks output-folder | ||
* if omitted, the input filepath stripped of its extension will be used | ||
*/ | ||
output?: string; | ||
|
||
/** | ||
* You can also add a [path] variable, which will emit the files with their | ||
* relative path, like output: | ||
* path.join(process.cwd(), "build", [path], "[name].html | ||
* | ||
* data passed to main hbs template: `main-template(data)` | ||
*/ | ||
data?: object | string; | ||
|
||
/** | ||
* globbed path to partials, where folder/filename is unique | ||
*/ | ||
partials?: string[]; | ||
|
||
/** | ||
* Register custom helpers. May be either a function or a glob-pattern | ||
*/ | ||
helpers?: HelperDeclareSpec | { projectHelpers: string }; | ||
|
||
/** | ||
* Modify the default output path of each entry-template | ||
*/ | ||
getTargetFilepath?: (filepath: string, outputTemplate: string, rootFolder: string) => string | undefined; | ||
|
||
/** | ||
* Modify the hbs partial-id created for a loaded partial | ||
*/ | ||
getPartialId?: (filePath: string) => string | undefined; | ||
|
||
/** | ||
* onBeforeSetup hook, runs before setup of the plugin | ||
*/ | ||
onBeforeSetup?: (Handlebars: RuntimeOptions) => any; | ||
|
||
/** | ||
* onBeforeAddPartials hook, runs before the partials addition to the .html files | ||
*/ | ||
onBeforeAddPartials?: (Handlebars: RuntimeOptions, partialsMap: PartialsMap) => any; | ||
|
||
/** | ||
* onBeforeCompile hook, runs before the plugin compilation | ||
*/ | ||
onBeforeCompile?: (Handlebars: RuntimeOptions, templateContent: string) => any; | ||
|
||
/** | ||
* onBeforeRender hook, runs before rendering of the templates | ||
*/ | ||
onBeforeRender?: (Handlebars: RuntimeOptions, data: object, filename: string) => any; | ||
|
||
/** | ||
* onBeforeSave hook, runs before saving | ||
*/ | ||
onBeforeSave?: (Handlebars: RuntimeOptions, resultHtml: string, filename: string) => any; | ||
|
||
/** | ||
* onDone, runs before the final stages of the plugin | ||
*/ | ||
onDone?: (Handlebars: RuntimeOptions, filename: string) => any; | ||
|
||
/** | ||
* HtmlWebpackPlugin additional configurations | ||
*/ | ||
htmlWebpackPlugin?: Options | HtmlWebpackPlugin; | ||
} | ||
} | ||
|
||
export = HandlebarsWebpackPlugin; |
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,6 @@ | ||
{ | ||
"private": true, | ||
"dependencies": { | ||
"handlebars": ">=4.0.3" | ||
} | ||
} |
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,23 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": [ | ||
"es6" | ||
], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictFunctionTypes": true, | ||
"strictNullChecks": true, | ||
"baseUrl": "../", | ||
"typeRoots": [ | ||
"../" | ||
], | ||
"types": [], | ||
"noEmit": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.d.ts", | ||
"handlebars-webpack-plugin-tests.ts" | ||
] | ||
} |
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 @@ | ||
{ "extends": "dtslint/dt.json" } |