Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions run-command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
lstatSync,
copyFileSync,
rmSync,
renameSync,
existsSync,
} from 'node:fs';
import { dirname, join } from 'node:path';
Expand Down Expand Up @@ -122,15 +123,16 @@ commands: for (let i = 2; i < process.argv.length; i++)
}

case 'build': {
const dist = fileURLToPath(new URL('./views/dist', import.meta.url));
const distFinal = fileURLToPath(new URL('./views/dist', import.meta.url));
const dist = fileURLToPath(new URL('./views/dist-new', import.meta.url));
rmSync(dist, { force: true, recursive: true });
mkdirSync(dist);

/* The archive directory is excluded from this process, since source
* rewrites are not intended to be used by any of those files.
* Assets are compiled separately, before the rest of the files.
*/
const ignoredDirectories = ['dist', 'assets', 'uv', 'scram', 'archive'];
const ignoredDirectories = ['dist', 'dist-new', 'assets', 'uv', 'scram', 'archive'];
const ignoredFileTypes = /\.map$/;

const compile = (
Expand All @@ -153,7 +155,7 @@ commands: for (let i = 2; i < process.argv.length; i++)
const fileStats = lstatSync(oldLocation),
targetPath = fileURLToPath(
new URL(
'./views/dist/' +
'./views/dist-new/' +
outDir +
(base + dir + '/').slice(initialDir.length + 1) +
((!config.usingSEO && flatAltPaths['files/' + file]) || file),
Expand All @@ -179,8 +181,14 @@ commands: for (let i = 2; i < process.argv.length; i++)

const localAssetDirs = ['assets', 'scram', 'uv'];
for (const path of localAssetDirs) {
mkdirSync('./views/dist/' + path);
compile('./views/' + path, '', path + '/', './views/' + path, true);
mkdirSync('./views/dist-new/' + path);
compile(
'./views/' + path,
'',
path + '/',
'./views/' + path,
path !== 'scram'
);
}

// Combine scripts from the corresponding node modules into the same
Expand All @@ -195,7 +203,7 @@ commands: for (let i = 2; i < process.argv.length; i++)
};
for (const path of Object.entries(compilePaths)) {
const prefix = path[0] + '/',
prefixUrl = new URL('./views/dist/' + prefix, import.meta.url);
prefixUrl = new URL('./views/dist-new/' + prefix, import.meta.url);
if (!existsSync(prefixUrl)) mkdirSync(prefixUrl);

compile(path[1].slice(path[1].indexOf('node_modules')), '', prefix);
Expand All @@ -205,11 +213,9 @@ commands: for (let i = 2; i < process.argv.length; i++)
if (config.minifyScripts)
await build({
entryPoints: [
'./views/dist/uv/**/*.js',
'./views/dist/scram/**/*.js',
'./views/dist/scram/**/*.wasm.wasm',
'./views/dist/assets/js/**/*.js',
'./views/dist/assets/css/**/*.css',
'./views/dist-new/uv/**/*.js',
'./views/dist-new/assets/js/**/*.js',
'./views/dist-new/assets/css/**/*.css',
],
platform: 'browser',
sourcemap: true,
Expand All @@ -224,13 +230,13 @@ commands: for (let i = 2; i < process.argv.length; i++)
compile('./views');

// Compile the archive directory separately.
mkdirSync('./views/dist/archive');
mkdirSync('./views/dist-new/archive');
if (existsSync('./views/archive'))
compile('./views/archive', '', 'archive/');

const createFile = (location, text) => {
writeFileSync(
fileURLToPath(new URL('./views/dist/' + location, import.meta.url)),
fileURLToPath(new URL('./views/dist-new/' + location, import.meta.url)),
paintSource(loadTemplates(text))
);
};
Expand Down Expand Up @@ -262,11 +268,14 @@ commands: for (let i = 2; i < process.argv.length; i++)
await compress(fileLocation, true);
}
};
await compress('./views/dist');
await compress('./views/dist/pages', true);
await compress('./views/dist/archive', true);
await compress('./views/dist-new');
await compress('./views/dist-new/pages', true);
await compress('./views/dist-new/archive', true);
}

rmSync(distFinal, { force: true, recursive: true });
renameSync(dist, distFinal);

break;
}

Expand Down Expand Up @@ -319,7 +328,7 @@ commands: for (let i = 2; i < process.argv.length; i++)
);
else
exec(
'npx pm2 delete ecosystem.config.js; pkill node',
'npx pm2 kill; pkill -f "node backend.js" || true',
(error, stdout) => {
console.log('[Kill]', stdout);
}
Expand Down