Skip to content

Commit

Permalink
#653 - Update Astro script
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Oct 6, 2023
1 parent 2423b73 commit f1d6132
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/constants/SsgScripts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const SsgScripts = {
folder: '/ssg-scripts',
astroContentCollection: 'astro-collections.mjs'
astroContentCollectionScript: 'astro.collections.mjs',
astroContentCollectionJSON: 'astro.collections.json'
};
15 changes: 10 additions & 5 deletions src/listeners/dashboard/SsgListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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();
Expand All @@ -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 });

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { writeFileSync } from "fs";
import { join } from "path";
import { createServer } from "vite";
import zod from "zod";

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f1d6132

Please sign in to comment.