Skip to content

Commit

Permalink
feat(script): build and release theme
Browse files Browse the repository at this point in the history
  • Loading branch information
ourai committed Apr 19, 2023
1 parent 170f102 commit 27a579f
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ sh.exe.stackdump

*.log
node_modules/
dist/

.cache/
.asset-cache/
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 0.0.0-alpha.1 (2023-04-19)

Initial release!
86 changes: 52 additions & 34 deletions bin/build.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,68 @@
const { resolve: resolvePath } = require('path');
const { pick } = require('@ntks/toolbox');

const { ensureDirExists, copyFileDeeply, readData, saveData, execute } = require('./helper');
const { ensureDirExists, copyFileDeeply, rm, cp, saveData, execute, copyThemeAssets } = require('./helper');

const SRC_ROOT = resolvePath(__dirname, '../src');
const SA_ROOT = `${SRC_ROOT}/shared`;
const prjRoot = resolvePath(__dirname, '..');
const srcRoot = `${prjRoot}/src`;
const distRoot = `${prjRoot}/dist`;

function copyAssets(distRoot, polyfill) {
['fonts', 'images', 'javascripts', 'stylesheets'].forEach(dirName => {
const assetsPath = `${distRoot}/${dirName}`;
function copyMetaFiles(dirName) {
const distDir = `${distRoot}/${dirName}`;
const readmeTemplate = `# [Lime](https://ourai.github.io/lime/)
ensureDirExists(assetsPath);
A simple, readable, responsive theme that:
const srcPath = `${SA_ROOT}/${dirName}`;
const distPath = `${distRoot}/${dirName}/ksio`;
- audience experience first design
- born for blogs, personal websites and API docs
- supports most of PC and mobile modern web browsers
ensureDirExists(distPath, true);
copyFileDeeply(srcPath, distPath, polyfill ? [] : ['polyfills']);
});
## Getting Started
const distStyleDirPath = `${distRoot}/stylesheets/ksio/`;
Please follow the documentation [on the website](https://ourai.github.io/lime/).
`;

const shareSnsStyleFilePath = `${distStyleDirPath}/vendors/share.scss`;
const shareSnsStyleFileContent = readData(shareSnsStyleFilePath);
saveData(`${distDir}/README.md`, readmeTemplate);
cp(`${prjRoot}/CHANGELOG.md`, `${distDir}/`);
}

if (!polyfill) {
return saveData(shareSnsStyleFilePath, shareSnsStyleFileContent.replace(new RegExp('fonts/vendors/share', 'g'), 'ksio/vendors/share'));
}
function copyJekyllFiles() {
const jekyllSrcRoot = `${srcRoot}/jekyll`;
const jekyllDistRoot = `${distRoot}/jekyll`;

saveData(shareSnsStyleFilePath, shareSnsStyleFileContent.replace(new RegExp('fonts/vendors/share', 'g'), '../../../fonts/ksio/vendors/share').replace(new RegExp('font-url', 'g'), 'url'));
ensureDirExists(jekyllDistRoot, true);

const faStyleFilePath = `${distStyleDirPath}/polyfills/_font-awesome-sprockets.scss`;
['_includes', '_layouts'].forEach(dirName => {
const distPath = `${jekyllDistRoot}/${dirName}/ksio`;

saveData(faStyleFilePath, readData(faStyleFilePath).replace(' font-path($path)', ' "../fonts/ksio/polyfills/#{$path}"'));
ensureDirExists(distPath, true);
copyFileDeeply(`${jekyllSrcRoot}/${dirName}/ksio`, distPath);
});

['_all', '_bootstrap-custom', '_helper', '_painter'].forEach(fileName => {
const filePath = `${distStyleDirPath}/${fileName}.scss`;
const bsStr = fileName === '_all' ? 'bootstrap-sprockets' : 'bootstrap';
copyThemeAssets(`${jekyllDistRoot}/_assets`);
copyMetaFiles('jekyll');
}

saveData(
filePath,
readData(filePath)
.replace(new RegExp('@import "compass', 'g'), '@import "./polyfills/compass')
.replace(new RegExp(`@import "${bsStr}`, 'g'), `@import "./polyfills/${bsStr}`)
.replace(new RegExp('@import "font-awesome', 'g'), '@import "./polyfills/font-awesome'),
);
});
function copyHexoFiles() {
const hexoSrcRoot = `${srcRoot}/hexo/themes/lime`;
const hexoDistRoot = `${distRoot}/hexo`;

ensureDirExists(hexoDistRoot, true);
copyFileDeeply(hexoSrcRoot, hexoDistRoot);
rm(`${hexoDistRoot}/*/_local`);

copyThemeAssets(`${hexoDistRoot}/source`, true);

const { devDependencies, ...pkgFields } = pick(require(`${prjRoot}/package.json`), ['version', 'description', 'repository', 'author', 'license', 'bugs', 'homepage', 'devDependencies']);

saveData(`${hexoDistRoot}/package.json`, JSON.stringify({
name: 'hexo-theme-lime',
main: 'package.json',
keywords: ['hexo', 'theme', 'lime', 'knosys', 'ksio'],
...pkgFields,
dependencies: { '@ntks/toolbox': devDependencies['@ntks/toolbox'] },
}, null, 2));
copyMetaFiles('hexo');
}

module.exports = {
Expand All @@ -54,11 +72,11 @@ module.exports = {
}

if (type === 'jekyll') {
return copyAssets(`${SRC_ROOT}/jekyll/_assets`);
return copyJekyllFiles();
}

if (type === 'hexo') {
return copyAssets(`${SRC_ROOT}/hexo/themes/lime/source`, true);
return copyHexoFiles();
}
},
};
17 changes: 17 additions & 0 deletions bin/copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { resolve: resolvePath } = require('path');

const { copyThemeAssets } = require('./helper');

module.exports = {
execute: (type = 'jekyll') => {
const srcRoot = resolvePath(__dirname, '../src');

if (type === 'jekyll') {
return copyThemeAssets(`${srcRoot}/jekyll/_assets`);
}

if (type === 'hexo') {
return copyThemeAssets(`${srcRoot}/hexo/themes/lime/source`, true);
}
},
};
50 changes: 50 additions & 0 deletions bin/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const { resolve: resolvePath } = require('path');
const { execSync } = require('child_process');

const { rm, execute } = require('./helper');

const prjRoot = resolvePath(__dirname, '..');
const distRoot = `${prjRoot}/dist`;

function zipTheme(dirName) {
const fileName = `${dirName}-theme-lime.zip`;

rm(`${distRoot}/${fileName}`);
execSync(`zip -rm ${fileName} ${dirName}`, { stdio: 'inherit', cwd: distRoot });
}

module.exports = {
execute: (type = 'site', alias) => {
if (type === 'site') {
return execute('site', 'deploy');
}

if (type !== 'pkg') {
return;
}

const pkgs = [];

if (alias) {
if (['jekyll', 'hexo'].includes(alias)) {
pkgs.push(alias);
}
} else {
pkgs.push('jekyll', 'hexo');
}

if (pkgs.length === 0) {
return;
}

pkgs.forEach(pkg => {
execSync(`npm run build ${pkg}`, { stdio: 'inherit', cwd: prjRoot });

if (pkg === 'hexo') {
execSync('npm publish', { stdio: 'inherit', cwd: `${distRoot}/hexo` });
}

zipTheme(pkg);
});
},
};
46 changes: 45 additions & 1 deletion bin/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,49 @@ const { resolve: resolvePath } = require('path');
const { readFileSync } = require('fs');

const rootPath = resolvePath(__dirname, '..');
const knosysUtils = require(resolvePath(rootPath, JSON.parse(readFileSync(resolvePath(rootPath, '.knosysrc'), 'utf8').toString().trim()).$path));
const { ensureDirExists, copyFileDeeply, readData, saveData } = knosysUtils;

module.exports = require(resolvePath(rootPath, JSON.parse(readFileSync(resolvePath(rootPath, '.knosysrc'), 'utf8').toString().trim()).$path));
function copyThemeAssets(distRoot, polyfill) {
['fonts', 'images', 'javascripts', 'stylesheets'].forEach(dirName => {
const assetsPath = `${distRoot}/${dirName}`;

ensureDirExists(assetsPath);

const srcPath = `${rootPath}/src/shared/${dirName}`;
const distPath = `${distRoot}/${dirName}/ksio`;

ensureDirExists(distPath, true);
copyFileDeeply(srcPath, distPath, polyfill ? [] : ['polyfills']);
});

const distStyleDirPath = `${distRoot}/stylesheets/ksio/`;

const shareSnsStyleFilePath = `${distStyleDirPath}/vendors/share.scss`;
const shareSnsStyleFileContent = readData(shareSnsStyleFilePath);

if (!polyfill) {
return saveData(shareSnsStyleFilePath, shareSnsStyleFileContent.replace(new RegExp('fonts/vendors/share', 'g'), 'ksio/vendors/share'));
}

saveData(shareSnsStyleFilePath, shareSnsStyleFileContent.replace(new RegExp('fonts/vendors/share', 'g'), '../../../fonts/ksio/vendors/share').replace(new RegExp('font-url', 'g'), 'url'));

const faStyleFilePath = `${distStyleDirPath}/polyfills/_font-awesome-sprockets.scss`;

saveData(faStyleFilePath, readData(faStyleFilePath).replace(' font-path($path)', ' "../fonts/ksio/polyfills/#{$path}"'));

['_all', '_bootstrap-custom', '_helper', '_painter'].forEach(fileName => {
const filePath = `${distStyleDirPath}/${fileName}.scss`;
const bsStr = fileName === '_all' ? 'bootstrap-sprockets' : 'bootstrap';

saveData(
filePath,
readData(filePath)
.replace(new RegExp('@import "compass', 'g'), '@import "./polyfills/compass')
.replace(new RegExp(`@import "${bsStr}`, 'g'), `@import "./polyfills/${bsStr}`)
.replace(new RegExp('@import "font-awesome', 'g'), '@import "./polyfills/font-awesome'),
);
});
}

module.exports = { copyThemeAssets, ...knosysUtils };
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "@ourai/lime",
"version": "0.0.0",
"version": "0.0.0-alpha.1",
"description": "Simple, readable, responsive theme for blogs, personal websites and API docs",
"private": true,
"main": "index.js",
"scripts": {
"copy": "node bin copy",
"build": "node bin build",
"clean": "rm -rf src/jekyll/.asset-cache",
"start": "node bin serve",
"predeploy": "npm run clean",
"deploy": "node bin site deploy"
"deploy": "node bin deploy"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 27a579f

Please sign in to comment.