update project setup script
This commit is contained in:
parent
fe5cdce6d7
commit
0f938e5c16
@ -1,6 +1,33 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const toggleComment = ({ filepath, regex }) => {
|
||||
let updatedContent = fs.readFileSync(filepath, "utf8");
|
||||
const match = updatedContent.match(regex);
|
||||
|
||||
if (match) {
|
||||
const matchedContent = match[0];
|
||||
const hasComment = matchedContent.startsWith("# ");
|
||||
if (hasComment) {
|
||||
updatedContent = updatedContent.replace(
|
||||
regex,
|
||||
matchedContent.replace("# ", "")
|
||||
);
|
||||
fs.writeFileSync(filepath, updatedContent, "utf8");
|
||||
} else {
|
||||
const hasBreakline = matchedContent.includes("\n");
|
||||
if (hasBreakline) {
|
||||
const content = matchedContent
|
||||
.split("\n")
|
||||
.map((line) => "# " + line)
|
||||
.join("\n");
|
||||
updatedContent = updatedContent.replace(regex, content);
|
||||
fs.writeFileSync(filepath, updatedContent, "utf8");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const getFolderName = (rootfolder) => {
|
||||
const configPath = path.join(rootfolder, "exampleSite/hugo.toml");
|
||||
const getConfig = fs.readFileSync(configPath, "utf8");
|
||||
@ -45,6 +72,21 @@ const iterateFilesAndFolders = (rootFolder, { destinationRoot }) => {
|
||||
const setupProject = () => {
|
||||
const rootfolder = path.join(__dirname, "../");
|
||||
if (!fs.existsSync(path.join(rootfolder, "themes"))) {
|
||||
// remove this part if you don't using theme demo as a module
|
||||
[
|
||||
{
|
||||
filepath: path.join(rootfolder, "exampleSite/hugo.toml"),
|
||||
regex: /^.*theme\s*=\s*("[^"\]]+"|\S+)/m,
|
||||
},
|
||||
{
|
||||
filepath: path.join(
|
||||
rootfolder,
|
||||
"exampleSite/config/_default/module.toml"
|
||||
),
|
||||
regex: /\[\[imports\]\]\s*\r?\npath = "([^"]+)"/,
|
||||
},
|
||||
].forEach(toggleComment);
|
||||
|
||||
const folderList = ["layouts", "assets", "static"];
|
||||
const folderName = getFolderName(rootfolder);
|
||||
const newfolderName = createNewfolder(
|
||||
|
@ -1,6 +1,29 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const toggleComment = ({ filepath, regex }) => {
|
||||
let updatedContent = fs.readFileSync(filepath, "utf8");
|
||||
const match = updatedContent.match(regex);
|
||||
|
||||
if (match) {
|
||||
const matchedContent = match[0];
|
||||
const hasComment = matchedContent.startsWith("# ");
|
||||
if (hasComment) {
|
||||
const hasBreakline = matchedContent.includes("\n");
|
||||
if (hasBreakline) {
|
||||
updatedContent = updatedContent.replace(
|
||||
regex,
|
||||
matchedContent.replace(/# /gm, "")
|
||||
);
|
||||
fs.writeFileSync(filepath, updatedContent, "utf8");
|
||||
}
|
||||
} else {
|
||||
updatedContent = updatedContent.replace(regex, "# " + matchedContent);
|
||||
fs.writeFileSync(filepath, updatedContent, "utf8");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const createNewfolder = (rootfolder, folderName) => {
|
||||
const newFolder = path.join(rootfolder, folderName);
|
||||
fs.mkdirSync(newFolder, { recursive: true });
|
||||
@ -46,6 +69,18 @@ const setupTheme = () => {
|
||||
const rootFolder = path.join(__dirname, "../");
|
||||
|
||||
if (!fs.existsSync(path.join(rootFolder, "exampleSite"))) {
|
||||
// remove this part if you don't using theme demo as a module
|
||||
[
|
||||
{
|
||||
filepath: path.join(rootFolder, "config/_default/module.toml"),
|
||||
regex: /# \[\[imports\]\]\s*\r?\n# path = "([^"]+)"/,
|
||||
},
|
||||
{
|
||||
filepath: path.join(rootFolder, "hugo.toml"),
|
||||
regex: /^.*theme\s*=\s*("[^"\]]+"|\S+)/m,
|
||||
},
|
||||
].forEach(toggleComment);
|
||||
|
||||
const includesFiles = [
|
||||
"tailwind.config.js",
|
||||
"postcss.config.js",
|
||||
|
Loading…
Reference in New Issue
Block a user