|
21 | 21 | // but with some TypeScript niceness baked in
|
22 | 22 | const fs = require('fs')
|
23 | 23 | const path = require('path')
|
24 |
| -const glob = require('glob') |
25 | 24 | const execSync = require('child_process').execSync
|
26 | 25 | const pkg_dir = 'dist/package'
|
27 | 26 | const pkg_version = JSON.parse(fs.readFileSync('./package.json').toString())[
|
28 | 27 | 'version'
|
29 | 28 | ]
|
30 | 29 |
|
31 |
| -function copyDirectory(srcDir, destDir) { |
| 30 | +function copyFiles(srcDir, destDir, extension = '') { |
32 | 31 | // Ensure that the destination directory exists
|
33 | 32 | if (!fs.existsSync(destDir)) {
|
34 | 33 | fs.mkdirSync(destDir, { recursive: true })
|
35 | 34 | }
|
36 | 35 |
|
37 |
| - // Loop through each file or directory |
38 |
| - fs.readdirSync(srcDir, { withFileTypes: true }).forEach((file) => { |
39 |
| - // Construct the full path of the file or directory |
40 |
| - const srcPath = path.join(srcDir, file.name) |
41 |
| - const destPath = path.join(destDir, file.name) |
| 36 | + fs.readdirSync(srcDir).forEach((file) => { |
| 37 | + const srcPath = path.join(srcDir, file) |
| 38 | + const destPath = path.join(destDir, file) |
42 | 39 |
|
43 |
| - if (file.isDirectory()) { |
44 |
| - // If the file is a directory, recursively call this function on the directory |
45 |
| - copyDirectory(srcPath, destPath) |
46 |
| - } else { |
47 |
| - // If the file is a file, copy it to the destination directory |
| 40 | + if (fs.statSync(srcPath).isDirectory()) { |
| 41 | + copyFiles(srcPath, destPath, extension) |
| 42 | + } else if (extension.length === 0 || file.endsWith(extension)) { |
48 | 43 | fs.copyFileSync(srcPath, destPath)
|
49 | 44 | }
|
50 | 45 | })
|
51 | 46 | }
|
52 | 47 |
|
53 |
| -function copyGlob(pattern, destDir = pkg_dir, dir = '.') { |
54 |
| - glob(pattern, { cwd: dir }, (error, files) => { |
55 |
| - for (let i = 0; i < files.length; i++) { |
56 |
| - const src = path.join(dir, files[i]) |
57 |
| - const dst = path.join(destDir, path.parse(files[i]).base) |
58 |
| - const dstDir = path.dirname(dst) |
59 |
| - |
60 |
| - fs.mkdirSync(dstDir, { recursive: true }) |
61 |
| - |
62 |
| - if (fs.statSync(src).isFile()) { |
63 |
| - fs.copyFileSync(src, dst) |
64 |
| - } |
65 |
| - } |
66 |
| - }) |
67 |
| -} |
68 |
| - |
69 | 48 | // Setup package directory
|
70 | 49 | function setup() {
|
71 | 50 | if (fs.existsSync(pkg_dir)) {
|
72 | 51 | fs.rmSync(pkg_dir, { recursive: true, force: true })
|
73 | 52 | }
|
74 | 53 |
|
75 |
| - fs.mkdirSync(pkg_dir, { recursive: true }) |
76 |
| - |
77 |
| - copyGlob(path.join('src', '*.d.ts')) |
78 |
| - copyGlob(path.join('src', '*.js')) |
79 |
| - copyGlob(path.join('out', '*')) |
| 54 | + // Copy generated files to the package directory |
| 55 | + copyFiles('src', pkg_dir, '.d.ts') |
| 56 | + copyFiles('src', pkg_dir, '.js') |
| 57 | + copyFiles('out', pkg_dir) |
80 | 58 |
|
81 | 59 | // Copy the server directory to the package directory
|
82 |
| - copyDirectory( |
| 60 | + copyFiles( |
83 | 61 | `omega-edit-grpc-server-${pkg_version}`,
|
84 | 62 | path.join(pkg_dir, `omega-edit-grpc-server-${pkg_version}`)
|
85 | 63 | )
|
|
0 commit comments