From e6afa9ad4fc55f7792756fa999ab2dbcefdb81ec Mon Sep 17 00:00:00 2001 From: Stefan Bauer Date: Tue, 7 Mar 2017 21:57:26 +0100 Subject: [PATCH] HandlebarJS sample using webpack loader configuration (#142) * handlebarsjs webpack loader sample * removed trashed folder --- .../handlebarsjs-webpack-loader/.editorconfig | 25 ++ .../.gitattributes | 1 + .../handlebarsjs-webpack-loader/.gitignore | 32 ++ .../handlebarsjs-webpack-loader/.npmignore | 14 + .../.vscode/settings.json | 3 + .../handlebarsjs-webpack-loader/.yo-rc.json | 8 + samples/handlebarsjs-webpack-loader/README.md | 45 +++ .../config/config.json | 19 ++ .../config/copy-assets.json | 3 + .../config/copy-static-assets.json | 6 + .../config/deploy-azure-storage.json | 6 + .../config/package-solution.json | 10 + .../config/serve.json | 9 + .../config/tslint.json | 46 +++ .../config/write-manifests.json | 3 + .../handlebarsjs-webpack-loader/gulpfile.js | 22 ++ .../handlebarsjs-webpack-loader/package.json | 29 ++ .../handlebarsjs-webpack-loader/settings.json | 3 + .../src/templates/HelloWorld.hbs | 14 + .../handlebarsDemo/HandlebarsDemo.module.scss | 52 ++++ .../HandlebarsDemoWebPart.manifest.json | 20 ++ .../handlebarsDemo/HandlebarsDemoWebPart.ts | 59 ++++ .../IHandlebarsDemoWebPartProps.ts | 3 + .../src/webparts/handlebarsDemo/loc/en-us.js | 7 + .../handlebarsDemo/loc/mystrings.d.ts | 10 + .../tests/HandlebarsDemo.test.ts | 9 + .../handlebarsjs-webpack-loader/tsconfig.json | 15 + .../handlebarsjs-webpack-loader/typings.json | 5 + .../typings/@ms/odsp.d.ts | 8 + .../typings/globals/handlebars/index.d.ts | 291 ++++++++++++++++++ .../typings/globals/handlebars/typings.json | 8 + .../typings/index.d.ts | 1 + .../typings/tsd.d.ts | 1 + 33 files changed, 787 insertions(+) create mode 100644 samples/handlebarsjs-webpack-loader/.editorconfig create mode 100644 samples/handlebarsjs-webpack-loader/.gitattributes create mode 100644 samples/handlebarsjs-webpack-loader/.gitignore create mode 100644 samples/handlebarsjs-webpack-loader/.npmignore create mode 100644 samples/handlebarsjs-webpack-loader/.vscode/settings.json create mode 100644 samples/handlebarsjs-webpack-loader/.yo-rc.json create mode 100644 samples/handlebarsjs-webpack-loader/README.md create mode 100644 samples/handlebarsjs-webpack-loader/config/config.json create mode 100644 samples/handlebarsjs-webpack-loader/config/copy-assets.json create mode 100644 samples/handlebarsjs-webpack-loader/config/copy-static-assets.json create mode 100644 samples/handlebarsjs-webpack-loader/config/deploy-azure-storage.json create mode 100644 samples/handlebarsjs-webpack-loader/config/package-solution.json create mode 100644 samples/handlebarsjs-webpack-loader/config/serve.json create mode 100644 samples/handlebarsjs-webpack-loader/config/tslint.json create mode 100644 samples/handlebarsjs-webpack-loader/config/write-manifests.json create mode 100644 samples/handlebarsjs-webpack-loader/gulpfile.js create mode 100644 samples/handlebarsjs-webpack-loader/package.json create mode 100644 samples/handlebarsjs-webpack-loader/settings.json create mode 100644 samples/handlebarsjs-webpack-loader/src/templates/HelloWorld.hbs create mode 100644 samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/HandlebarsDemo.module.scss create mode 100644 samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/HandlebarsDemoWebPart.manifest.json create mode 100644 samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/HandlebarsDemoWebPart.ts create mode 100644 samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/IHandlebarsDemoWebPartProps.ts create mode 100644 samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/loc/en-us.js create mode 100644 samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/loc/mystrings.d.ts create mode 100644 samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/tests/HandlebarsDemo.test.ts create mode 100644 samples/handlebarsjs-webpack-loader/tsconfig.json create mode 100644 samples/handlebarsjs-webpack-loader/typings.json create mode 100644 samples/handlebarsjs-webpack-loader/typings/@ms/odsp.d.ts create mode 100644 samples/handlebarsjs-webpack-loader/typings/globals/handlebars/index.d.ts create mode 100644 samples/handlebarsjs-webpack-loader/typings/globals/handlebars/typings.json create mode 100644 samples/handlebarsjs-webpack-loader/typings/index.d.ts create mode 100644 samples/handlebarsjs-webpack-loader/typings/tsd.d.ts diff --git a/samples/handlebarsjs-webpack-loader/.editorconfig b/samples/handlebarsjs-webpack-loader/.editorconfig new file mode 100644 index 000000000..8ffcdc4ec --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/.editorconfig @@ -0,0 +1,25 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + + +[*] + +# change these settings to your own preference +indent_style = space +indent_size = 2 + +# we recommend you to keep these unchanged +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false + +[{package,bower}.json] +indent_style = space +indent_size = 2 \ No newline at end of file diff --git a/samples/handlebarsjs-webpack-loader/.gitattributes b/samples/handlebarsjs-webpack-loader/.gitattributes new file mode 100644 index 000000000..212566614 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/.gitattributes @@ -0,0 +1 @@ +* text=auto \ No newline at end of file diff --git a/samples/handlebarsjs-webpack-loader/.gitignore b/samples/handlebarsjs-webpack-loader/.gitignore new file mode 100644 index 000000000..b19bbe123 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/.gitignore @@ -0,0 +1,32 @@ +# Logs +logs +*.log +npm-debug.log* + +# Dependency directories +node_modules + +# Build generated files +dist +lib +solution +temp +*.sppkg + +# Coverage directory used by tools like istanbul +coverage + +# OSX +.DS_Store + +# Visual Studio files +.ntvs_analysis.dat +.vs +bin +obj + +# Resx Generated Code +*.resx.ts + +# Styles Generated Code +*.scss.ts diff --git a/samples/handlebarsjs-webpack-loader/.npmignore b/samples/handlebarsjs-webpack-loader/.npmignore new file mode 100644 index 000000000..2c93a9384 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/.npmignore @@ -0,0 +1,14 @@ +# Folders +.vscode +coverage +node_modules +sharepoint +src +temp + +# Files +*.csproj +.git* +.yo-rc.json +gulpfile.js +tsconfig.json diff --git a/samples/handlebarsjs-webpack-loader/.vscode/settings.json b/samples/handlebarsjs-webpack-loader/.vscode/settings.json new file mode 100644 index 000000000..0c4a6693f --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "vsicons.presets.angular": false +} \ No newline at end of file diff --git a/samples/handlebarsjs-webpack-loader/.yo-rc.json b/samples/handlebarsjs-webpack-loader/.yo-rc.json new file mode 100644 index 000000000..e4881614b --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/.yo-rc.json @@ -0,0 +1,8 @@ +{ + "@microsoft/generator-sharepoint": { + "libraryName": "spfx-handlebars", + "framework": "none", + "version": "1.0.0", + "libraryId": "b8285cda-e974-4141-aab6-b7927b732a41" + } +} \ No newline at end of file diff --git a/samples/handlebarsjs-webpack-loader/README.md b/samples/handlebarsjs-webpack-loader/README.md new file mode 100644 index 000000000..2b8972948 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/README.md @@ -0,0 +1,45 @@ +## SPFx Sample with Handlebars.js + +This sample demonstrate how to set up SPFX to use [Handlebars](http://handlebarsjs.com) through [webpack loader](https://webpack.github.io/docs/loaders.html). + + + +## Used SharePoint Framework Version +![drop](https://img.shields.io/badge/drop-GA-green.svg) + +## Applies to + +* [SharePoint Framework Developer](http://dev.office.com/sharepoint/docs/spfx/sharepoint-framework-overview) +* [Office 365 developer tenant](http://dev.office.com/sharepoint/docs/spfx/set-up-your-developer-tenant) + +## Solution + +Solution|Author(s) +--------|--------- +SPFx-handlebars | Stefan Bauer - n8d ([@stfbauer](https://twitter.com/stfbauer)) + +## Version history + +Version|Date|Comments +-------|----|-------- +1.0|March 5, 2017|Initial release + +## Disclaimer +**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.** + +### Building the code + +```bash +git clone the repo +npm i +npm i -g gulp +gulp +``` + +This package produces the following: + +* lib/* - intermediate-stage commonjs build artifacts +* dist/* - the bundled script, along with other resources +* deploy/* - all resources which should be uploaded to a CDN. + + diff --git a/samples/handlebarsjs-webpack-loader/config/config.json b/samples/handlebarsjs-webpack-loader/config/config.json new file mode 100644 index 000000000..1a13f35cf --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/config/config.json @@ -0,0 +1,19 @@ +{ + "entries": [{ + "entry": "./lib/webparts/handlebarsDemo/HandlebarsDemoWebPart.js", + "manifest": "./src/webparts/handlebarsDemo/HandlebarsDemoWebPart.manifest.json", + "outputPath": "./dist/handlebars-demo.bundle.js" + }], + "externals": { + + // Load Handlebar templates from CDN + // "handlebars": "https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.6/handlebars.amd.js" + + // load handlebars from node_modules + "handlebars": "./node_modules/handlebars/dist/handlebars.amd.min.js" + + }, + "localizedResources": { + "handlebarsDemoStrings": "webparts/handlebarsDemo/loc/{locale}.js" + } +} diff --git a/samples/handlebarsjs-webpack-loader/config/copy-assets.json b/samples/handlebarsjs-webpack-loader/config/copy-assets.json new file mode 100644 index 000000000..6aca63656 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/config/copy-assets.json @@ -0,0 +1,3 @@ +{ + "deployCdnPath": "temp/deploy" +} diff --git a/samples/handlebarsjs-webpack-loader/config/copy-static-assets.json b/samples/handlebarsjs-webpack-loader/config/copy-static-assets.json new file mode 100644 index 000000000..dd91b5024 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/config/copy-static-assets.json @@ -0,0 +1,6 @@ +// copy-static-assets.json +{ + "includeExtensions": [ + "hbs" + ] +} diff --git a/samples/handlebarsjs-webpack-loader/config/deploy-azure-storage.json b/samples/handlebarsjs-webpack-loader/config/deploy-azure-storage.json new file mode 100644 index 000000000..05b016a5b --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/config/deploy-azure-storage.json @@ -0,0 +1,6 @@ +{ + "workingDir": "./temp/deploy/", + "account": "", + "container": "spfx-handlebars", + "accessKey": "" +} \ No newline at end of file diff --git a/samples/handlebarsjs-webpack-loader/config/package-solution.json b/samples/handlebarsjs-webpack-loader/config/package-solution.json new file mode 100644 index 000000000..c7ecdf98f --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/config/package-solution.json @@ -0,0 +1,10 @@ +{ + "solution": { + "name": "spfx-handlebars-client-side-solution", + "id": "b8285cda-e974-4141-aab6-b7927b732a41", + "version": "1.0.0.0" + }, + "paths": { + "zippedPackage": "solution/spfx-handlebars.sppkg" + } +} diff --git a/samples/handlebarsjs-webpack-loader/config/serve.json b/samples/handlebarsjs-webpack-loader/config/serve.json new file mode 100644 index 000000000..087899637 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/config/serve.json @@ -0,0 +1,9 @@ +{ + "port": 4321, + "initialPage": "https://localhost:5432/workbench", + "https": true, + "api": { + "port": 5432, + "entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/" + } +} diff --git a/samples/handlebarsjs-webpack-loader/config/tslint.json b/samples/handlebarsjs-webpack-loader/config/tslint.json new file mode 100644 index 000000000..3c085daaf --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/config/tslint.json @@ -0,0 +1,46 @@ +{ + // Display errors as warnings + "displayAsWarning": true, + // The TSLint task may have been configured with several custom lint rules + // before this config file is read (for example lint rules from the tslint-microsoft-contrib + // project). If true, this flag will deactivate any of these rules. + "removeExistingRules": true, + // When true, the TSLint task is configured with some default TSLint "rules.": + "useDefaultConfigAsBase": false, + // Since removeExistingRules=true and useDefaultConfigAsBase=false, there will be no lint rules + // which are active, other than the list of rules below. + "lintConfig": { + // Opt-in to Lint rules which help to eliminate bugs in JavaScript + "rules": { + "class-name": false, + "export-name": false, + "forin": false, + "label-position": false, + "member-access": true, + "no-arg": false, + "no-console": false, + "no-construct": false, + "no-duplicate-case": true, + "no-duplicate-variable": true, + "no-eval": false, + "no-function-expression": true, + "no-internal-module": true, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-unnecessary-semicolons": true, + "no-unused-expression": true, + "no-unused-imports": true, + "no-use-before-declare": true, + "no-with-statement": true, + "semicolon": true, + "trailing-comma": false, + "typedef": false, + "typedef-whitespace": false, + "use-named-parameter": true, + "valid-typeof": true, + "variable-name": false, + "whitespace": false, + "prefer-const": true + } + } +} \ No newline at end of file diff --git a/samples/handlebarsjs-webpack-loader/config/write-manifests.json b/samples/handlebarsjs-webpack-loader/config/write-manifests.json new file mode 100644 index 000000000..0a4bafb06 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/config/write-manifests.json @@ -0,0 +1,3 @@ +{ + "cdnBasePath": "" +} \ No newline at end of file diff --git a/samples/handlebarsjs-webpack-loader/gulpfile.js b/samples/handlebarsjs-webpack-loader/gulpfile.js new file mode 100644 index 000000000..8b54bd1cc --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/gulpfile.js @@ -0,0 +1,22 @@ +'use strict'; + +const gulp = require('gulp'); +const build = require('@microsoft/sp-build-web'); + +// Custom config section starts here +const loaderConfig = [{ + test: /\.hbs/, + loader: "handlebars-template-loader" +}]; + +// push loader configuration to SPFx configuration +build.configureWebpack.mergeConfig({ + additionalConfiguration: (generatedConfiguration) => { + generatedConfiguration.module.loaders.push(loaderConfig); + + return generatedConfiguration; + + } +}); + +build.initialize(gulp); diff --git a/samples/handlebarsjs-webpack-loader/package.json b/samples/handlebarsjs-webpack-loader/package.json new file mode 100644 index 000000000..440e44673 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/package.json @@ -0,0 +1,29 @@ +{ + "name": "spfx-handlebars", + "version": "0.0.1", + "private": true, + "engines": { + "node": ">=0.10.0" + }, + "dependencies": { + "@microsoft/sp-client-base": "~1.0.0", + "@microsoft/sp-core-library": "~1.0.0", + "@microsoft/sp-webpart-base": "~1.0.0", + "@types/webpack-env": ">=1.12.1 <1.14.0", + "handlebars": "^4.0.6" + }, + "devDependencies": { + "@microsoft/sp-build-web": "~1.0.0", + "@microsoft/sp-module-interfaces": "~1.0.0", + "@microsoft/sp-webpart-workbench": "~1.0.0", + "@types/chai": ">=3.4.34 <3.6.0", + "@types/mocha": ">=2.2.33 <2.6.0", + "gulp": "~3.9.1", + "handlebars-template-loader": "^0.7.0" + }, + "scripts": { + "build": "gulp bundle", + "clean": "gulp clean", + "test": "gulp test" + } +} diff --git a/samples/handlebarsjs-webpack-loader/settings.json b/samples/handlebarsjs-webpack-loader/settings.json new file mode 100644 index 000000000..0c4a6693f --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/settings.json @@ -0,0 +1,3 @@ +{ + "vsicons.presets.angular": false +} \ No newline at end of file diff --git a/samples/handlebarsjs-webpack-loader/src/templates/HelloWorld.hbs b/samples/handlebarsjs-webpack-loader/src/templates/HelloWorld.hbs new file mode 100644 index 000000000..27a629d9a --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/src/templates/HelloWorld.hbs @@ -0,0 +1,14 @@ +
+
+
+
+ Welcome to SharePoint! +

Customize SharePoint experiences using Web Parts.

+

{{description}}

+ + Learn more + +
+
+
+
diff --git a/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/HandlebarsDemo.module.scss b/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/HandlebarsDemo.module.scss new file mode 100644 index 000000000..8f3144d1b --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/HandlebarsDemo.module.scss @@ -0,0 +1,52 @@ +.helloWorld { + .container { + max-width: 700px; + margin: 0px auto; + box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1); + } + + .row { + padding: 20px; + } + + .listItem { + max-width: 715px; + margin: 5px auto 5px auto; + box-shadow: 0 0 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1); + } + + .button { + // Our button + text-decoration: none; + height: 32px; + + // Primary Button + min-width: 80px; + background-color: #0078d7; + border-color: #0078d7; + color: #ffffff; + + // Basic Button + outline: transparent; + position: relative; + font-family: "Segoe UI WestEuropean","Segoe UI",-apple-system,BlinkMacSystemFont,Roboto,"Helvetica Neue",sans-serif; + -webkit-font-smoothing: antialiased; + font-size: 14px; + font-weight: 400; + border-width: 0; + text-align: center; + cursor: pointer; + display: inline-block; + padding: 0 16px; + + .label { + font-weight: 600; + font-size: 14px; + height: 32px; + line-height: 32px; + margin: 0 4px; + vertical-align: top; + display: inline-block; + } + } +} \ No newline at end of file diff --git a/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/HandlebarsDemoWebPart.manifest.json b/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/HandlebarsDemoWebPart.manifest.json new file mode 100644 index 000000000..b34c90ec9 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/HandlebarsDemoWebPart.manifest.json @@ -0,0 +1,20 @@ +{ + "$schema": "../../../node_modules/@microsoft/sp-module-interfaces/lib/manifestSchemas/jsonSchemas/clientSideComponentManifestSchema.json", + + "id": "5cf1bbfb-4088-4eb1-8221-c5ebf4e37606", + "alias": "HandlebarsDemoWebPart", + "componentType": "WebPart", + "version": "0.0.1", + "manifestVersion": 2, + + "preconfiguredEntries": [{ + "groupId": "5cf1bbfb-4088-4eb1-8221-c5ebf4e37606", + "group": { "default": "Under Development" }, + "title": { "default": "HandlebarsDemo" }, + "description": { "default": "Handlebars Demo Web Part" }, + "officeFabricIconFontName": "Page", + "properties": { + "description": "HandlebarsDemo" + } + }] +} diff --git a/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/HandlebarsDemoWebPart.ts b/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/HandlebarsDemoWebPart.ts new file mode 100644 index 000000000..a2d47faf6 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/HandlebarsDemoWebPart.ts @@ -0,0 +1,59 @@ +import { Version } from '@microsoft/sp-core-library'; +import { + BaseClientSideWebPart, + IPropertyPaneConfiguration, + PropertyPaneTextField +} from '@microsoft/sp-webpart-base'; +import { escape } from '@microsoft/sp-lodash-subset'; + +import styles from './HandlebarsDemo.module.scss'; +import * as strings from 'handlebarsDemoStrings'; +import { IHandlebarsDemoWebPartProps } from './IHandlebarsDemoWebPartProps'; + +// Importing handlebars +import * as Handlebars from 'handlebars'; + +// load and precompile template +var HelloWorldTemplate = require('../../templates/HelloWorld.hbs'); + +export default class HandlebarsDemoWebPart extends BaseClientSideWebPart { + + public render(): void { + + // bind data to template + var data = { + styles: styles, + description: this.properties.description + } + + // compile and add template + this.domElement.innerHTML = HelloWorldTemplate(data); + + } + + protected get dataVersion(): Version { + return Version.parse('1.0'); + } + + protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration { + return { + pages: [ + { + header: { + description: strings.PropertyPaneDescription + }, + groups: [ + { + groupName: strings.BasicGroupName, + groupFields: [ + PropertyPaneTextField('description', { + label: strings.DescriptionFieldLabel + }) + ] + } + ] + } + ] + }; + } +} diff --git a/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/IHandlebarsDemoWebPartProps.ts b/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/IHandlebarsDemoWebPartProps.ts new file mode 100644 index 000000000..e4eb58e30 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/IHandlebarsDemoWebPartProps.ts @@ -0,0 +1,3 @@ +export interface IHandlebarsDemoWebPartProps { + description: string; +} diff --git a/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/loc/en-us.js b/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/loc/en-us.js new file mode 100644 index 000000000..89f98bc1e --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/loc/en-us.js @@ -0,0 +1,7 @@ +define([], function() { + return { + "PropertyPaneDescription": "Description", + "BasicGroupName": "Group Name", + "DescriptionFieldLabel": "Description Field" + } +}); \ No newline at end of file diff --git a/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/loc/mystrings.d.ts b/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/loc/mystrings.d.ts new file mode 100644 index 000000000..a11b1fafc --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/loc/mystrings.d.ts @@ -0,0 +1,10 @@ +declare interface IHandlebarsDemoStrings { + PropertyPaneDescription: string; + BasicGroupName: string; + DescriptionFieldLabel: string; +} + +declare module 'handlebarsDemoStrings' { + const strings: IHandlebarsDemoStrings; + export = strings; +} diff --git a/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/tests/HandlebarsDemo.test.ts b/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/tests/HandlebarsDemo.test.ts new file mode 100644 index 000000000..c98aeb299 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/src/webparts/handlebarsDemo/tests/HandlebarsDemo.test.ts @@ -0,0 +1,9 @@ +/// + +import { assert } from 'chai'; + +describe('HandlebarsDemoWebPart', () => { + it('should do something', () => { + assert.ok(true); + }); +}); diff --git a/samples/handlebarsjs-webpack-loader/tsconfig.json b/samples/handlebarsjs-webpack-loader/tsconfig.json new file mode 100644 index 000000000..5fa39c930 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "es5", + "forceConsistentCasingInFileNames": true, + "module": "commonjs", + "jsx": "react", + "declaration": true, + "sourceMap": true, + "types": [ + "es6-promise", + "es6-collections", + "webpack-env" + ] + } +} diff --git a/samples/handlebarsjs-webpack-loader/typings.json b/samples/handlebarsjs-webpack-loader/typings.json new file mode 100644 index 000000000..634531043 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/typings.json @@ -0,0 +1,5 @@ +{ + "globalDependencies": { + "handlebars": "registry:dt/handlebars#4.0.5+20160810231743" + } +} diff --git a/samples/handlebarsjs-webpack-loader/typings/@ms/odsp.d.ts b/samples/handlebarsjs-webpack-loader/typings/@ms/odsp.d.ts new file mode 100644 index 000000000..2d2913e53 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/typings/@ms/odsp.d.ts @@ -0,0 +1,8 @@ +// Type definitions for Microsoft ODSP projects +// Project: ODSP + +/* Global definition for UNIT_TEST builds + Code that is wrapped inside an if(UNIT_TEST) {...} + block will not be included in the final bundle when the + --ship flag is specified */ +declare const UNIT_TEST: boolean; \ No newline at end of file diff --git a/samples/handlebarsjs-webpack-loader/typings/globals/handlebars/index.d.ts b/samples/handlebarsjs-webpack-loader/typings/globals/handlebars/index.d.ts new file mode 100644 index 000000000..ace400827 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/typings/globals/handlebars/index.d.ts @@ -0,0 +1,291 @@ +// Generated by typings +// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/90198235019d12c00b3ccca03a36cc3d1579d644/handlebars/index.d.ts +declare namespace Handlebars { + export function registerHelper(name: string, fn: Function, inverse?: boolean): void; + export function registerHelper(name: Object): void; + export function registerPartial(name: string, str: any): void; + export function unregisterHelper(name: string): void; + export function unregisterPartial(name: string): void; + export function K(): void; + export function createFrame(object: any): any; + export function Exception(message: string): void; + export function log(level: number, obj: any): void; + export function parse(input: string): hbs.AST.Program; + export function compile(input: any, options?: CompileOptions): HandlebarsTemplateDelegate; + export function precompile(input: any, options?: PrecompileOptions): TemplateSpecification; + export function template(precompilation: TemplateSpecification): HandlebarsTemplateDelegate; + + export function create(): typeof Handlebars; + + export var SafeString: typeof hbs.SafeString; + export var escapeExpression: typeof hbs.Utils.escapeExpression; + export var Utils: typeof hbs.Utils; + export var logger: Logger; + export var templates: HandlebarsTemplates; + export var helpers: any; + + export function registerDecorator(name: string, fn: Function): void; + export function registerDecorator(obj: {[name: string] : Function}): void; + export function unregisterDecorator(name: string): void; + + export function noConflict(): typeof Handlebars; + + export module AST { + export var helpers: hbs.AST.helpers; + } + + interface ICompiler { + accept(node: hbs.AST.Node): void; + Program(program: hbs.AST.Program): void; + BlockStatement(block: hbs.AST.BlockStatement): void; + PartialStatement(partial: hbs.AST.PartialStatement): void; + PartialBlockStatement(partial: hbs.AST.PartialBlockStatement): void; + DecoratorBlock(decorator: hbs.AST.DecoratorBlock): void; + Decorator(decorator: hbs.AST.Decorator): void; + MustacheStatement(mustache: hbs.AST.MustacheStatement): void; + ContentStatement(content: hbs.AST.ContentStatement): void; + CommentStatement(comment?: hbs.AST.CommentStatement): void; + SubExpression(sexpr: hbs.AST.SubExpression): void; + PathExpression(path: hbs.AST.PathExpression): void; + StringLiteral(str: hbs.AST.StringLiteral): void; + NumberLiteral(num: hbs.AST.NumberLiteral): void; + BooleanLiteral(bool: hbs.AST.BooleanLiteral): void; + UndefinedLiteral(): void; + NullLiteral(): void; + Hash(hash: hbs.AST.Hash): void; + } + + export class Visitor implements ICompiler { + accept(node: hbs.AST.Node): void; + acceptKey(node: hbs.AST.Node, name: string): void; + acceptArray(arr: hbs.AST.Expression[]): void; + Program(program: hbs.AST.Program): void; + BlockStatement(block: hbs.AST.BlockStatement): void; + PartialStatement(partial: hbs.AST.PartialStatement): void; + PartialBlockStatement(partial: hbs.AST.PartialBlockStatement): void; + DecoratorBlock(decorator: hbs.AST.DecoratorBlock): void; + Decorator(decorator: hbs.AST.Decorator): void; + MustacheStatement(mustache: hbs.AST.MustacheStatement): void; + ContentStatement(content: hbs.AST.ContentStatement): void; + CommentStatement(comment?: hbs.AST.CommentStatement): void; + SubExpression(sexpr: hbs.AST.SubExpression): void; + PathExpression(path: hbs.AST.PathExpression): void; + StringLiteral(str: hbs.AST.StringLiteral): void; + NumberLiteral(num: hbs.AST.NumberLiteral): void; + BooleanLiteral(bool: hbs.AST.BooleanLiteral): void; + UndefinedLiteral(): void; + NullLiteral(): void; + Hash(hash: hbs.AST.Hash): void; + } +} + +/** +* Implement this interface on your MVW/MVVM/MVC views such as Backbone.View +**/ +interface HandlebarsTemplatable { + template: HandlebarsTemplateDelegate; +} + +interface HandlebarsTemplateDelegate { + (context: any, options?: any): string; +} + +interface HandlebarsTemplates { + [index: string]: HandlebarsTemplateDelegate; +} + +interface TemplateSpecification { + +} + +interface CompileOptions { + data?: boolean; + compat?: boolean; + knownHelpers?: { + helperMissing?: boolean; + blockHelperMissing?: boolean; + each?: boolean; + if?: boolean; + unless?: boolean; + with?: boolean; + log?: boolean; + lookup?: boolean; + } + knownHelpersOnly?: boolean; + noEscape?: boolean; + strict?: boolean; + assumeObjects?: boolean; + preventIndent?: boolean; + ignoreStandalone?: boolean; + explicitPartialContext?: boolean; +} + +interface PrecompileOptions extends CompileOptions { + srcName?: string; + destName?: string; +} + +declare namespace hbs { + class SafeString { + constructor(str: string); + static toString(): string; + } + + namespace Utils { + function escapeExpression(str: string): string; + function createFrame(obj: Object): Object; + function isEmpty(obj: any) : boolean; + function extend(obj: any, ...source: any[]): any; + function toString(obj: any): string; + function isArray(obj: any): boolean; + function isFunction(obj: any): boolean; + } +} + +interface Logger { + DEBUG: number; + INFO: number; + WARN: number; + ERROR: number; + level: number; + + methodMap: { [level: number]: string }; + + log(level: number, obj: string): void; +} + +declare namespace hbs { + namespace AST { + interface Node { + type: string; + loc: SourceLocation; + } + + interface SourceLocation { + source: string; + start: Position; + end: Position; + } + + interface Position { + line: number; + column: number; + } + + interface Program extends Node { + body: Statement[]; + blockParams: string[]; + } + + interface Statement extends Node {} + + interface MustacheStatement extends Statement { + path: PathExpression | Literal; + params: Expression[]; + hash: Hash; + escaped: boolean; + strip: StripFlags; + } + + interface Decorator extends MustacheStatement { } + + interface BlockStatement extends Statement { + path: PathExpression; + params: Expression[]; + hash: Hash; + program: Program; + inverse: Program; + openStrip: StripFlags; + inverseStrip: StripFlags; + closeStrip: StripFlags; + } + + interface DecoratorBlock extends BlockStatement { } + + interface PartialStatement extends Statement { + name: PathExpression | SubExpression; + params: Expression[]; + hash: Hash; + indent: string; + strip: StripFlags; + } + + interface PartialBlockStatement extends Statement { + name: PathExpression | SubExpression; + params: Expression[], + hash: Hash, + program: Program, + openStrip: StripFlags, + closeStrip: StripFlags + } + + interface ContentStatement extends Statement { + value: string; + original: StripFlags; + } + + interface CommentStatement extends Statement { + value: string; + strip: StripFlags; + } + + interface Expression extends Node {} + + interface SubExpression extends Expression { + path: PathExpression; + params: Expression[]; + hash: Hash; + } + + interface PathExpression extends Expression { + data: boolean; + depth: number; + parts: string[]; + original: string; + } + + interface Literal extends Expression {} + interface StringLiteral extends Literal { + value: string; + original: string; + } + + interface BooleanLiteral extends Literal { + value: boolean; + original: boolean; + } + + interface NumberLiteral extends Literal { + value: number; + original: number; + } + + interface UndefinedLiteral extends Literal {} + + interface NullLiteral extends Literal {} + + interface Hash extends Node { + pairs: HashPair[]; + } + + interface HashPair extends Node { + key: string; + value: Expression; + } + + interface StripFlags { + open: boolean; + close: boolean; + } + + interface helpers { + helperExpression(node: Node): boolean; + scopeId(path: PathExpression): boolean; + simpleId(path: PathExpression): boolean; + } + } +} + +declare module "handlebars" { + export = Handlebars; +} diff --git a/samples/handlebarsjs-webpack-loader/typings/globals/handlebars/typings.json b/samples/handlebarsjs-webpack-loader/typings/globals/handlebars/typings.json new file mode 100644 index 000000000..49e3ced3a --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/typings/globals/handlebars/typings.json @@ -0,0 +1,8 @@ +{ + "resolution": "main", + "tree": { + "src": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/90198235019d12c00b3ccca03a36cc3d1579d644/handlebars/index.d.ts", + "raw": "registry:dt/handlebars#4.0.5+20160810231743", + "typings": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/90198235019d12c00b3ccca03a36cc3d1579d644/handlebars/index.d.ts" + } +} diff --git a/samples/handlebarsjs-webpack-loader/typings/index.d.ts b/samples/handlebarsjs-webpack-loader/typings/index.d.ts new file mode 100644 index 000000000..5045c8953 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/typings/index.d.ts @@ -0,0 +1 @@ +/// diff --git a/samples/handlebarsjs-webpack-loader/typings/tsd.d.ts b/samples/handlebarsjs-webpack-loader/typings/tsd.d.ts new file mode 100644 index 000000000..e7efdd728 --- /dev/null +++ b/samples/handlebarsjs-webpack-loader/typings/tsd.d.ts @@ -0,0 +1 @@ +///