-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtsup.config.ts
84 lines (71 loc) · 2.81 KB
/
tsup.config.ts
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { defineConfig, build } from 'tsup';
import * as fs from "fs";
import path from 'path';
import * as cp from 'child_process';
export default defineConfig({
entry: ['src/index.ts'],
clean: true,
dts: true,
sourcemap: true,
format: ['cjs', 'esm'],
external: ["color-convert", "color-temperature"],
onSuccess: async () =>
{
//? Build all the ts files and pop em in the dist/node-red folder
//* Bundling is disabled to be able to use html and other stuff
var fileArray = []
var files = fs.readdirSync("./src/node-red/").filter((val)=> val.endsWith(".ts"))
files.forEach((file)=>{
fileArray.push("./src/node-red/" + file)
})
await build({
entry: fileArray,
clean: true,
skipNodeModulesBundle: true,
outDir: "dist/node-red",
config: false,
bundle: false,
tsconfig: "./tsconfig.red.json"
}).catch((reason) =>
{
console.log(reason);
});
//? Get all HTML files and copy them to the same folder
var HTMLfiles = fs.readdirSync("./src/node-red/html/").filter((file)=> file.endsWith(".html"))
HTMLfiles.forEach((htmlFile)=>{
fs.copyFileSync("./src/node-red/html/" + htmlFile, "./dist/node-red/" + htmlFile)
})
//* Copy the icons folder
//? Could not use fs, bc of "operation not permitted"
// copyFolderRecursiveSync("./src/node-red/html/assets", "./dist/node-red/")
if (!fs.existsSync("./dist/node-red/icons")) {
fs.mkdirSync("./dist/node-red/icons")
}
cp.exec(`xcopy "${fs.realpathSync("./src/node-red/html/icons").replaceAll("\\", "/")}" "${fs.realpathSync("./dist/node-red/icons").replaceAll("\\", "/")}" /K /D /H /Y`)
.on("message", console.log)
.on("error", console.error)
// Copy the dgramTest.js
fs.copyFileSync("./src/dgramTest.js", "./dist/dgramTest.js")
}
});
//* https://stackoverflow.com/a/26038979
// function copyFolderRecursiveSync( source, target ) {
// var files = [];
// // Check if folder needs to be created or integrated
// var targetFolder = path.join( target, path.basename( source ) );
// if ( !fs.existsSync( targetFolder ) ) {
// fs.mkdirSync( targetFolder );
// }
// // Copy
// if ( fs.lstatSync( source ).isDirectory() ) {
// files = fs.readdirSync( source );
// files.forEach( function ( file ) {
// var curSource = path.join( source, file );
// if ( fs.lstatSync( curSource ).isDirectory() ) {
// copyFolderRecursiveSync( curSource, targetFolder );
// } else {
// fs.copyFileSync( curSource, targetFolder );
// }
// } );
// }
// }