Skip to content

Commit

Permalink
chore: run format fix on tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
dcshzj committed Aug 12, 2024
1 parent 2e49116 commit d2a6419
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 122 deletions.
30 changes: 15 additions & 15 deletions tooling/build/amplify/create-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const {
CreateAppCommand,
CreateBranchCommand,
StartJobCommand,
} = require("@aws-sdk/client-amplify");
} = require("@aws-sdk/client-amplify")

const AMPLIFY_BUILD_SPEC = `
version: 1
Expand All @@ -24,13 +24,13 @@ frontend:
# paths:
# - .next/cache/**/*
# - node_modules/**/*
`;
`

const amplifyClient = new AmplifyClient({ region: "ap-southeast-1" });
const amplifyClient = new AmplifyClient({ region: "ap-southeast-1" })

const createApp = async (appName) => {
console.log("Creating app:", appName);
let appId = "";
console.log("Creating app:", appName)
let appId = ""

const params = new CreateAppCommand({
name: appName,
Expand All @@ -41,12 +41,12 @@ const createApp = async (appName) => {
NEXT_PUBLIC_ISOMER_NEXT_ENVIRONMENT: "staging",
},
customRules: [{ source: "/<*>", target: "/404.html", status: "404" }],
});
})

await amplifyClient
.send(params)
.then((appInfo) => {
appId = appInfo.app?.appId;
appId = appInfo.app?.appId

const mainBranchParams = new CreateBranchCommand({
appId,
Expand All @@ -56,9 +56,9 @@ const createApp = async (appName) => {
environmentVariables: {
NEXT_PUBLIC_ISOMER_NEXT_ENVIRONMENT: "production",
},
});
})

return amplifyClient.send(mainBranchParams);
return amplifyClient.send(mainBranchParams)
})
.then(() =>
amplifyClient.send(
Expand Down Expand Up @@ -87,8 +87,8 @@ const createApp = async (appName) => {
jobType: "RELEASE",
}),
),
);
};
)
}

const main = async () => {
const apps = [
Expand All @@ -99,11 +99,11 @@ const main = async () => {
"moh-biosafety-next",
"moh-dc-next",
"moh-prepare-next",
];
]

for (const app of apps) {
await createApp(app);
await createApp(app)
}
};
}

main();
main()
54 changes: 27 additions & 27 deletions tooling/build/scripts/generate-search-index.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
const fs = require("fs");
const path = require("path");
const fs = require("fs")
const path = require("path")

const schemaDirectory = path.join(__dirname, "../schema");
let finalIndex = [];
let indexId = 0; // Counter for the running order of each index's record
const schemaDirectory = path.join(__dirname, "../schema")
let finalIndex = []
let indexId = 0 // Counter for the running order of each index's record

function decodeAndStripMarkdown(base64Content) {
const decodedContent = Buffer.from(base64Content, "base64").toString("utf-8");
const decodedContent = Buffer.from(base64Content, "base64").toString("utf-8")
const strippedContent = decodedContent
.replace(/!\[[^\]]*\]\([^\)]+\)/g, "") // Remove images
.replace(/\[[^\]]+\]\([^\)]+\)/g, "") // Remove links
.replace(/[*_~`>#-]+/g, "") // Remove styling characters
.replace(/\n+/g, " "); // Replace newlines with spaces
return strippedContent;
.replace(/\n+/g, " ") // Replace newlines with spaces
return strippedContent
}

function extractIndexableContent(schemaContent) {
const parsedContent = JSON.parse(schemaContent);
const parsedContent = JSON.parse(schemaContent)
const indexableObject = {
id: indexId.toString(), // Assign the current indexId as a string
title: "",
content: "",
url: parsedContent.permalink || "", // Assign URL from permalink
};
}

if (parsedContent.title) {
indexableObject.title = parsedContent.title;
indexableObject.title = parsedContent.title
}

parsedContent.components?.forEach((component) => {
component.indexable?.forEach((fieldPath) => {
if (fieldPath === "props.markdown") {
const decodedStrippedContent = decodeAndStripMarkdown(
component.props.markdown,
);
indexableObject.content += decodedStrippedContent + " ";
)
indexableObject.content += decodedStrippedContent + " "
}
});
});
})
})

indexableObject.content = indexableObject.content.trim();
indexableObject.content = indexableObject.content.trim()

indexId++; // Increment the counter after adding each record
return indexableObject;
indexId++ // Increment the counter after adding each record
return indexableObject
}

function readSchemaFiles(directory) {
fs.readdirSync(directory).forEach((file) => {
const fullPath = path.join(directory, file);
const fullPath = path.join(directory, file)
if (fs.statSync(fullPath).isDirectory()) {
readSchemaFiles(fullPath);
readSchemaFiles(fullPath)
} else if (file === "schema.json") {
const schemaContent = fs.readFileSync(fullPath, "utf-8");
const indexableObject = extractIndexableContent(schemaContent);
finalIndex.push(indexableObject);
const schemaContent = fs.readFileSync(fullPath, "utf-8")
const indexableObject = extractIndexableContent(schemaContent)
finalIndex.push(indexableObject)
}
});
})
}

readSchemaFiles(schemaDirectory);
readSchemaFiles(schemaDirectory)

fs.writeFileSync(
path.join(__dirname, "../searchIndex.json"),
JSON.stringify(finalIndex, null, 2),
);
console.log("Search index created successfully!");
)
console.log("Search index created successfully!")
Loading

0 comments on commit d2a6419

Please sign in to comment.