forked from unimatrix/web
Complete V2 sign-in, permission-aware navigation and retire the V1 shell
This commit is contained in:
parent
8881216e30
commit
81836613b4
4 changed files with 153 additions and 316 deletions
|
|
@ -4,7 +4,7 @@ import {BUTTON_CSS,BUTTON_SCRIPT} from './dune-buttons.mjs';
|
|||
const release=process.argv[2];if(!release)throw Error('Release directory required');
|
||||
const add=(html,local=false)=>{if(html.includes('/dune-actions.css'))return html;const base=local?'':'https://www.dunerealms.com';return html.replace('</head>','<link rel="stylesheet" href="'+base+'/dune-actions.css?v=1"><script src="'+base+'/dune-actions.js?v=1" defer></script></head>');};
|
||||
mkdirSync(release+'/web',{recursive:true});writeFileSync(release+'/web/dune-actions.css',BUTTON_CSS);writeFileSync(release+'/web/dune-actions.js',BUTTON_SCRIPT);
|
||||
const cp=release+'/control-panel/public/index.html';if(existsSync(cp))writeFileSync(cp,add(readFileSync(cp,'utf8')));
|
||||
const cp=release+'/control-panel/public/cp-v2/index.html';if(existsSync(cp))writeFileSync(cp,add(readFileSync(cp,'utf8')));
|
||||
if(!process.argv.includes('--source-only')){
|
||||
const worker=release+'/dist/server/index.js',text=readFileSync(worker,'utf8'),prefix='const ASSET_DATA=',end=text.indexOf(';\n');if(!text.startsWith(prefix)||end<0)throw Error('Unrecognised public asset bundle');
|
||||
const assets=JSON.parse(text.slice(prefix.length,end));assets['/dune-actions.css']=['text/css; charset=utf-8',Buffer.from(BUTTON_CSS).toString('base64')];assets['/dune-actions.js']=['text/javascript; charset=utf-8',Buffer.from(BUTTON_SCRIPT).toString('base64')];
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ for(const[key,extra]of [['/portal-navigation.js',RELEASE_SCRIPT],['/portal-navig
|
|||
const bump=s=>s.replace(/portal-navigation\.(js|css)\?v=hosting-9(?:-release-1002)?/g,'portal-navigation.$1?v=hosting-9-release-1002');
|
||||
for(const asset of Object.values(assets))if(asset[0].startsWith('text/html'))asset[1]=Buffer.from(bump(Buffer.from(asset[1],'base64').toString())).toString('base64');
|
||||
assets['/release.json']=['application/json; charset=utf-8',Buffer.from(JSON.stringify({version:RELEASE_VERSION,stage:'alpha',updatedAt:new Date().toISOString()})).toString('base64')];writeFileSync(file,prefix+JSON.stringify(assets)+before.slice(end));
|
||||
for(const path of [root+'/control-panel/public/index.html','/home/dunerealms/htdocs/clans.dunerealms.com/index.html','/home/dunerealms/apps/integrations/shared-header.php'])if(existsSync(path))writeFileSync(path,bump(readFileSync(path,'utf8')));
|
||||
for(const path of [root+'/control-panel/public/cp-v2/index.html','/home/dunerealms/htdocs/clans.dunerealms.com/index.html','/home/dunerealms/apps/integrations/shared-header.php'])if(existsSync(path))writeFileSync(path,bump(readFileSync(path,'utf8')));
|
||||
console.log('Alpha '+RELEASE_VERSION+' shared badge published; logo and runtime preserved');
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ export function deployCanonicalMenu({release,nativeRoot,backupDir,extraFiles=[]}
|
|||
const save=(file,content,key)=>{if(existsSync(file)){const old=readFileSync(file);if(old.equals(Buffer.from(content)))return;const backup=path.join(backupDir,key);mkdirSync(path.dirname(backup),{recursive:true});if(!existsSync(backup))writeFileSync(backup,old,{mode:0o600});}writeFileSync(file,content,{mode:0o644});changed.push(file);};
|
||||
const worker=path.join(release,'dist/server/index.js'),before=readFileSync(worker,'utf8'),prefix='const ASSET_DATA=',end=before.indexOf(';\n');if(!before.startsWith(prefix)||end<0)throw Error('Unknown asset bundle');const assets=JSON.parse(before.slice(prefix.length,end));if(!assets['/portal-navigation.js'])throw Error('No shared script');const script=withCanonicalMenu(Buffer.from(assets['/portal-navigation.js'][1],'base64').toString());assets['/portal-navigation.js'][1]=Buffer.from(script).toString('base64');let pages=0;for(const asset of Object.values(assets))if(asset[0].startsWith('text/html')){const old=Buffer.from(asset[1],'base64').toString(),next=canonicalHeaderHtml(old);if(next!==old){asset[1]=Buffer.from(next).toString('base64');pages++;}}
|
||||
const after=prefix+JSON.stringify(assets)+before.slice(end);save(worker,after,'worker.js');save(path.join(release,'web/portal-navigation.js'),script,'web-script.js');
|
||||
for(const file of[path.join(release,'control-panel/public/index.html'),path.join(release,'node/public/forums.html'),...extraFiles])if(existsSync(file))save(file,canonicalHeaderHtml(readFileSync(file,'utf8')),'templates/'+createHash('sha256').update(file).digest('hex')+'.html');
|
||||
for(const file of[path.join(release,'control-panel/public/cp-v2/index.html'),path.join(release,'node/public/forums.html'),...extraFiles])if(existsSync(file))save(file,canonicalHeaderHtml(readFileSync(file,'utf8')),'templates/'+createHash('sha256').update(file).digest('hex')+'.html');
|
||||
if(nativeRoot){save(path.join(nativeRoot,'shared-main-menu.html'),PORTAL_NAV,'shared-main-menu.html');for(const name of['shared-header.html','shared-header-head.html']){const file=path.join(nativeRoot,name);if(existsSync(file))save(file,canonicalHeaderHtml(readFileSync(file,'utf8')),name);}}
|
||||
const apiUnchanged=createHash('sha256').update(before.slice(end)).digest('hex')===createHash('sha256').update(after.slice(after.indexOf(';\n'))).digest('hex');if(!apiUnchanged)throw Error('Runtime tail changed');return{changed,pages,apiUnchanged};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import {existsSync, readFileSync,writeFileSync,copyFileSync} from 'node:fs';
|
|||
import {SHARED_HEADER,SHARED_HEAD,PORTAL_SCRIPT,PORTAL_CSS,CONTEXT_SCRIPT,CONTEXT_CSS} from './portal-navigation.mjs';
|
||||
const release=process.argv[2],integrations=process.argv[3];
|
||||
if(!release||!integrations)throw Error('Provide release and integration directories');
|
||||
const cp=release+'/control-panel/public/index.html';let html=readFileSync(cp,'utf8');
|
||||
const cp=release+'/control-panel/public/cp-v2/index.html';let html=readFileSync(cp,'utf8');
|
||||
html=html.replace(/<header\b[^>]*>[\s\S]*?<\/header>/,SHARED_HEADER);
|
||||
if(!html.includes('https://www.dunerealms.com/portal-navigation.js'))html=html.replace('</head>',SHARED_HEAD+'</head>');
|
||||
writeFileSync(cp,html);
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff