Skip to content

Commit 2face02

Browse files
fix: favicon linking logic
1 parent f11b8df commit 2face02

File tree

10 files changed

+102
-17
lines changed

10 files changed

+102
-17
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"@nguniversal/express-engine": "^6.0.0",
7575
"@types/cookie-parser": "^1.4.1",
7676
"@types/express": "^4.16.0",
77+
"@types/fs-extra": "^5.0.4",
7778
"@types/jest": "^23.1.6",
7879
"@types/lru-cache": "^4.1.1",
7980
"@types/node": "^10.5.2",
@@ -89,6 +90,7 @@
8990
"express": "^4.16.3",
9091
"favicons": "^5.1.1",
9192
"firebase": "^5.2.0",
93+
"fs-extra": "^6.0.1",
9294
"fuse-box": "^3.4.0",
9395
"hammerjs": "^2.0.8",
9496
"iltorb": "^2.3.2",

src/commands/create.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ function create(overwriteExisting = false) {
316316
flatMap(toEnsureProjectDirectoryExists, im => im),
317317
flatMap(im => {
318318
const path = resolve(im.config.fullname)
319+
const faviOverrides = {
320+
appName: im.config.fullname,
321+
appShortName: im.config.shortname
322+
}
319323
const firebaseConfig: FirebaseConfig | undefined = im.config.firebase
320324
? {
321325
apiKey: im.config.firebaseApiKey,
@@ -340,7 +344,7 @@ function create(overwriteExisting = false) {
340344
im.config.googleAnalyticsTrackingId,
341345
im.config.googleSiteVerificationCode
342346
),
343-
generateFngConfig(path, overwriteExisting),
347+
generateFngConfig(path, overwriteExisting, faviOverrides),
344348
generateTsConfig(path, overwriteExisting),
345349
generateTsDeclartionFile(path, overwriteExisting),
346350
im.config.ide

src/commands/favicon.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { command } from 'yargs'
22
import { logInfoWithBackground, logError } from '../utilities/log'
33
import { flatMap, map, first, filter, tap } from 'rxjs/operators'
44
import { rxFavicons } from '../utilities/rx-favicon'
5-
import { writeFile_, mkDirDeep_ } from '../utilities/rx-fs'
5+
import { writeFile_, mkDirDeep_, writeJsonFile_ } from '../utilities/rx-fs'
66
import { resolve } from 'path'
77
import { forkJoin } from 'rxjs'
88
import readConfig_, {
@@ -52,8 +52,32 @@ interface configModel {
5252
}
5353

5454
function mapResponsesToWriteableObservables(response: configModel) {
55-
return response.result.images.map(file =>
56-
writeFile_(resolve(`${response.config.output}/${file.name}`), file.contents)
55+
return readConfig_().pipe(
56+
flatMap(config => {
57+
const _confg = {
58+
...config,
59+
generatedMetaTags: response.result.html
60+
}
61+
return writeJsonFile_(resolve('fusing-angular.json'), _confg, true)
62+
}),
63+
flatMap(() => {
64+
return forkJoin(
65+
...response.result.files.map(file =>
66+
writeFile_(
67+
resolve(`${response.config.output}/${file.name}`),
68+
file.contents
69+
)
70+
)
71+
)
72+
}),
73+
map(() => {
74+
return response.result.images.map(file =>
75+
writeFile_(
76+
resolve(`${response.config.output}/${file.name}`),
77+
file.contents
78+
)
79+
)
80+
})
5781
)
5882
}
5983

src/commands/serve.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { exec, execSync } from 'child_process'
2424
import { NgSwPlugin } from '../fusebox/ng.sw.plugin'
2525
import clearTerminal from '../utilities/clear'
2626
import readConfig_ from '../utilities/read-config'
27+
import { copy } from 'fs-extra'
2728

2829
command(
2930
'serve [port][prod][aot][sw]',
@@ -95,7 +96,8 @@ function serve(isProdBuild = false, isServiceWorkerEnabled = false) {
9596
engine: 'pug',
9697
locals: {
9798
pageTitle: 'FUSING ANGULAR',
98-
isLocalDev
99+
isLocalDev,
100+
faviconMeta: (config.generatedMetaTags || []).join('\n')
99101
}
100102
}),
101103
NgProdPlugin({ enabled: isProdBuild }),
@@ -223,8 +225,10 @@ function serve(isProdBuild = false, isServiceWorkerEnabled = false) {
223225
process.exit(1)
224226
})
225227

226-
fuseSw.run().then(() => {
227-
fuseBrowser.run({ chokidar: { ignored: /^(.*\.scss$)*$/gim } })
228-
})
228+
copy(resolve('src/assets'), resolve('.dist/public/assets'))
229+
.then(() => fuseSw.run())
230+
.then(() => {
231+
fuseBrowser.run({ chokidar: { ignored: /^(.*\.scss$)*$/gim } })
232+
})
229233
})
230234
}

src/generators/config.gen.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ import { FUSEBOX_DEFAULTS as fusebox } from '../templates/fusebox'
55

66
const configPath = 'fusing-angular.json'
77

8-
export default function generateFngConfig(path: string, overwrite = false) {
8+
export default function generateFngConfig(
9+
path: string,
10+
overwrite = false,
11+
faviconOverride?: any
12+
) {
913
return writeJsonFile_(
1014
resolve(path, configPath),
1115
{
12-
favicon,
16+
favicon: {
17+
...favicon,
18+
...faviconOverride
19+
},
1320
fusebox
1421
},
1522
overwrite

src/templates/core/app/index.pug.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ html(lang="en")
55
base(href="/")
66
meta(charset="utf-8")
77
meta(name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0")
8+
!= faviconMeta
89
body
910
app-root
1011
| $bundles

src/templates/favicon.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
export const FAVICON_DEFAULTS = {
2-
source: 'src/misc/logo.svg',
2+
source: 'src/app/favicon.svg',
33
output: 'src/assets/favicons',
4-
config: {}
4+
config: {
5+
path: '/',
6+
appName: null,
7+
appDescription: null,
8+
developerName: null,
9+
developerURL: null,
10+
lang: 'en-US',
11+
background: '#fff',
12+
theme_color: '#fff',
13+
display: 'standalone',
14+
orientation: 'any',
15+
start_url: '/'
16+
}
517
}

src/utilities/read-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export interface FusingAngularConfig {
4242
readonly favicon: FaviconConfig
4343
readonly fusebox: FuseBoxConfig
4444
readonly environment: EnvironmentConfig
45+
readonly generatedMetaTags?: ReadonlyArray<string>
4546
}
4647

4748
export default function readConfig_() {

src/utilities/rx-favicon.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ function callback(config: FaviconConfig) {
1616
export function rxFavicons(config?: FaviconConfig) {
1717
const _config = {
1818
source: resolve('src/misc/logo.svg'),
19-
configuration: {},
19+
configuration: {
20+
path: '/assets/favicons'
21+
},
2022
...config
2123
} as FaviconConfig
2224

0 commit comments

Comments
 (0)