@unvt/charites 2.1.4 → 2.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/serve.js +22 -1
- package/package.json +1 -1
- package/src/commands/serve.ts +21 -1
package/dist/commands/serve.js
CHANGED
|
@@ -67,7 +67,28 @@ export async function serve(source, options) {
|
|
|
67
67
|
try {
|
|
68
68
|
style = parser(sourcePath);
|
|
69
69
|
if (typeof spriteOut !== 'undefined') {
|
|
70
|
-
|
|
70
|
+
const spriteUrl = `http://${req.headers.host || `localhost:${port}`}/sprite`;
|
|
71
|
+
if (typeof style.sprite === 'string') {
|
|
72
|
+
// update a single sprite URL
|
|
73
|
+
style.sprite = spriteUrl;
|
|
74
|
+
}
|
|
75
|
+
else if (Array.isArray(style.sprite)) {
|
|
76
|
+
// if sprite is an array, update default sprite URL.
|
|
77
|
+
// if default sprite is not found, add default url.
|
|
78
|
+
if (style.sprite.find((s) => s.id === 'default')) {
|
|
79
|
+
for (const s of style.sprite) {
|
|
80
|
+
if (s.id === 'default') {
|
|
81
|
+
s.url = spriteUrl;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
style.sprite.push({
|
|
87
|
+
id: 'default',
|
|
88
|
+
url: spriteUrl,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
71
92
|
}
|
|
72
93
|
validateStyle(style);
|
|
73
94
|
}
|
package/package.json
CHANGED
package/src/commands/serve.ts
CHANGED
|
@@ -87,9 +87,29 @@ export async function serve(source: string, options: serveOptions) {
|
|
|
87
87
|
try {
|
|
88
88
|
style = parser(sourcePath)
|
|
89
89
|
if (typeof spriteOut !== 'undefined') {
|
|
90
|
-
|
|
90
|
+
const spriteUrl = `http://${
|
|
91
91
|
req.headers.host || `localhost:${port}`
|
|
92
92
|
}/sprite`
|
|
93
|
+
|
|
94
|
+
if (typeof style.sprite === 'string') {
|
|
95
|
+
// update a single sprite URL
|
|
96
|
+
style.sprite = spriteUrl
|
|
97
|
+
} else if (Array.isArray(style.sprite)) {
|
|
98
|
+
// if sprite is an array, update default sprite URL.
|
|
99
|
+
// if default sprite is not found, add default url.
|
|
100
|
+
if (style.sprite.find((s) => s.id === 'default')) {
|
|
101
|
+
for (const s of style.sprite) {
|
|
102
|
+
if (s.id === 'default') {
|
|
103
|
+
s.url = spriteUrl
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
style.sprite.push({
|
|
108
|
+
id: 'default',
|
|
109
|
+
url: spriteUrl,
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
}
|
|
93
113
|
}
|
|
94
114
|
validateStyle(style)
|
|
95
115
|
} catch (error) {
|