Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add inline step for templateUrl #831

Merged
merged 1 commit into from
Dec 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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