-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathprepare-dist-for-dev.js
40 lines (30 loc) · 1.58 KB
/
prepare-dist-for-dev.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import * as fs from 'fs';
import path from 'path';
/**
* When doing dev for Tidy 5e Sheets, the style CSS file is ignored, and the main JS file is proxied in by the vite proxy server.
*
* That leaves the static files such as templates, images, lang files, and the module JSON file.
*
* For a plug-and-play dev experience, this script prepares the dist folder with the minimum static files needed and relies on the dev server to take over the rest.
*
* Additionally, when a developer is updating templates, localization data, or any other static file, this small amount of time spent copying to the dist folder makes the feedback loop much shorter in the long run.
*/
function prepareDistForDev() {
const distFolder = './dist';
// Remove the dist folder and all its files, if present
if (fs.existsSync(distFolder)) {
fs.rmSync(distFolder, { recursive: true, force: true });
}
// Ensure the dist folder exists
fs.mkdirSync(distFolder);
const publicFolder = './public';
// Copy all of the public folder contents to dist
fs.cpSync(publicFolder, distFolder, { recursive: true });
// Put empty tidy5e-sheet.js and tidy5e-sheet.css files in place
const message =
'Hello, Tidy 5e dev 👋. This file exists so that foundry is happy and will consider the module eligible to load up. The vite server proxy will do the rest.';
fs.writeFileSync(path.join(distFolder, 'tidy5e-sheet.js'), `// ${message}`);
fs.writeFileSync(path.join(distFolder, 'tidy5e-sheet.css'), `/* ${message} */`);
fs.writeFileSync(path.join(distFolder, 'tidy5e-sheet.lock'), "🔒");
}
prepareDistForDev();