Skip to content

Commit

Permalink
build: add inline step for templateUrl (NG-ZORRO#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
trotyl authored and wilsoncook committed Dec 30, 2017
1 parent 3d29366 commit 78911f9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ readonly currentDir=$(cd $(dirname $0); pwd)
cd ${currentDir}
rm -rf publish
cp -r src/components src/__gen_components
node ./inline-template.js
node ./less.convert.js

echo 'Compiling to es2015 via Angular compiler'
Expand Down
30 changes: 30 additions & 0 deletions inline-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const fs = require('fs')
const path = require('path')
const glob = require('glob').sync

function inlineResourcesForDirectory(folderPath) {
glob(path.join(folderPath, '**/*.ts')).forEach(filePath => inlineResources(filePath))
}

function inlineResources(filePath) {
let fileContent = fs.readFileSync(filePath, 'utf-8')

fileContent = inlineTemplate(fileContent, filePath)

fs.writeFileSync(filePath, fileContent, 'utf-8')
}

function inlineTemplate(fileContent, filePath) {
return fileContent.replace(/templateUrl\s*:\s*'([^']+?\.html)'/g, (_match, templateUrl) => {
const templatePath = path.join(path.dirname(filePath), templateUrl)
const templateContent = loadResourceFile(templatePath)
return `template: \`${templateContent}\``
})
}

function loadResourceFile(filePath) {
return fs.readFileSync(filePath, 'utf-8')
.replace(/([\n\r]\s*)+/gm, ' ')
}

inlineResourcesForDirectory('./src/__gen_components')
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"codelyzer": "~4.0.1",
"core-js": "^2.4.1",
"coveralls": "^2.13.1",
"glob": "^7.1.2",
"highlight.js": "^9.12.0",
"intl": "^1.2.5",
"jasmine-core": "~2.6.2",
Expand Down
2 changes: 2 additions & 0 deletions src/components/button/nz-button.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<i class="anticon anticon-spin anticon-loading" *ngIf="nzLoading"></i>
<ng-content></ng-content>
5 changes: 1 addition & 4 deletions src/components/button/nz-button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ export type NzButtonSize = 'small' | 'large' | 'default' ;
@Component({
selector : '[nz-button]',
encapsulation: ViewEncapsulation.None,
template : `
<i class="anticon anticon-spin anticon-loading" *ngIf="nzLoading"></i>
<ng-content></ng-content>
`,
templateUrl : './nz-button.component.html',
styleUrls : [
'./style/index.less'
]
Expand Down

0 comments on commit 78911f9

Please sign in to comment.