@uni-helper/vite-plugin-uni-pages 0.1.2 → 0.1.3
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/index.cjs +17 -5
- package/dist/index.d.ts +5 -2
- package/dist/index.mjs +17 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -154,10 +154,15 @@ async function parseSFC(code) {
|
|
|
154
154
|
}
|
|
155
155
|
function parseCustomBlock(block, filePath, options) {
|
|
156
156
|
const lang = block.lang ?? options.routeBlockLang;
|
|
157
|
+
const attr = {
|
|
158
|
+
type: "page",
|
|
159
|
+
...block.attrs
|
|
160
|
+
};
|
|
161
|
+
let content;
|
|
157
162
|
debug.routeBlock(`use ${lang} parser`);
|
|
158
163
|
if (lang === "json5") {
|
|
159
164
|
try {
|
|
160
|
-
|
|
165
|
+
content = JSON5.parse(block.content);
|
|
161
166
|
} catch (err) {
|
|
162
167
|
throw new Error(
|
|
163
168
|
`Invalid JSON5 format of <${block.type}> content in ${filePath}
|
|
@@ -166,7 +171,7 @@ ${err.message}`
|
|
|
166
171
|
}
|
|
167
172
|
} else if (lang === "json") {
|
|
168
173
|
try {
|
|
169
|
-
|
|
174
|
+
content = JSON.parse(block.content);
|
|
170
175
|
} catch (err) {
|
|
171
176
|
throw new Error(
|
|
172
177
|
`Invalid JSON format of <${block.type}> content in ${filePath}
|
|
@@ -175,7 +180,7 @@ ${err.message}`
|
|
|
175
180
|
}
|
|
176
181
|
} else if (lang === "yaml" || lang === "yml") {
|
|
177
182
|
try {
|
|
178
|
-
|
|
183
|
+
content = yaml.parse(block.content);
|
|
179
184
|
} catch (err) {
|
|
180
185
|
throw new Error(
|
|
181
186
|
`Invalid YAML format of <${block.type}> content in ${filePath}
|
|
@@ -183,6 +188,12 @@ ${err.message}`
|
|
|
183
188
|
);
|
|
184
189
|
}
|
|
185
190
|
}
|
|
191
|
+
if (content) {
|
|
192
|
+
return {
|
|
193
|
+
attr,
|
|
194
|
+
content
|
|
195
|
+
};
|
|
196
|
+
}
|
|
186
197
|
}
|
|
187
198
|
async function getRouteBlock(path, options) {
|
|
188
199
|
const content = fs.readFileSync(path, "utf8");
|
|
@@ -278,9 +289,9 @@ class PageContext {
|
|
|
278
289
|
const { relativePath, absolutePath } = page;
|
|
279
290
|
const routeBlock = await getRouteBlock(absolutePath, this.options);
|
|
280
291
|
const relativePathWithFileName = relativePath.replace(path.extname(relativePath), "");
|
|
281
|
-
const pageMetaDatum = { path: vite.normalizePath(relativePathWithFileName), type: "page" };
|
|
292
|
+
const pageMetaDatum = { path: vite.normalizePath(relativePathWithFileName), type: routeBlock?.attr.type ?? "page" };
|
|
282
293
|
if (routeBlock)
|
|
283
|
-
Object.assign(pageMetaDatum, routeBlock);
|
|
294
|
+
Object.assign(pageMetaDatum, routeBlock.content);
|
|
284
295
|
return pageMetaDatum;
|
|
285
296
|
}
|
|
286
297
|
async mergePageMetaData() {
|
|
@@ -296,6 +307,7 @@ class PageContext {
|
|
|
296
307
|
else
|
|
297
308
|
this.pageMetaData = generatedPageMetaData;
|
|
298
309
|
}
|
|
310
|
+
this.pageMetaData.sort((page) => page.type === "home" ? -1 : 0);
|
|
299
311
|
debug.pages(generatedPageMetaData);
|
|
300
312
|
}
|
|
301
313
|
async updatePagesJSON() {
|
package/dist/index.d.ts
CHANGED
|
@@ -633,7 +633,10 @@ declare class PageContext {
|
|
|
633
633
|
resolveRoutes(): string;
|
|
634
634
|
}
|
|
635
635
|
|
|
636
|
-
|
|
636
|
+
interface CustomBlock {
|
|
637
|
+
attr: Record<string, any>;
|
|
638
|
+
content: Record<string, any>;
|
|
639
|
+
}
|
|
637
640
|
interface Options {
|
|
638
641
|
/**
|
|
639
642
|
* Whether to merge pages in pages.json
|
|
@@ -735,7 +738,7 @@ declare function resolveOptions(userOptions: UserOptions, viteRoot?: string): Re
|
|
|
735
738
|
declare function resolvePageDirs(dir: string, root: string, exclude: string[]): string[];
|
|
736
739
|
|
|
737
740
|
declare function parseSFC(code: string): Promise<SFCDescriptor>;
|
|
738
|
-
declare function parseCustomBlock(block: SFCBlock, filePath: string, options: ResolvedOptions):
|
|
741
|
+
declare function parseCustomBlock(block: SFCBlock, filePath: string, options: ResolvedOptions): CustomBlock | undefined;
|
|
739
742
|
declare function getRouteBlock(path: string, options: ResolvedOptions): Promise<CustomBlock | undefined>;
|
|
740
743
|
|
|
741
744
|
declare const VitePluginUniPages: (userOptions?: UserOptions) => Plugin;
|
package/dist/index.mjs
CHANGED
|
@@ -150,10 +150,15 @@ async function parseSFC(code) {
|
|
|
150
150
|
}
|
|
151
151
|
function parseCustomBlock(block, filePath, options) {
|
|
152
152
|
const lang = block.lang ?? options.routeBlockLang;
|
|
153
|
+
const attr = {
|
|
154
|
+
type: "page",
|
|
155
|
+
...block.attrs
|
|
156
|
+
};
|
|
157
|
+
let content;
|
|
153
158
|
debug.routeBlock(`use ${lang} parser`);
|
|
154
159
|
if (lang === "json5") {
|
|
155
160
|
try {
|
|
156
|
-
|
|
161
|
+
content = JSON5.parse(block.content);
|
|
157
162
|
} catch (err) {
|
|
158
163
|
throw new Error(
|
|
159
164
|
`Invalid JSON5 format of <${block.type}> content in ${filePath}
|
|
@@ -162,7 +167,7 @@ ${err.message}`
|
|
|
162
167
|
}
|
|
163
168
|
} else if (lang === "json") {
|
|
164
169
|
try {
|
|
165
|
-
|
|
170
|
+
content = JSON.parse(block.content);
|
|
166
171
|
} catch (err) {
|
|
167
172
|
throw new Error(
|
|
168
173
|
`Invalid JSON format of <${block.type}> content in ${filePath}
|
|
@@ -171,7 +176,7 @@ ${err.message}`
|
|
|
171
176
|
}
|
|
172
177
|
} else if (lang === "yaml" || lang === "yml") {
|
|
173
178
|
try {
|
|
174
|
-
|
|
179
|
+
content = parse$1(block.content);
|
|
175
180
|
} catch (err) {
|
|
176
181
|
throw new Error(
|
|
177
182
|
`Invalid YAML format of <${block.type}> content in ${filePath}
|
|
@@ -179,6 +184,12 @@ ${err.message}`
|
|
|
179
184
|
);
|
|
180
185
|
}
|
|
181
186
|
}
|
|
187
|
+
if (content) {
|
|
188
|
+
return {
|
|
189
|
+
attr,
|
|
190
|
+
content
|
|
191
|
+
};
|
|
192
|
+
}
|
|
182
193
|
}
|
|
183
194
|
async function getRouteBlock(path, options) {
|
|
184
195
|
const content = fs.readFileSync(path, "utf8");
|
|
@@ -274,9 +285,9 @@ class PageContext {
|
|
|
274
285
|
const { relativePath, absolutePath } = page;
|
|
275
286
|
const routeBlock = await getRouteBlock(absolutePath, this.options);
|
|
276
287
|
const relativePathWithFileName = relativePath.replace(path.extname(relativePath), "");
|
|
277
|
-
const pageMetaDatum = { path: normalizePath(relativePathWithFileName), type: "page" };
|
|
288
|
+
const pageMetaDatum = { path: normalizePath(relativePathWithFileName), type: routeBlock?.attr.type ?? "page" };
|
|
278
289
|
if (routeBlock)
|
|
279
|
-
Object.assign(pageMetaDatum, routeBlock);
|
|
290
|
+
Object.assign(pageMetaDatum, routeBlock.content);
|
|
280
291
|
return pageMetaDatum;
|
|
281
292
|
}
|
|
282
293
|
async mergePageMetaData() {
|
|
@@ -292,6 +303,7 @@ class PageContext {
|
|
|
292
303
|
else
|
|
293
304
|
this.pageMetaData = generatedPageMetaData;
|
|
294
305
|
}
|
|
306
|
+
this.pageMetaData.sort((page) => page.type === "home" ? -1 : 0);
|
|
295
307
|
debug.pages(generatedPageMetaData);
|
|
296
308
|
}
|
|
297
309
|
async updatePagesJSON() {
|
package/package.json
CHANGED