mirror of
https://github.com/RetroShare/RSNewWebUI.git
synced 2026-09-12 19:50:04 +05:00
build: make WebUI npm scripts cross-platform
This commit is contained in:
parent
81f3ef17a6
commit
6eada33d47
@ -157,6 +157,9 @@ npm run build
|
||||
npm run lint
|
||||
```
|
||||
|
||||
These npm commands use `build.bat` on native Windows and `build.sh` on other
|
||||
platforms.
|
||||
|
||||
Commit SCSS changes together with the regenerated `webui-src/styles.css`.
|
||||
`qmake .` packages that committed CSS but does not compile SCSS. Running
|
||||
`make` alone does not rebuild this `TEMPLATE = subdirs` project; rerun
|
||||
@ -189,8 +192,9 @@ when testing watched changes through RetroShare.
|
||||
|
||||
Before submitting, run the full build and lint commands, then point
|
||||
RetroShare's **Web interface directory** at `webui/` and manually test the
|
||||
affected screens. ESLint, generated JavaScript syntax, and shell syntax are
|
||||
checked by `npm run lint`; no formatting script is defined.
|
||||
affected screens. ESLint, generated JavaScript syntax, the build dispatcher,
|
||||
and shell syntax on non-Windows systems are checked by `npm run lint`; no
|
||||
formatting script is defined.
|
||||
|
||||
### References
|
||||
|
||||
|
||||
@ -5,55 +5,58 @@ setlocal enabledelayedexpansion
|
||||
|
||||
echo "### Starting WebUI build ###"
|
||||
|
||||
set src=%~dp0..\..\webui-src
|
||||
set "src=%~dp0..\..\webui-src"
|
||||
|
||||
rem Output destination
|
||||
if "%~1"=="" (
|
||||
set publicdest=%~dp0..\..\webui
|
||||
set "publicdest=%~dp0..\..\webui"
|
||||
) else (
|
||||
set publicdest=%~1\webui
|
||||
set "publicdest=%~1\webui"
|
||||
)
|
||||
|
||||
if exist "%publicdest%" echo removing existing %publicdest%&&rd %publicdest% /S /Q
|
||||
if exist "%publicdest%" (
|
||||
echo removing existing %publicdest%
|
||||
rd "%publicdest%" /S /Q
|
||||
)
|
||||
|
||||
echo creating %publicdest%
|
||||
md %publicdest%
|
||||
md "%publicdest%"
|
||||
|
||||
rem Make full path
|
||||
pushd %publicdest%
|
||||
set publicdest=%cd%
|
||||
pushd "%publicdest%"
|
||||
set "publicdest=%cd%"
|
||||
popd
|
||||
|
||||
echo copying html file
|
||||
xcopy /s %src%\index.html %publicdest%
|
||||
copy /Y "%src%\index.html" "%publicdest%\index.html" >nul
|
||||
|
||||
echo copying css file
|
||||
xcopy /s %src%\styles.css %publicdest%
|
||||
copy /Y "%src%\styles.css" "%publicdest%\styles.css" >nul
|
||||
|
||||
echo building app.js
|
||||
echo - copying template.js ...
|
||||
copy %src%\make-src\template.js %publicdest%\app.js
|
||||
copy /Y "%src%\make-src\template.js" "%publicdest%\app.js" >nul
|
||||
|
||||
pushd %src%\app
|
||||
pushd "%src%\app"
|
||||
set "basefolder=%cd%\"
|
||||
set "lastsection="
|
||||
for /R %%F in (*.js) do call :addfile-js "%basefolder%" "%%F"
|
||||
popd
|
||||
|
||||
echo copying assets folder
|
||||
xcopy /s %src%\assets\ %publicdest%
|
||||
xcopy "%src%\assets\*" "%publicdest%\" /E /I /Y >nul
|
||||
|
||||
echo "### WebUI build complete ###"
|
||||
|
||||
goto :EOF
|
||||
|
||||
:addfile-js
|
||||
set basefolder=%~1
|
||||
set fname=%~2
|
||||
set "basefolder=%~1"
|
||||
set "fname=%~2"
|
||||
|
||||
set registername=%~dpn2
|
||||
set registername=!registername:%basefolder%=!
|
||||
set registername=%registername:\=/%
|
||||
set "registername=%~dpn2"
|
||||
set "registername=!registername:%basefolder%=!"
|
||||
set "registername=%registername:\=/%"
|
||||
|
||||
for /f "tokens=1,2 delims=/" %%A in ("!registername!") do (
|
||||
if "%%B"=="" (
|
||||
@ -64,9 +67,9 @@ for /f "tokens=1,2 delims=/" %%A in ("!registername!") do (
|
||||
set "lastsection=%%A"
|
||||
)
|
||||
)
|
||||
echo require.register("%registername%", function(exports, require, module) { >> %publicdest%\app.js
|
||||
type %fname% >> %publicdest%\app.js
|
||||
echo. >> %publicdest%\app.js
|
||||
echo }); >> %publicdest%\app.js
|
||||
echo require.register("%registername%", function(exports, require, module) { >>"%publicdest%\app.js"
|
||||
type "%fname%" >>"%publicdest%\app.js"
|
||||
echo. >>"%publicdest%\app.js"
|
||||
echo }); >>"%publicdest%\app.js"
|
||||
|
||||
:EOF
|
||||
|
||||
35
webui-src/make-src/build.js
Normal file
35
webui-src/make-src/build.js
Normal file
@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('node:assert/strict');
|
||||
const path = require('node:path');
|
||||
const { spawnSync } = require('node:child_process');
|
||||
|
||||
const shellScript = path.join(__dirname, 'build.sh');
|
||||
const batchScript = path.join(__dirname, 'build.bat');
|
||||
|
||||
function getRunner(platform, commandShell = 'cmd.exe') {
|
||||
return platform === 'win32'
|
||||
? { command: commandShell, args: ['/d', '/c', batchScript] }
|
||||
: { command: 'sh', args: [shellScript] };
|
||||
}
|
||||
|
||||
function run(runner) {
|
||||
const result = spawnSync(runner.command, runner.args, { stdio: 'inherit' });
|
||||
if (result.error) {
|
||||
console.error(result.error.message);
|
||||
return 1;
|
||||
}
|
||||
return result.status ?? 1;
|
||||
}
|
||||
|
||||
if (process.argv[2] === '--check') {
|
||||
assert.equal(path.basename(getRunner('win32').args[2]), 'build.bat');
|
||||
assert.equal(path.basename(getRunner('linux').args[0]), 'build.sh');
|
||||
const status = process.platform === 'win32'
|
||||
? 0
|
||||
: run({ command: 'sh', args: ['-n', shellScript] });
|
||||
if (status === 0) console.log('Build dispatcher checks passed.');
|
||||
process.exitCode = status;
|
||||
} else {
|
||||
process.exitCode = run(getRunner(process.platform, process.env.ComSpec));
|
||||
}
|
||||
@ -3,9 +3,9 @@
|
||||
"version": "1.0.0",
|
||||
"description": "Retroshare's Web Interface",
|
||||
"scripts": {
|
||||
"watch": "rm ./styles.css && sass --watch --embed-sources --embed-source-map ./app/scss/main.scss ./styles.css",
|
||||
"build": "sass --no-source-map --style=compressed ./app/scss/main.scss ./styles.css && sh ./make-src/build.sh",
|
||||
"lint": "eslint app && node --check ../webui/app.js && sh -n make-src/build.sh && echo 'Lint checks passed.'"
|
||||
"watch": "sass --watch --embed-sources --embed-source-map ./app/scss/main.scss ./styles.css",
|
||||
"build": "sass --no-source-map --style=compressed ./app/scss/main.scss ./styles.css && node ./make-src/build.js",
|
||||
"lint": "eslint app && node --check ../webui/app.js && node ./make-src/build.js --check && echo Lint checks passed."
|
||||
},
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user