Skip to content

Commit d4976a8

Browse files
fix: component based layout added for css, html templates (#20)
1 parent c40d2ea commit d4976a8

File tree

15 files changed

+165
-9
lines changed

15 files changed

+165
-9
lines changed

package-lock.json

Lines changed: 46 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"favicons": "^5.1.1",
7676
"fuse-box": "^3.3.0",
7777
"inquirer": "^6.0.0",
78+
"ng2-fused": "^0.5.1",
7879
"npm": "^6.1.0",
7980
"rxjs": "^6.2.1",
8081
"ts-node": "^6.1.2",

src/commands/serve.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import { command } from 'yargs'
22
import { take, tap } from 'rxjs/operators'
33
import { logInfo } from '../utilities/log'
4-
import { FuseBox, JSONPlugin, QuantumPlugin } from 'fuse-box'
4+
import {
5+
FuseBox,
6+
JSONPlugin,
7+
QuantumPlugin,
8+
RawPlugin,
9+
SassPlugin
10+
} from 'fuse-box'
511
import { resolve } from 'path'
612
import { NgProdPlugin } from '../fusebox/ng.prod.plugin'
713
import { NgPolyfillPlugin } from '../fusebox/ng.polyfill.plugin'
814
import { NgCompilerPlugin } from '../fusebox/ng.compiler.plugin'
915
import readConfig_ from '../utilities/read-config'
16+
import { Ng2TemplatePlugin } from 'ng2-fused'
1017

1118
command(
1219
'serve [port][prod][aot][sw]',
@@ -63,10 +70,22 @@ function serve(isProdBuild = false) {
6370
target: 'browser@es5',
6471
useTypescriptCompiler: true,
6572
plugins: [
73+
Ng2TemplatePlugin(),
74+
['*.component.html', RawPlugin()],
6675
NgProdPlugin({ enabled: isProdBuild }),
6776
NgCompilerPlugin({ enabled: isAotBuild }),
6877
NgPolyfillPlugin(),
6978
// NgOptimizerPlugin({ enabled: opts.enableAngularBuildOptimizer }),
79+
[
80+
'*.component.css',
81+
SassPlugin({
82+
indentedSyntax: false,
83+
importer: true,
84+
sourceMap: false,
85+
outputStyle: 'compressed'
86+
} as any),
87+
RawPlugin()
88+
],
7089
isProdBuild &&
7190
QuantumPlugin({
7291
warnings: false,
@@ -89,6 +108,18 @@ function serve(isProdBuild = false) {
89108
output: `${serverOutput}/$name.js`,
90109
plugins: [
91110
JSONPlugin(),
111+
Ng2TemplatePlugin(),
112+
['*.component.html', RawPlugin()],
113+
[
114+
'*.component.css',
115+
SassPlugin({
116+
indentedSyntax: false,
117+
importer: true,
118+
sourceMap: false,
119+
outputStyle: 'compressed'
120+
} as any),
121+
RawPlugin()
122+
],
92123
NgProdPlugin({
93124
enabled: true,
94125
fileTest: 'server.angular.module.ts'

src/generators/angular-core.gen.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import {
22
appModuleTemplate,
33
appComponentTemplate,
44
appRoutingModuleTemplate,
5-
appSharedModuleTemplate
5+
appSharedModuleTemplate,
6+
appComponentCssTemplate,
7+
appComponentHtmlTemplate
68
} from '../templates/core/app'
79
import { writeFile_, mkDirAndContinueIfExists_ } from '../utilities/rx-fs'
810
import { forkJoin } from 'rxjs'
@@ -53,8 +55,22 @@ export function generateCoreAngularApp(projectDir: string, universal = true) {
5355
`${baseDir}/app.routing.module.ts`,
5456
appRoutingModuleTemplate
5557
),
56-
writeFile_(`${baseDir}/app.component.ts`, appComponentTemplate)
58+
writeFile_(`${baseDir}/app.component.ts`, appComponentTemplate),
59+
writeFile_(`${baseDir}/app.component.css`, appComponentCssTemplate), // TODO: write component generator function instead
60+
writeFile_(`${baseDir}/app.component.html`, appComponentHtmlTemplate)
5761
])
62+
),
63+
flatMap(() =>
64+
mkDirAndContinueIfExists_(resolve(baseDir, 'home')).pipe(
65+
flatMap(() =>
66+
forkJoin([
67+
// writeFile_(
68+
// `${baseDir}/home/home.component.ts`,
69+
// homeComponentTemplate
70+
// )
71+
])
72+
)
73+
)
5874
)
5975
)
6076
}

src/templates/component/component.ts.txt

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:host {
2+
display: block;
3+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h1>Your New Angular App</h1>
2+
<router-outlet></router-outlet>

src/templates/core/app/app.component.ts.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { Component, ChangeDetectionStrategy } from '@angular/core'
22

33
@Component({
44
selector: 'app-root',
5-
template: `<router-outlet></router-outlet>`,
5+
templateUrl: './app.component.html',
6+
styleUrls: ['./app.component.css'],
67
changeDetection: ChangeDetectionStrategy.OnPush
78
})
89
export class AppComponent {

src/templates/core/app/app.routing.module.ts.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { NgModule } from '@angular/core'
22
import { RouterModule, Routes } from '@angular/router'
33

4+
//export function homeModule() {
5+
// return import('./home/home.module').then(m => m.HomeModule)
6+
//}
7+
48
export const routes: Routes = [
9+
// { path: '', loadChildren: homeModule },
510
]
611

712
@NgModule({
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Component, ChangeDetectionStrategy } from '@angular/core'
2+
3+
@Component({
4+
selector: 'ng-home',
5+
template: `HOME COMPONENT`,
6+
changeDetection: ChangeDetectionStrategy.OnPush
7+
})
8+
export class HomeComponent {
9+
}

0 commit comments

Comments
 (0)