Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the install-local and watch-all scripts #541

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
110 changes: 0 additions & 110 deletions scripts/install-local.js

This file was deleted.

175 changes: 175 additions & 0 deletions scripts/install-local.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/**
* Installs a local version of all the rokucommunity dependent packages into this project
*/

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!');
}

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)!;
}

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

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

text += ''.padStart(length, '-') + '\n';

console.log(chalk.blue(text));
}

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);
}
}
}

interface Project {
name: string;
dependencies: string[];
processed?: boolean;
}

new InstallLocalRunner().run();
21 changes: 16 additions & 5 deletions scripts/watch-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
Expand Down