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


##########
build/scripts/process_build.ts:
##########
@@ -18,39 +18,98 @@
 // @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 path = require('path')
+const glob = require('glob')
 const execSync = require('child_process').execSync
+const pkg_dir = 'dist/package'
+var fileCount = 0
 
-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}`)
+      fileCount++
+    }
+  })
+}
+
+function getDir(file) {
+  return file
+    .split('/')
+    .slice(0, file.split('/').length - 1)
+    .join('/')
+}
+
+function fileCopy(srcPath, destPath) {
+  if (fs.statSync(srcPath).isFile()) {
+    fs.copyFileSync(srcPath, destPath)
+  }
+}
+
+function create_package() {
+  // wait to run these commands till all files have been copied
+  while (fileCount < fs.readdirSync(pkg_dir).length) {
+    execSync('yarn install', { cwd: pkg_dir })
+    execSync('yarn package --out ../../', { cwd: pkg_dir })
+  }
 }
 
-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 build_package() {
+  if (fs.existsSync(pkg_dir)) {
+    fs.rmdirSync(pkg_dir, { recursive: true })
   }
 
-  if (
-    fs.readFileSync('build/bin.NOTICE').toString() ===
-    fs.readFileSync('NOTICE').toString()
-  ) {
-    execSync('git checkout NOTICE')
+  fs.mkdirSync(pkg_dir)
+
+  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).trim()
+
+    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}`)
+      fileCount++
+    }
   }
+
+  // Copy ignore file
+  fileCopy('build/package/.vscodeignore', `${pkg_dir}/.vscodeignore`)
+
+  // Copy required package files into package directory
+  copyGlob('build/package/{.,}*', true)
+
+  // Copy node_modules into package directory
+  copyGlob('node_modules/{.,}**/{.,}*')

Review Comment:
   So it would be one or the other. I think I just forgot to remove one. I will 
remove yarn install.



-- 
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