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
|
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`.
|
Commit SCSS changes together with the regenerated `webui-src/styles.css`.
|
||||||
`qmake .` packages that committed CSS but does not compile SCSS. Running
|
`qmake .` packages that committed CSS but does not compile SCSS. Running
|
||||||
`make` alone does not rebuild this `TEMPLATE = subdirs` project; rerun
|
`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
|
Before submitting, run the full build and lint commands, then point
|
||||||
RetroShare's **Web interface directory** at `webui/` and manually test the
|
RetroShare's **Web interface directory** at `webui/` and manually test the
|
||||||
affected screens. ESLint, generated JavaScript syntax, and shell syntax are
|
affected screens. ESLint, generated JavaScript syntax, the build dispatcher,
|
||||||
checked by `npm run lint`; no formatting script is defined.
|
and shell syntax on non-Windows systems are checked by `npm run lint`; no
|
||||||
|
formatting script is defined.
|
||||||
|
|
||||||
### References
|
### References
|
||||||
|
|
||||||
|
|||||||
@ -5,55 +5,58 @@ setlocal enabledelayedexpansion
|
|||||||
|
|
||||||
echo "### Starting WebUI build ###"
|
echo "### Starting WebUI build ###"
|
||||||
|
|
||||||
set src=%~dp0..\..\webui-src
|
set "src=%~dp0..\..\webui-src"
|
||||||
|
|
||||||
rem Output destination
|
rem Output destination
|
||||||
if "%~1"=="" (
|
if "%~1"=="" (
|
||||||
set publicdest=%~dp0..\..\webui
|
set "publicdest=%~dp0..\..\webui"
|
||||||
) else (
|
) 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%
|
echo creating %publicdest%
|
||||||
md %publicdest%
|
md "%publicdest%"
|
||||||
|
|
||||||
rem Make full path
|
rem Make full path
|
||||||
pushd %publicdest%
|
pushd "%publicdest%"
|
||||||
set publicdest=%cd%
|
set "publicdest=%cd%"
|
||||||
popd
|
popd
|
||||||
|
|
||||||
echo copying html file
|
echo copying html file
|
||||||
xcopy /s %src%\index.html %publicdest%
|
copy /Y "%src%\index.html" "%publicdest%\index.html" >nul
|
||||||
|
|
||||||
echo copying css file
|
echo copying css file
|
||||||
xcopy /s %src%\styles.css %publicdest%
|
copy /Y "%src%\styles.css" "%publicdest%\styles.css" >nul
|
||||||
|
|
||||||
echo building app.js
|
echo building app.js
|
||||||
echo - copying template.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 "basefolder=%cd%\"
|
||||||
set "lastsection="
|
set "lastsection="
|
||||||
for /R %%F in (*.js) do call :addfile-js "%basefolder%" "%%F"
|
for /R %%F in (*.js) do call :addfile-js "%basefolder%" "%%F"
|
||||||
popd
|
popd
|
||||||
|
|
||||||
echo copying assets folder
|
echo copying assets folder
|
||||||
xcopy /s %src%\assets\ %publicdest%
|
xcopy "%src%\assets\*" "%publicdest%\" /E /I /Y >nul
|
||||||
|
|
||||||
echo "### WebUI build complete ###"
|
echo "### WebUI build complete ###"
|
||||||
|
|
||||||
goto :EOF
|
goto :EOF
|
||||||
|
|
||||||
:addfile-js
|
:addfile-js
|
||||||
set basefolder=%~1
|
set "basefolder=%~1"
|
||||||
set fname=%~2
|
set "fname=%~2"
|
||||||
|
|
||||||
set registername=%~dpn2
|
set "registername=%~dpn2"
|
||||||
set registername=!registername:%basefolder%=!
|
set "registername=!registername:%basefolder%=!"
|
||||||
set registername=%registername:\=/%
|
set "registername=%registername:\=/%"
|
||||||
|
|
||||||
for /f "tokens=1,2 delims=/" %%A in ("!registername!") do (
|
for /f "tokens=1,2 delims=/" %%A in ("!registername!") do (
|
||||||
if "%%B"=="" (
|
if "%%B"=="" (
|
||||||
@ -64,9 +67,9 @@ for /f "tokens=1,2 delims=/" %%A in ("!registername!") do (
|
|||||||
set "lastsection=%%A"
|
set "lastsection=%%A"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
echo require.register("%registername%", function(exports, require, module) { >> %publicdest%\app.js
|
echo require.register("%registername%", function(exports, require, module) { >>"%publicdest%\app.js"
|
||||||
type %fname% >> %publicdest%\app.js
|
type "%fname%" >>"%publicdest%\app.js"
|
||||||
echo. >> %publicdest%\app.js
|
echo. >>"%publicdest%\app.js"
|
||||||
echo }); >> %publicdest%\app.js
|
echo }); >>"%publicdest%\app.js"
|
||||||
|
|
||||||
:EOF
|
: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",
|
"version": "1.0.0",
|
||||||
"description": "Retroshare's Web Interface",
|
"description": "Retroshare's Web Interface",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"watch": "rm ./styles.css && sass --watch --embed-sources --embed-source-map ./app/scss/main.scss ./styles.css",
|
"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 && sh ./make-src/build.sh",
|
"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 && sh -n make-src/build.sh && echo 'Lint checks passed.'"
|
"lint": "eslint app && node --check ../webui/app.js && node ./make-src/build.js --check && echo Lint checks passed."
|
||||||
},
|
},
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@ -33,7 +33,7 @@ WEBUI_SRC_CSS = $$PWD/webui-src/styles.css
|
|||||||
|
|
||||||
WEBUI_SRC_IMAGE = $$PWD/data/retroshare.svg
|
WEBUI_SRC_IMAGE = $$PWD/data/retroshare.svg
|
||||||
|
|
||||||
win32-g++ {
|
win32 {
|
||||||
isEmpty(QMAKE_SH) {
|
isEmpty(QMAKE_SH) {
|
||||||
# Windows native build
|
# Windows native build
|
||||||
WEBUI_SRC_SCRIPT = $$PWD/webui-src/make-src/build.bat
|
WEBUI_SRC_SCRIPT = $$PWD/webui-src/make-src/build.bat
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user