mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-07-04 08:51:05 +02:00
#653 - Update Astro script
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
export const SsgScripts = {
|
||||
folder: '/ssg-scripts',
|
||||
astroContentCollection: 'astro-collections.mjs'
|
||||
astroContentCollectionScript: 'astro.collections.mjs',
|
||||
astroContentCollectionJSON: 'astro.collections.json'
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Folders } from '../../commands';
|
||||
import { SETTING_TAXONOMY_CONTENT_TYPES, SsgScripts } from '../../constants';
|
||||
import { SettingsListener } from './SettingsListener';
|
||||
import { Terminal } from '../../services';
|
||||
import { existsAsync, readFileAsync } from '../../utils';
|
||||
|
||||
export class SsgListener extends BaseListener {
|
||||
/**
|
||||
@@ -120,7 +121,7 @@ export class SsgListener extends BaseListener {
|
||||
const scriptPath = Uri.joinPath(
|
||||
Extension.getInstance().extensionPath,
|
||||
SsgScripts.folder,
|
||||
SsgScripts.astroContentCollection
|
||||
SsgScripts.astroContentCollectionScript
|
||||
);
|
||||
|
||||
const wsFolder = Folders.getWorkspaceFolder();
|
||||
@@ -130,7 +131,7 @@ export class SsgListener extends BaseListener {
|
||||
}
|
||||
|
||||
const tempLocation = Uri.joinPath(wsFolder, '/.frontmatter/temp');
|
||||
const tempScriptPath = Uri.joinPath(tempLocation, SsgScripts.astroContentCollection);
|
||||
const tempScriptPath = Uri.joinPath(tempLocation, SsgScripts.astroContentCollectionScript);
|
||||
await workspace.fs.createDirectory(tempLocation);
|
||||
workspace.fs.copy(scriptPath, tempScriptPath, { overwrite: true });
|
||||
|
||||
@@ -139,9 +140,13 @@ export class SsgListener extends BaseListener {
|
||||
try {
|
||||
const result: string = await SsgListener.executeScript(fullScript, wsFolder?.fsPath || '');
|
||||
if (result) {
|
||||
let collections: AstroCollection[] = JSON.parse(result);
|
||||
collections = collections.filter((c) => c.type === 'content');
|
||||
SsgListener.sendRequest(command as any, requestId, collections);
|
||||
const tempJsonPath = Uri.joinPath(tempLocation, SsgScripts.astroContentCollectionJSON);
|
||||
if (await existsAsync(tempJsonPath.fsPath)) {
|
||||
const contents = await readFileAsync(tempJsonPath.fsPath, 'utf8');
|
||||
let collections: AstroCollection[] = JSON.parse(contents);
|
||||
collections = collections.filter((c) => c.type === 'content');
|
||||
SsgListener.sendRequest(command as any, requestId, collections);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.error((error as Error).message);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { writeFileSync } from "fs";
|
||||
import { join } from "path";
|
||||
import { createServer } from "vite";
|
||||
import zod from "zod";
|
||||
|
||||
@@ -206,7 +208,9 @@ const astroContentModulePlugin = () => {
|
||||
const collections = Object.entries(contentModule.collections ?? {});
|
||||
const processedCollections = processCollection(collections);
|
||||
|
||||
console.log(JSON.stringify(processedCollections));
|
||||
writeFileSync(join(process.cwd(), `./.frontmatter/temp/astro.collections.json`), JSON.stringify(processedCollections));
|
||||
|
||||
console.log("Collections generated successfully");
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.log(error.message);
|
||||
Reference in New Issue
Block a user