building pipeline

This commit is contained in:
Letter N
2021-03-04 21:51:20 +08:00
parent 23c04cac12
commit dcab40cdb6
134 changed files with 10776 additions and 5991 deletions
+40 -30
View File
@@ -26,9 +26,18 @@ fi
base_dir="$(dirname "$(tgui-realpath "${0}")")/.."
base_dir="$(tgui-realpath "${base_dir}")"
## Make use of nvm if it exists
if [[ -e "${HOME}/.nvm/nvm.sh" ]]; then
source "${HOME}/.nvm/nvm.sh"
fi
## Fall back to running Yarn from the repo
if ! hash yarn 2>/dev/null; then
alias yarn="node '${base_dir}/.yarn/releases/yarn-2.3.3.cjs'"
yarn_releases=("${base_dir}"/.yarn/releases/yarn-*.cjs)
yarn_release="${yarn_releases[0]}"
yarn() {
node "${yarn_release}" "${@}"
}
fi
@@ -54,22 +63,32 @@ task-dev-server() {
}
## Run a linter through all packages
task-eslint() {
task-lint() {
cd "${base_dir}"
yarn run eslint packages "${@}"
yarn run tsc
echo "tgui: type check passed"
yarn run eslint packages --ext .js,.jsx,.ts,.tsx,.cjs,.mjs "${@}"
echo "tgui: eslint check passed"
}
task-test() {
cd "${base_dir}"
yarn run jest
}
## Mr. Proper
task-clean() {
cd "${base_dir}"
## Build artifacts
rm -rf public/.tmp
rm -f public/*.map
rm -f public/*.chunk.*
rm -f public/*.bundle.*
rm -f public/*.hot-update.*
## Yarn artifacts
rm -rf .yarn/cache
rm -rf .yarn/unplugged
rm -rf .yarn/webpack
rm -rf .yarn/build-state.yml
rm -rf .yarn/install-state.gz
rm -f .pnp.js
@@ -78,19 +97,6 @@ task-clean() {
rm -f **/package-lock.json
}
## Validates current build against the build stored in git
task-validate-build() {
cd "${base_dir}"
local diff
diff="$(git diff public/*)"
if [[ -n ${diff} ]]; then
echo "Error: our build differs from the build committed into git."
echo "Please rebuild tgui."
exit 1
fi
echo "tgui: build is ok"
}
## Installs merge drivers and git hooks
task-install-git-hooks() {
cd "${base_dir}"
@@ -133,16 +139,6 @@ if [[ ${1} == "--install-git-hooks" ]]; then
exit 0
fi
## Continuous integration scenario
if [[ ${1} == "--ci" ]]; then
task-clean
task-install
task-eslint
task-webpack --mode=production
task-validate-build
exit 0
fi
if [[ ${1} == "--clean" ]]; then
task-clean
exit 0
@@ -158,21 +154,28 @@ fi
if [[ ${1} == '--lint' ]]; then
shift 1
task-install
task-eslint "${@}"
task-lint "${@}"
exit 0
fi
if [[ ${1} == '--lint-harder' ]]; then
shift 1
task-install
task-eslint -c .eslintrc-harder.yml "${@}"
task-lint -c .eslintrc-harder.yml "${@}"
exit 0
fi
if [[ ${1} == '--fix' ]]; then
shift 1
task-install
task-eslint --fix "${@}"
task-lint --fix "${@}"
exit 0
fi
if [[ ${1} == '--test' ]]; then
shift 1
task-install
task-test "${@}"
exit 0
fi
@@ -184,9 +187,16 @@ if [[ ${1} == '--analyze' ]]; then
fi
## Make a production webpack build
if [[ ${1} == '--build' ]]; then
task-install
task-webpack --mode=production
exit 0
fi
## Make a production webpack build + Run eslint
if [[ -z ${1} ]]; then
task-install
task-eslint
task-lint --fix
task-webpack --mode=production
exit 0
fi
+1 -1
View File
@@ -1,7 +1,7 @@
@echo off
rem Copyright (c) 2020 Aleksej Komarov
rem SPDX-License-Identifier: MIT
call powershell.exe -NoLogo -ExecutionPolicy Bypass -File "%~dp0\tgui.ps1" --dev %*
call powershell.exe -NoLogo -ExecutionPolicy Bypass -File "%~dp0\tgui_.ps1" --dev %*
rem Pause if launched in a separate shell unless initiated from powershell
echo %PSModulePath% | findstr %USERPROFILE% >NUL
if %errorlevel% equ 0 exit 0
+1 -1
View File
@@ -1,7 +1,7 @@
@echo off
rem Copyright (c) 2020 Aleksej Komarov
rem SPDX-License-Identifier: MIT
call powershell.exe -NoLogo -ExecutionPolicy Bypass -File "%~dp0\tgui.ps1" %*
call powershell.exe -NoLogo -ExecutionPolicy Bypass -File "%~dp0\tgui_.ps1" %*
rem Pause if launched in a separate shell unless initiated from powershell
echo %PSModulePath% | findstr %USERPROFILE% >NUL
if %errorlevel% equ 0 exit 0
+67 -37
View File
@@ -4,6 +4,18 @@
## Initial set-up
## --------------------------------------------------------
## Enable strict mode and stop of first cmdlet error
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
## Validates exit code of external commands
function Throw-On-Native-Failure {
if (-not $?) {
exit 1
}
}
## Normalize current directory
$basedir = Split-Path $MyInvocation.MyCommand.Path
$basedir = Resolve-Path "$($basedir)\.."
@@ -15,7 +27,9 @@ Set-Location $basedir
## --------------------------------------------------------
function yarn {
node.exe ".yarn\releases\yarn-2.3.3.cjs" @Args
$YarnRelease = Get-ChildItem -Filter ".yarn\releases\yarn-*.cjs" | Select-Object -First 1
node ".yarn\releases\$YarnRelease" @Args
Throw-On-Native-Failure
}
function Remove-Quiet {
@@ -37,11 +51,17 @@ function task-dev-server {
}
## Run a linter through all packages
function task-eslint {
yarn run eslint packages @Args
function task-lint {
yarn run tsc
Write-Output "tgui: type check passed"
yarn run eslint packages --ext .js,.jsx,.ts,.tsx,.cjs,.mjs @Args
Write-Output "tgui: eslint check passed"
}
function task-test {
yarn run jest
}
## Mr. Proper
function task-clean {
## Build artifacts
@@ -51,6 +71,7 @@ function task-clean {
## Yarn artifacts
Remove-Quiet -Recurse -Force ".yarn\cache"
Remove-Quiet -Recurse -Force ".yarn\unplugged"
Remove-Quiet -Recurse -Force ".yarn\webpack"
Remove-Quiet -Recurse -Force ".yarn\build-state.yml"
Remove-Quiet -Recurse -Force ".yarn\install-state.gz"
Remove-Quiet -Force ".pnp.js"
@@ -63,50 +84,59 @@ function task-clean {
## Main
## --------------------------------------------------------
if ($Args[0] -eq "--clean") {
task-clean
exit 0
}
if ($Args.Length -gt 0) {
if ($Args[0] -eq "--clean") {
task-clean
exit 0
}
if ($Args[0] -eq "--dev") {
$Rest = $Args | Select-Object -Skip 1
task-install
task-dev-server @Rest
exit 0
}
if ($Args[0] -eq "--dev") {
$Rest = $Args | Select-Object -Skip 1
task-install
task-dev-server @Rest
exit 0
}
if ($Args[0] -eq "--lint") {
$Rest = $Args | Select-Object -Skip 1
task-install
task-eslint @Rest
exit 0
}
if ($Args[0] -eq "--lint") {
$Rest = $Args | Select-Object -Skip 1
task-install
task-lint @Rest
exit 0
}
if ($Args[0] -eq "--lint-harder") {
$Rest = $Args | Select-Object -Skip 1
task-install
task-eslint -c ".eslintrc-harder.yml" @Rest
exit 0
}
if ($Args[0] -eq "--lint-harder") {
$Rest = $Args | Select-Object -Skip 1
task-install
task-lint -c ".eslintrc-harder.yml" @Rest
exit 0
}
if ($Args[0] -eq "--fix") {
$Rest = $Args | Select-Object -Skip 1
task-install
task-eslint --fix @Rest
exit 0
}
if ($Args[0] -eq "--fix") {
$Rest = $Args | Select-Object -Skip 1
task-install
task-lint --fix @Rest
exit 0
}
## Analyze the bundle
if ($Args[0] -eq "--analyze") {
task-install
task-webpack --mode=production --analyze
exit 0
if ($Args[0] -eq "--test") {
$Rest = $Args | Select-Object -Skip 1
task-install
task-test @Rest
exit 0
}
## Analyze the bundle
if ($Args[0] -eq "--analyze") {
task-install
task-webpack --mode=production --analyze
exit 0
}
}
## Make a production webpack build
if ($Args.Length -eq 0) {
task-install
task-eslint
task-lint
task-webpack --mode=production
exit 0
}