Shanedell commented on code in PR #232:
URL: https://github.com/apache/daffodil-vscode/pull/232#discussion_r923979020


##########
build/scripts/process_build.ts:
##########
@@ -18,39 +18,83 @@
 // @ts-nocheck <-- This is needed as this file is basically a JavaScript script
 //                 but with some TypeScript niceness baked in
 const fs = require('fs')
-const execSync = require('child_process').execSync
+const path = require('path')
+const glob = require('glob')
+const pkg_dir = 'dist/package'
 
-function prebuild() {
-  fs.renameSync('LICENSE', 'tmp.LICENSE')
-  fs.renameSync('NOTICE', 'tmp.NOTICE')
-  fs.copyFileSync('build/bin.NOTICE', 'NOTICE')
-  fs.copyFileSync('build/bin.LICENSE', 'LICENSE')
+function copyGlob(pattern, skipDirectory = false) {
+  glob(pattern, (error, files) => {
+    for (var i = 0; i < files.length; i++) {
+      let file = !skipDirectory
+        ? files[i]
+        : files[i].split('/')[files[i].split('/').length - 1]
+
+      let directory = path.join(pkg_dir, getDir(file))
+
+      if (!fs.existsSync(directory)) {
+        fs.mkdirSync(directory, { recursive: true })
+      }
+
+      fileCopy(file, `${pkg_dir}/${file}`)
+    }
+  })
+}
+
+function getDir(file) {
+  return file
+    .split('/')
+    .slice(0, file.split('/').length - 1)
+    .join('/')
 }
 
-function postbuild() {
-  fs.rmSync('LICENSE')
-  fs.rmSync('NOTICE')
-  fs.renameSync('tmp.LICENSE', 'LICENSE')
-  fs.renameSync('tmp.NOTICE', 'NOTICE')
-
-  // This will make sure that if the root LICENSE and NOTICE are the same as 
the build LICENSE
-  // and NOTICE that they are reverted back to their original contents.
-  if (
-    fs.readFileSync('build/bin.LICENSE').toString() ===
-    fs.readFileSync('LICENSE').toString()
-  ) {
-    execSync('git checkout LICENSE')
+function fileCopy(srcPath, destPath) {
+  if (fs.statSync(srcPath).isFile()) {
+    fs.copyFileSync(srcPath, destPath)
   }
+}
+
+function setup_package() {
+  if (fs.existsSync(pkg_dir)) {
+    fs.rmdirSync(pkg_dir, { recursive: true })
+  }
+
+  fs.mkdirSync(pkg_dir)
 
-  if (
-    fs.readFileSync('build/bin.NOTICE').toString() ===
-    fs.readFileSync('NOTICE').toString()
-  ) {
-    execSync('git checkout NOTICE')
+  let lines = fs
+    .readFileSync('build/package/.vscodeignore')
+    .toString()
+    .split('\n')
+
+  // Copy all files listed in the .vscodeignore
+  for (var i = 0; i < lines.length; i++) {
+    var line = lines[i]
+
+    if (!line.startsWith('!')) continue
+
+    let pattern = line.substring(1)
+
+    if (pattern.includes('*')) {
+      copyGlob(pattern)
+    } else {
+      let file = pattern
+      let directory = getDir(file)
+
+      fs.mkdirSync(`${pkg_dir}/${directory}`, { recursive: true })
+
+      fileCopy(file, `${pkg_dir}/${file}`)
+    }
   }
+
+  // Copy ignore file
+  fileCopy('build/package/.vscodeignore', `${pkg_dir}/.vscodeignore`)
+
+  // Copy required package files into package directory
+  copyGlob('build/package/*', true)

Review Comment:
   Yeah so this update must have just missed you. I have `{.,}*` which makes it 
check for any hidden files



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to