0.0.10 • Published 10 months ago
abuild v0.0.10
abuild
A lightweight compilation tool suitable for file path changes, content replacement, and log generation.
Install
npm i -g abuild
OR
npm i abuild -D
Configuration
Step 1:
Create an abuild
specific configuration file called abuild.config.js
in the project root directory
Step 2:
The configuration file will ultimately return an object that can contain the following attributes:
1. Public Configuration Properties
preChangeLocalPath
// File matching rules that require changing the path before compilation
preChangeLocalPath: [
{
// {Boolean} Whether to directly replace the source file that needs to change the path before compilation: false - keep the source file (default), true - delete the source file
isReplace: true,
// Whether to add a hash to this file
needFileHash: true,
// {String} File directory or file path (limited range)
path: '/client/dist/global.css',
// {RegExp} File Regular Matching Rules
from: /\/client\/dist\/(global\.css)/i,
// {String|Function} The new path that needs to be changed can be a string or a function that can return a string
// options.configCache: a k-v storage object for caching data during the compilation process
// options.fileHash: fileHash will only be passed in as a parameter when needFileHash is true
to: (options) => {
const {configCache, fileHash} = options;
configCache && (configCache.globalCssHash = fileHash);
return `/client/dist/assets/${fileHash}.css`
}
}
]
ignoreRelease
// File matching rules without compilation (non-standard regular rules)
ignoreRelease: '*.sh,foutput.js,release.js,build.js,_build.js,debug.js,deploy.js,*.log,.gitignore,*config.js,*conf.js,*conf*.js,.vscode,/.DS_Store,/README.md,/{.git,config,doc,docs,html,mockup,node_modules,test,material,public,output,output-*,.DS_Store,build,client,client*}/**'
needReleasePath
// Path to files (or directories) that require special compilation (note: it is a path, not a matching rule)
// Generally, it is aimed at files or file directories that are included in the ignoreRelease rule but need to be extracted for compilation processing
needReleasePath: ['/client/dist/']
changePathRelease
// Regular matching rules for files that need to change paths
// The same file will be processed according to the last matching rule (try to avoid the same file being matched multiple times by different processing rules, which may lead to unexpected compilation paths)
changePathRelease: [
// *.html -> /views/*.html
{
from: /\/client\/dist\/(.+?\.html)$/i,
to: () => {
return `/views/${RegExp.$1}`;
}
}
]
2. Compilation mode (debug | deploy)
debug
- Debugging environment compilation mode configuration
// debug env
debug: {
// Compilation Path
deployPath: `../output/${siteName}/`,
// File Content Replacement
replace: {
// Files that require content replacement (non-standard regular rules)
files: '{package.json,package-lock.json,go.js,go*.js,*.html,/{lib,views}/**}',
// Content Replacement Matching Rules - RegExp
rules: [
// client html content
{
from: /\.*\/*(assets\/global).css/gim,
// {String|Function} The new path that needs to be changed can be a string or a function that can return a string
// options.configCache: a k-v storage object for caching data during the compilation process
// options.fileHash: fileHash will only be passed in as a parameter when needFileHash is true
to: (options) => {
const { configCache } = options || {};
const { globalCssHash } = configCache || {};
return `/${RegExp.$1}.${globalCssHash}.css`
}
}
]
}
}
deploy
- Production environment compilation mode configuration
// production env
deploy: {
// Compilation Path
deployPath: `${deployPath}/latest_${dirName}`,
// File Content Replacement
replace: {
// Files that require content replacement (non-standard regular rules)
files: '{*.html,/{common,views}/**}',
// Content Replacement Matching Rules - RegExp
rules: [
// client html content
{
from: /\.*\/*(assets\/global).css/gim,
// {String|Function} The new path that needs to be changed can be a string or a function that can return a string
// options.configCache: a k-v storage object for caching data during the compilation process
// options.fileHash: fileHash will only be passed in as a parameter when needFileHash is true
to: (options) => {
const { configCache } = options || {};
const { globalCssHash } = configCache || {};
return `/${RegExp.$1}.${globalCssHash}.css`
}
}
]
},
// Build log files that require additional content after compilation
outputLog: {
// {Boolean} true - append log(default), false - replace log
isAdditional: true,
// Log file path
path: `${deployPath}/output.txt`,
// {String|Function} A string or a function that can return a string
log: () => {
// for example
return `, ${Date.now()}`
}
}
}
Usage
Compile using the abuild
and its abuild.config.js
configuration file:
// debug env
abuild debug
OR
// production env
abuild deploy