added project-setup script

This commit is contained in:
somrat sorkar 2023-07-05 15:19:52 +06:00
parent dd723881c8
commit 8bc0dd868f
19 changed files with 251 additions and 259 deletions

View File

@ -16,8 +16,8 @@ permissions:
# Environment variables available to all jobs and steps in this workflow # Environment variables available to all jobs and steps in this workflow
env: env:
HUGO_ENV: production HUGO_ENV: production
HUGO_VERSION: "0.114.0" HUGO_VERSION: "0.115.1"
GO_VERSION: "1.16.3" GO_VERSION: "1.20.5"
NODE_VERSION: "18.15.0" NODE_VERSION: "18.15.0"
TINA_CLIENT_ID: ${{ vars.TINA_CLIENT_ID }} TINA_CLIENT_ID: ${{ vars.TINA_CLIENT_ID }}
TINA_TOKEN: ${{ vars.TINA_TOKEN }} TINA_TOKEN: ${{ vars.TINA_TOKEN }}
@ -49,6 +49,9 @@ jobs:
rm go${{ env.GO_VERSION }}.linux-amd64.tar.gz rm go${{ env.GO_VERSION }}.linux-amd64.tar.gz
go version go version
- name: Setup Project
run: npm run project-setup
- name: Install npm dependencies - name: Install npm dependencies
run: npm install run: npm install
@ -58,7 +61,7 @@ jobs:
- name: Upload artifact - name: Upload artifact
uses: actions/upload-pages-artifact@v1 uses: actions/upload-pages-artifact@v1
with: with:
path: ./exampleSite/public path: ./public
# Deployment job # Deployment job
deploy: deploy:

View File

@ -3,9 +3,9 @@ stages:
variables: variables:
HUGO_ENV: production HUGO_ENV: production
HUGO_VERSION: "0.114.0" HUGO_VERSION: "0.115.1"
GO_VERSION: "1.16.3" GO_VERSION: "1.20.5"
NODE_VERSION: "18.15.0" NODE_VERSION: "18.16.1"
cache: cache:
paths: paths:
@ -28,20 +28,12 @@ default:
- echo "GO ${GO_VERSION} INSTALLED" - echo "GO ${GO_VERSION} INSTALLED"
- npm install - npm install
test:
stage: build
script:
- npm run build
rules:
- if: $CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH
pages: pages:
stage: build stage: build
script: script:
- npm run project-setup
- npm run build - npm run build
- echo "SITE BUILT SUCCESSFULLY! LIVE AT https://$GITLAB_USER_LOGIN.gitlab.io/$CI_PROJECT_NAME/" - echo "SITE BUILT SUCCESSFULLY! LIVE AT https://$GITLAB_USER_LOGIN.gitlab.io/$CI_PROJECT_NAME/"
artifacts: artifacts:
paths: paths:
- public - public
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH

View File

@ -1,14 +0,0 @@
; https://editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

View File

@ -1,15 +0,0 @@
Thumbs.db
.DS_Store
.dist
.tmp
.sass-cache
npm-debug.log
node_modules
builds
package-lock.json
public
resources
.hugo_build.lock
jsconfig.json
hugo_stats.json
go.sum

View File

@ -1,59 +0,0 @@
{
"maxerr": 50,
"bitwise": true,
"camelcase": false,
"curly": true,
"eqeqeq": true,
"forin": true,
"freeze": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": false,
"noarg": true,
"noempty": true,
"nonbsp": true,
"nonew": true,
"plusplus": false,
"undef": true,
"unused": false,
"strict": true,
"maxparams": false,
"maxdepth": 4,
"maxstatements": false,
"maxcomplexity": false,
"maxlen": 400,
"browser": true,
"devel": true,
"asi": false,
"boss": false,
"debug": false,
"eqnull": false,
"es3": false,
"es5": false,
"esversion": 12,
"moz": false,
"evil": true,
"expr": true,
"funcscope": false,
"globalstrict": false,
"iterator": false,
"lastsemic": false,
"laxbreak": false,
"laxcomma": false,
"loopfunc": true,
"multistr": true,
"noyield": false,
"notypeof": false,
"proto": false,
"scripturl": false,
"shadow": false,
"sub": false,
"supernew": false,
"validthis": false,
"globals": {
"jQuery": false,
"google": false,
"$": false
}
}

View File

@ -1,12 +0,0 @@
{
"overrides": [
{
"files": ["*.html"],
"options": {
"parser": "go-template",
"goTemplateBracketSpacing": true,
"bracketSameLine": true
}
}
]
}

View File

@ -13,12 +13,13 @@ googleAnalytics = "" # example: UA-123-45, for more info, read the article https
# disqus short name # disqus short name
disqusShortname = "themefisher-template" # we use disqus to show comments in blog posts . To install disqus please follow this tutorial https://portfolio.peter-baumgartner.net/2017/09/10/how-to-install-disqus-on-hugo/ disqusShortname = "themefisher-template" # we use disqus to show comments in blog posts . To install disqus please follow this tutorial https://portfolio.peter-baumgartner.net/2017/09/10/how-to-install-disqus-on-hugo/
# disable language # disable language
disableLanguages = [] # example: ["fr"] for disable french language. see https://gohugo.io/content-management/multilingual/ disableLanguages = [
] # example: ["fr"] for disable french language. see https://gohugo.io/content-management/multilingual/
hasCJKLanguage = false # If hasCJKLanguage true, auto-detect Chinese/Japanese/Korean Languages in the content. see: https://gohugo.io/getting-started/configuration/#hascjklanguage hasCJKLanguage = false # If hasCJKLanguage true, auto-detect Chinese/Japanese/Korean Languages in the content. see: https://gohugo.io/getting-started/configuration/#hascjklanguage
########################## Permalinks ############################ ########################## Permalinks ############################
[permalinks] [permalinks.page]
"pages" = "/:slugorfilename/" "pages" = "/:slugorfilename/"

View File

@ -1,17 +0,0 @@
[build]
publish = "public"
command = "yarn build"
[build.environment]
HUGO_VERSION = "0.112.5"
GO_VERSION = "1.19.4"
HUGO_BASEURL = "/"
[[headers]]
for = "/*" # This defines which paths this specific [[headers]] block will cover.
[headers.values]
X-Frame-Options = "DENY"
X-XSS-Protection = "1; mode=block"
Referrer-Policy = "same-origin"
Strict-Transport-Security = "max-age=31536000; includeSubDomains; preload"

View File

@ -1,29 +0,0 @@
{
"name": "hugoplate",
"description": "hugo tailwindcss boilerplate",
"version": "1.1.1",
"license": "MIT",
"author": "zeon.studio",
"scripts": {
"dev": "cd exampleSite; hugo server || hugo server --themesDir ../..",
"test": "cd exampleSite; hugo server --disableFastRender --navigateToChanged --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --watch --forceSyncStatic -e production --minify || hugo server --themesDir ../.. --disableFastRender --navigateToChanged --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --watch --forceSyncStatic -e production --minify",
"build": "cd exampleSite; hugo --gc --minify --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --forceSyncStatic || hugo --themesDir ../.. --gc --minify --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --forceSyncStatic",
"update-modules": "node ./scripts/cleanMod.js && hugo mod clean --all && hugo mod get -u ./... && hugo mod tidy",
"format": "prettier -w .",
"remove-darkmode": "node ./scripts/removeDarkmode.js && yarn format"
},
"devDependencies": {
"@fullhuman/postcss-purgecss": "^5.0.0",
"@tailwindcss/forms": "^0.5.3",
"@tailwindcss/typography": "^0.5.9",
"autoprefixer": "^10.4.14",
"postcss": "^8.4.24",
"postcss-cli": "^10.1.0",
"prettier": "^2.8.8",
"prettier-plugin-go-template": "0.0.13",
"prettier-plugin-tailwindcss": "^0.3.0",
"tailwind-bootstrap-grid": "^5.0.1",
"tailwindcss": "^3.3.2",
"toml": "^3.0.0"
}
}

View File

@ -1,52 +0,0 @@
const fs = require("fs");
const path = require("path");
const rootDirs = [
"themes/iot-hub-docs/assets/scss",
"themes/iot-hub-docs/layouts",
];
const configFiles = [
{
filePath: "tailwind.config.js",
patterns: ["darkmode:\\s*{[^}]*},", 'darkMode:\\s*"class",'],
},
{
filePath: "config.toml",
patterns: ["\\S*\\.darkmode[^\\]]*\\]\\n*([\\s\\S]*?)(?=\\[|$)"],
},
];
rootDirs.forEach(removeDarkModeFromPages);
configFiles.forEach(removeDarkMode);
function removeDarkModeFromFiles(filePath, regexPatterns) {
const fileContent = fs.readFileSync(filePath, "utf8");
let updatedContent = fileContent;
regexPatterns.forEach((pattern) => {
const regex = new RegExp(pattern, "g");
updatedContent = updatedContent.replace(regex, "");
});
fs.writeFileSync(filePath, updatedContent, "utf8");
}
function removeDarkModeFromPages(directoryPath) {
const files = fs.readdirSync(directoryPath);
files.forEach((file) => {
const filePath = path.join(directoryPath, file);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
removeDarkModeFromPages(filePath);
} else if (stats.isFile()) {
removeDarkModeFromFiles(filePath, [
'(?:(?!["])\\S)*dark:(?:(?![,;"])\\S)*',
"@apply?(\\s)*;",
]);
}
});
}
function removeDarkMode(configFile) {
const { filePath, patterns } = configFile;
removeDarkModeFromFiles(filePath, patterns);
}

View File

@ -1,20 +0,0 @@
#!/bin/bash
# default versions
if [ -z $GO_VERSION ]; then GO_VERSION='1.19.3'; fi
if [ -z $HUGO_VERSION ]; then HUGO_VERSION='0.112.5'; fi
# install Go
curl -sSOL https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz
tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
# install Hugo
echo "Installing Hugo $HUGO_VERSION..."
curl -sSOL https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz
tar -xzf hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz
hugo version
# run Hugo
echo "Running Hugo..."
hugo --gc --minify

View File

@ -1,18 +1,8 @@
[build] [build]
publish = "exampleSite/public" publish = "public"
command = "yarn build" command = "yarn project-setup && yarn build"
[build.environment] [build.environment]
HUGO_VERSION = "0.112.5" HUGO_VERSION = "0.115.1"
GO_VERSION = "1.19.4" GO_VERSION = "1.20.5"
HUGO_THEME = "repo"
HUGO_BASEURL = "/" HUGO_BASEURL = "/"
# [[headers]]
# for = "/*" # This defines which paths this specific [[headers]] block will cover.
# [headers.values]
# X-Frame-Options = "DENY"
# X-XSS-Protection = "1; mode=block"
# Referrer-Policy = "same-origin"
# Strict-Transport-Security = "max-age=31536000; includeSubDomains; preload"

View File

@ -1,16 +1,21 @@
{ {
"name": "hugoplate", "name": "hugoplate",
"description": "hugo tailwindcss boilerplate", "description": "hugo tailwindcss boilerplate",
"version": "1.1.2", "version": "1.2.0",
"license": "MIT", "license": "MIT",
"author": "zeon.studio", "author": "zeon.studio",
"scripts": { "scripts": {
"dev": "cd exampleSite; hugo server || hugo server --themesDir ../..", "dev": "hugo server",
"test": "cd exampleSite; hugo server --disableFastRender --navigateToChanged --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --watch --forceSyncStatic -e production --minify || hugo server --themesDir ../.. --disableFastRender --navigateToChanged --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --watch --forceSyncStatic -e production --minify", "build": "hugo --gc --minify --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --forceSyncStatic",
"build": "cd exampleSite; hugo --gc --minify --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --forceSyncStatic || hugo --themesDir ../.. --gc --minify --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --forceSyncStatic", "test": "hugo server --disableFastRender --navigateToChanged --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --watch --forceSyncStatic -e production --minify",
"update-modules": "node ./scripts/cleanMod.js && hugo mod clean --all && hugo mod get -u ./... && hugo mod tidy", "dev:example": "cd exampleSite; hugo server --themesDir ../..",
"format": "prettier -w .", "build:example": "cd exampleSite; hugo --themesDir ../.. --gc --minify --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --forceSyncStatic",
"remove-darkmode": "node ./scripts/removeDarkmode.js && yarn format" "test:example": "cd exampleSite; hugo server --themesDir ../.. --disableFastRender --navigateToChanged --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --watch --forceSyncStatic -e production --minify",
"update-modules": "node ./scripts/clearModules.js && hugo mod clean --all && hugo mod get -u ./... && hugo mod tidy",
"remove-darkmode": "node ./scripts/removeDarkmode.js && yarn format",
"project-setup": "node ./scripts/projectSetup.js",
"theme-setup": "node ./scripts/themeSetup.js",
"format": "prettier -w ."
}, },
"devDependencies": { "devDependencies": {
"@fullhuman/postcss-purgecss": "^5.0.0", "@fullhuman/postcss-purgecss": "^5.0.0",

View File

@ -63,6 +63,12 @@
- Npm v9.5+ - Npm v9.5+
- Tailwindcss v3+ - Tailwindcss v3+
### 👉 Project Setup
```
npm run project-setup
```
### 👉 Development Command ### 👉 Development Command
``` ```

View File

@ -1,6 +1,6 @@
const fs = require("fs"); const fs = require("fs");
const clearMode = (filePath) => { const clearModules = (filePath) => {
if (fs.existsSync(filePath)) { if (fs.existsSync(filePath)) {
let fileContent = fs.readFileSync(filePath, "utf8"); let fileContent = fs.readFileSync(filePath, "utf8");
fileContent = fileContent.replace(/require\s*\([\s\S]*?\)/, ""); fileContent = fileContent.replace(/require\s*\([\s\S]*?\)/, "");
@ -10,5 +10,5 @@ const clearMode = (filePath) => {
} }
}; };
clearMode("go.mod"); clearModules("go.mod");
clearMode("exampleSite/go.mod"); clearModules("exampleSite/go.mod");

77
scripts/projectSetup.js Normal file
View File

@ -0,0 +1,77 @@
const fs = require("fs");
const path = require("path");
const getFolderName = (rootfolder) => {
const configPath = path.join(
rootfolder,
"exampleSite/config/_default/config.toml"
);
const getConfig = fs.readFileSync(configPath, "utf8");
const match = getConfig.match(/theme\s*=\s*\[?"([^"\]]+)"\]?/);
let selectedTheme = null;
if (match && match[1]) {
selectedTheme = match[1];
}
return selectedTheme;
};
const deleteFolder = (folderPath) => {
if (fs.existsSync(folderPath)) {
fs.rmSync(folderPath, { recursive: true, force: true });
}
};
const createNewfolder = (rootfolder, folderName) => {
const newFolder = path.join(rootfolder, folderName);
fs.mkdirSync(newFolder, { recursive: true });
return newFolder;
};
const iterateFilesAndFolders = (rootFolder, { destinationRoot }) => {
const directory = path.join(rootFolder);
const items = fs.readdirSync(directory, { withFileTypes: true });
items.forEach((item) => {
if (item.isDirectory()) {
createNewfolder(destinationRoot, item.name);
iterateFilesAndFolders(path.join(directory, item.name), {
currentFolder: item.name,
destinationRoot: path.join(destinationRoot, item.name),
});
} else {
const sourceFile = path.join(directory, item.name);
const destinationFile = path.join(destinationRoot, item.name);
fs.renameSync(sourceFile, destinationFile);
}
});
};
const setupProject = () => {
const rootfolder = path.join(__dirname, "../");
if (!fs.existsSync(path.join(rootfolder, "themes"))) {
const folderList = ["layouts", "assets", "static"];
const folderName = getFolderName(rootfolder);
const newfolderName = createNewfolder(
path.join(rootfolder, "themes"),
folderName
);
folderList.forEach((folder) => {
const source = path.join(rootfolder, folder);
const destination = path.join(newfolderName, folder);
if (fs.existsSync(source)) {
fs.mkdirSync(destination, { recursive: true });
iterateFilesAndFolders(source, {
currentFolder: folder,
destinationRoot: destination,
});
deleteFolder(source);
}
});
const exampleSite = path.join(rootfolder, "exampleSite");
iterateFilesAndFolders(exampleSite, { destinationRoot: rootfolder });
deleteFolder(exampleSite);
}
};
setupProject();

93
scripts/themeSetup.js Normal file
View File

@ -0,0 +1,93 @@
const fs = require("fs");
const path = require("path");
const createNewfolder = (rootfolder, folderName) => {
const newFolder = path.join(rootfolder, folderName);
fs.mkdirSync(newFolder, { recursive: true });
return newFolder;
};
const deleteFolder = (folderPath) => {
if (fs.existsSync(folderPath)) {
fs.rmSync(folderPath, { recursive: true, force: true });
}
};
const getFolderName = (rootfolder) => {
const configPath = path.join(
rootfolder,
"exampleSite/config/_default/config.toml"
);
const getConfig = fs.readFileSync(configPath, "utf8");
const match = getConfig.match(/theme\s*=\s*\[?"([^"\]]+)"\]?/);
let selectedTheme = null;
if (match && match[1]) {
selectedTheme = match[1];
}
return selectedTheme;
};
const iterateFilesAndFolders = (rootFolder, { destinationRoot }) => {
const directory = path.join(rootFolder);
const items = fs.readdirSync(directory, { withFileTypes: true });
items.forEach((item) => {
if (item.isDirectory()) {
createNewfolder(destinationRoot, item.name);
iterateFilesAndFolders(path.join(directory, item.name), {
currentFolder: item.name,
destinationRoot: path.join(destinationRoot, item.name),
});
} else {
const sourceFile = path.join(directory, item.name);
const destinationFile = path.join(destinationRoot, item.name);
fs.renameSync(sourceFile, destinationFile);
}
});
};
const setupTheme = () => {
const rootFolder = path.join(__dirname, "../");
if (!fs.existsSync(path.join(rootFolder, "exampleSite"))) {
const includesFiles = [
"tailwind.config.js",
"postcss.config.js",
"go.mod",
"config.toml",
"assets",
"config",
"content",
"i18n",
"static",
];
const folder = createNewfolder(rootFolder, "exampleSite");
console.log({ folder });
fs.readdirSync(rootFolder, { withFileTypes: true }).forEach((file) => {
if (includesFiles.includes(file.name)) {
if (file.isDirectory()) {
const destination = path.join(rootFolder, "exampleSite", file.name);
fs.mkdirSync(destination, { recursive: true });
iterateFilesAndFolders(path.join(rootFolder, file.name), {
destinationRoot: destination,
});
deleteFolder(path.join(rootFolder, file.name));
} else {
fs.renameSync(
path.join(rootFolder, file.name),
path.join(folder, file.name)
);
}
}
});
const themes = path.join(rootFolder, "themes");
iterateFilesAndFolders(path.join(themes, getFolderName(rootFolder)), {
destinationRoot: rootFolder,
});
deleteFolder(themes);
}
};
setupTheme();

43
vercel-build.sh Executable file
View File

@ -0,0 +1,43 @@
#!/bin/bash
# default versions
NODE_VERSION='18.16.1';
GO_VERSION='1.20.5';
HUGO_VERSION='0.115.1';
# install Node.js
# echo "Installing Node.js $NODE_VERSION..."
# curl -sSOL https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}.tar.gz
# tar -xzf node-v${NODE_VERSION}.tar.gz
# export PATH=$PATH:/usr/local/bin
# rm -rf node-v${NODE_VERSION}.tar.gz
echo "USING NODE VERSION: $(node -v)"
# install Go
echo "Installing Go $GO_VERSION..."
curl -sSOL https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz
tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
rm -rf go${GO_VERSION}.linux-amd64.tar.gz
go version
# install Hugo
echo "Installing Hugo $HUGO_VERSION..."
curl -sSOL https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz
tar -xzf hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz
mv hugo /usr/local/bin/
rm -rf hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz
hugo version
# project setup
echo "Project setting up..."
npm run project-setup
# install dependencies
echo "Installing project dependencies..."
npm install
# run the build command
echo "Running the build command..."
npm run build