From c46361eb475daa41f6ac78ec8c6fa600d04755e2 Mon Sep 17 00:00:00 2001 From: Bronley Plumb Date: Tue, 23 Jan 2024 15:02:11 -0500 Subject: [PATCH 1/3] Convert install-local to ts --- scripts/{install-local.js => install-local.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/{install-local.js => install-local.ts} (100%) diff --git a/scripts/install-local.js b/scripts/install-local.ts similarity index 100% rename from scripts/install-local.js rename to scripts/install-local.ts From 43d8bebe2eabbe1e9b2cfc7678d1dd773504a596 Mon Sep 17 00:00:00 2001 From: Bronley Plumb Date: Tue, 23 Jan 2024 15:02:40 -0500 Subject: [PATCH 2/3] Improve install-local script --- package.json | 2 +- scripts/install-local.ts | 251 ++++++++++++++++++++++++--------------- 2 files changed, 159 insertions(+), 94 deletions(-) diff --git a/package.json b/package.json index b50d1625..eebd7bbf 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "package-local": "node scripts/package-local.js", "publish": "vsce publish", "clean": "rimraf dist", - "install-local": "node scripts/install-local.js", + "install-local": "npm i && ts-node scripts/install-local.ts", "install-pull-local": "node scripts/install-local.js --pull", "uninstall-local": "node scripts/uninstall-local.js", "build-docs": "statigen -s docs -o .tmp/docs", diff --git a/scripts/install-local.ts b/scripts/install-local.ts index 1436f2ba..1b225b53 100644 --- a/scripts/install-local.ts +++ b/scripts/install-local.ts @@ -2,109 +2,174 @@ * Installs a local version of all the rokucommunity dependent packages into this project */ -let path = require('path'); -let childProcess = require('child_process'); - -//run `npm install` first before the rest of this script -childProcess.execSync('npm install', { - cwd: path.normalize(path.join(__dirname, '../')), - stdio: 'inherit' -}); - -let fsExtra = require('fs-extra'); -let chalk = require('chalk'); - -let argv = require('yargs').argv; - -let packages = [ - 'roku-debug', - 'roku-deploy', - 'brighterscript', - 'brighterscript-formatter' -]; - -//set the cwd to the root of this project -let thisProjectRootPath = path.join(__dirname, '..'); -process.chdir(thisProjectRootPath); -let packageJson = JSON.parse(fsExtra.readFileSync('package.json').toString()); - -for (let packageName of packages) { - printHeader(packageName); - let packageSrcPath = path.resolve(path.join('..', packageName)); - - //if the project doesn't exist, clone it from github - if (!fsExtra.pathExistsSync(packageSrcPath)) { - console.log(`Cloning '${packageName}' from github`); - //clone the project - childProcess.execSync(`git clone https://github.com/rokucommunity/${packageName}`, { - cwd: path.resolve('..'), - stdio: 'inherit' - }); - //if --pull was provided, fetch and pull latest for each repo - } else if (argv.pull === true) { - console.log(`'${packageName}' exists. Getting latest`); - - childProcess.execSync(`git fetch && git pull`, { - cwd: packageSrcPath, - stdio: 'inherit' - }); +import * as path from 'path'; +import * as childProcess from 'child_process'; +import * as fsExtra from 'fs-extra'; +import * as chalk from 'chalk'; +//path to the parent folder where all of the rokucommunity projects reside (i.e. 1 level above vscode-brightscript-language +const cwd = path.normalize(`${__dirname}/../../`); + +const pull = process.argv.includes('--pull'); +const enableVerboseLogging = process.argv.includes('--verbose'); + +class InstallLocalRunner { + + public run() { + for (const project of this.projects) { + this.installProject(project.name); + } + //create a symlink of the workspace file at the root + try { + if (!fsExtra.pathExistsSync(`${cwd}/workspace.code-workspace`)) { + console.log(`Creating hardlink for 'workspace.code-workspace'`); + fsExtra.linkSync(`${cwd}/vscode-brightscript-language/workspace.code-workspace`, `${cwd}/workspace.code-workspace`); + } + } catch (e) { + console.error(e); + } + console.log('Done!'); } - //install all npm dependencies - console.log(`Installing npm packages for '${packageName}'`); - try { - childProcess.execSync(`npm install`, { - cwd: path.resolve('..', packageName), - stdio: 'inherit' - }); - } catch (e) { - console.error(e); + private projects: Project[] = [ + { + name: 'roku-deploy', + dependencies: [] + }, + { + name: 'brighterscript', + dependencies: [ + 'roku-deploy' + ] + }, + { + name: 'brighterscript-formatter', + dependencies: [ + 'brighterscript' + ] + }, + { + name: 'roku-debug', + dependencies: [ + 'roku-deploy', + 'brighterscript' + ] + }, + { + name: 'vscode-brightscript-language', + dependencies: [ + 'roku-deploy', + 'brighterscript', + 'roku-debug', + 'brighterscript-formatter' + ] + } + ]; + + private getProject(name: string) { + return this.projects.find(x => x.name === name)!; } - console.log(`bulding '${packageName}'`); - //build the project - try { - childProcess.execSync(`npm run build`, { - cwd: path.resolve('..', packageName), - stdio: 'inherit' - }); - } catch (e) { - console.error(e); + private installProject(projectName: string) { + const project = this.getProject(projectName); + + function log(...args: any[]) { + let projectName = `${chalk.blue(project.name)}:`; + if (args[0] === '\n') { + projectName = args.shift() + projectName; + } + console.log(projectName, ...args); + } + + if (project.processed) { + log('already processed...skipping'); + return; + } + + this.printHeader(project.name); + let projectDir = `${cwd}/${project.name}`; + + //if the project doesn't exist, clone it from github + if (!fsExtra.pathExistsSync(projectDir)) { + this.execSync(`git clone https://github.com/rokucommunity/${project.name}`); + + //if --pull was provided, fetch and pull latest for each repo + } else if (pull === true) { + log(`project directory exists so fetching latest from github`); + + this.execSync(`git fetch && git pull`, { cwd: projectDir }); + } + + //install all npm dependencies + log(`installing npm packages`); + try { + this.execSync(`npm install`, { cwd: projectDir }); + } catch (e) { + console.error(e); + } + + //ensure all dependencies are installed + for (const dependency of project.dependencies) { + log('\n', `installing dependency ${chalk.blue(dependency)}`); + this.installProject(dependency); + + log(`deleting ${chalk.green(`./node_modules/${dependency}`)} to prevent contention`); + try { + fsExtra.removeSync(`node_modules/${project.name}`); + } catch (e) { + console.error(e); + } + log(`linking ${chalk.green(`../${dependency}`)} to ${chalk.green(`./node_modules/${dependency}`)}`); + //install local version of the dependency into this project + this.execSync(`npm install file:../${dependency}`, { cwd: projectDir }); + } + + log('\n', `building`); + //build the project + try { + this.execSync(`npm run build`, { cwd: projectDir }); + } catch (e) { + console.error(e); + } + + project.processed = true; } - console.log(`deleting '${packageName}' from node_modules to prevent contention`); - try { - fsExtra.ensureDirSync(`node_modules/${packageName}`); - fsExtra.removeSync(`node_modules/${packageName}`); - } catch (e) { - console.error(e); - } - - console.log(`adding '../${packageName}' to package.json`); - packageJson.dependencies[packageName] = `file:../${packageName}`; -} - -printHeader('vscode-brightscript-language'); -console.log('saving package.json changes'); -fsExtra.writeFileSync('package.json', JSON.stringify(packageJson, null, 4)); -console.log('npm install'); -childProcess.execSync('npm install', { - stdio: 'inherit' -}); + private printHeader(name) { + const length = 80; + let text = '\n'; + text += ''.padStart(length, '-') + '\n'; + let leftLen = Math.round((length / 2) - (name.length / 2)); + let rightLen = 80 - (name.length + leftLen); + text += ''.padStart(leftLen, '-') + chalk.white(name) + ''.padStart(rightLen, '-') + '\n'; -function printHeader(name) { - var length = 80; - let text = '\n'; + text += ''.padStart(length, '-') + '\n'; - text += ''.padStart(length, '-') + '\n'; + console.log(chalk.blue(text)); + } - let leftLen = Math.round((length / 2) - (name.length / 2)); - let rightLen = 80 - (name.length + leftLen); - text += ''.padStart(leftLen, '-') + chalk.white(name) + ''.padStart(rightLen, '-') + '\n'; + private execSync(command: string, options?: childProcess.ExecSyncOptions) { + options = { + cwd: cwd, + stdio: enableVerboseLogging ? 'inherit' : 'ignore', + ...options ?? {} + }; + if (enableVerboseLogging) { + console.log(command, options); + } + try { + return childProcess.execSync(command, options); + } catch (e) { + console.error(e); + } + } +} - text += ''.padStart(length, '-') + '\n'; +interface Project { + name: string; + dependencies: string[]; + processed?: boolean; +} - console.log(chalk.blue(text)); -} \ No newline at end of file +new InstallLocalRunner().run(); From 5ec089df8e9863ce1f843de6527cd98c176e4bf0 Mon Sep 17 00:00:00 2001 From: Bronley Plumb Date: Tue, 23 Jan 2024 16:13:22 -0500 Subject: [PATCH 3/3] Run watch-all projects in order --- scripts/watch-all.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/scripts/watch-all.ts b/scripts/watch-all.ts index c739b42d..c07862e3 100644 --- a/scripts/watch-all.ts +++ b/scripts/watch-all.ts @@ -25,18 +25,29 @@ logger.writeLine(`${timestamp()} Starting compilation in watch mode...`); //run watch tasks for every related project, in a single output window so we don't have 7 console tabs open const projects = [{ - name: 'brighterscript' + name: 'roku-deploy', + dependencies: [] }, { - name: 'roku-deploy' + name: 'brighterscript', + dependencies: [ + 'roku-deploy' + ] }, { - name: 'roku-debug' + name: 'brighterscript-formatter', + dependencies: [ + 'brighterscript' + ] }, { - name: 'brighterscript-formatter' + name: 'roku-debug', + dependencies: [ + 'roku-deploy', + 'brighterscript' + ] }, { name: path.basename(path.resolve(__dirname, '..')), dependencies: [ - 'brighterscript', 'roku-deploy', + 'brighterscript', 'roku-debug', 'brighterscript-formatter' ]