Skip to content

Commit

Permalink
Meep script refactor (#69)
Browse files Browse the repository at this point in the history
* Moved the AutoConst transform to a separate file to prep for DriveBase consumption
* Moved everything into a Closure because Javascript classes are terrible
* Added some comments, stopped splitting, then joining after comment removal
* Tweaked stuff for the flip tool a bit
* Got the toVec() -> vec() change from a different diff
  • Loading branch information
kevinfrei authored Nov 14, 2024
1 parent 3887756 commit 2f5c151
Show file tree
Hide file tree
Showing 7 changed files with 3,619 additions and 517 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"- // i+": "",
"- // i.": " The '../' before the scripts line is because it's called from MeepMeepTesting directory",
"meep": "bun run ../scripts/preprocessor.ts",
"testmeep": "bun run scripts/preprocessor.ts /Users/freik/src/ftc/CenterStage2023/MeepMeepTesting/build '[/Users/freik/src/ftc/CenterStage2023/Sixteen750/src/main/java/org/firstinspires/ftc/sixteen750/AutoConstants.java, /Users/freik/src/ftc/CenterStage2023/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/opmodes/BasicAuto.java, /Users/freik/src/ftc/CenterStage2023/MeepMeepTesting/src/main/java/com/example/meepmeeptesting/AutoConstantsBlue.java, /Users/freik/src/ftc/CenterStage2023/MeepMeepTesting/src/main/java/com/example/meepmeeptesting/AutoConstantsRed.java, /Users/freik/src/ftc/CenterStage2023/RoadRunnerQuickStart/src/main/java/org/firstinspires/ftc/teamcode/drive/opmode/AutomaticFeedforwardTuner.java, /Users/freik/src/ftc/CenterStage2023/Twenty403/src/main/java/org/firstinspires/ftc/twenty403/AutoConstants.java]'",
"testmeep": "bun run scripts/preprocessor.ts ./MeepMeepTesting/build/test TEST_CLASS ./Sixteen750/src/main/java/org/firstinspires/ftc/sixteen750/AutoConstants.java ./Sixteen750/src/main/java/org/firstinspires/ftc/sixteen750/subsystems/DrivebaseSubsystem.java",
"- // j-": "",
"- // j ": "This is the script that presents the students with a workflow",
"work": "bun run scripts/workflow.ts",
Expand Down
64 changes: 30 additions & 34 deletions scripts/flip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,42 @@ import { argv } from 'process';
const { readFile, writeFile } = promises;

type FileList = {
name: string;
key: string;
files: string[];
};

const technoLib: FileList = {
key: 'TechnoLibLocal',
files: [
'LearnBot/build.gradle',
'Sixteen750/build.gradle',
'Twenty403/build.gradle',
'build.dependencies.gradle',
'settings.gradle',
],
};
const botList: FileList = {
key: 'BUILD ALL BOTS',
files: ['settings.gradle', 'build.gradle'],
};
const meepList: FileList = {
key: 'MeepMeepLocal',
files: ['MeepMeepTesting/build.gradle', 'settings.gradle'],
};
// This is a map of keys (the argument to call flip.js with) to objects that
// are a name (the tag at the end of the comment) and an array of files to
// scan & process
const fileList = new Map<string, FileList>([
[
'lib',
{
name: 'TechnoLibLocal',
files: [
'LearnBot/build.gradle',
'Sixteen750/build.gradle',
'Twenty403/build.gradle',
'build.dependencies.gradle',
'settings.gradle',
],
},
],
[
'bot',
{ name: 'BUILD ALL BOTS', files: ['settings.gradle', 'build.gradle'] },
],
[
'meepmeep',
{
name: 'MeepMeepLocal',
files: [
'MeepMeepTesting/build.gradle',
'settings.gradle',
]
}
]
['lib', technoLib],
['bot', botList],
['meepmeep', meepList],
['meep', meepList],
]);

// For any line that ends with '// FLIP: id',
// toggle the line comment 'status'
function toggleLine(lineFull: string, str: string) {
const commentMarker = '// FLIP: ' + str;
function toggleLine(lineFull: string, id: string) {
const commentMarker = '// FLIP: ' + id;
const line = lineFull.trimEnd();
// If the line doesn't end with the comment marker, don't change it at all
if (!line.endsWith(commentMarker)) {
Expand All @@ -80,11 +76,11 @@ function toggleLine(lineFull: string, str: string) {
}

// Read the file, flip the comments for lines with markers, the write it back
async function toggleFile(file: string, str: string) {
async function toggleFile(file: string, key: string) {
try {
const contents = await readFile(file, 'utf-8');
const resultArray = contents.split('\n');
const toggled = resultArray.map((elem) => toggleLine(elem, str));
const toggled = resultArray.map((elem) => toggleLine(elem, key));
await writeFile(file, toggled.join('\n'));
} catch (e) {
// Some file access problem :(
Expand All @@ -100,9 +96,9 @@ async function toggleLinesWithComments(arg: string) {
'This script only understands :' + [...fileList.keys()].join(', '),
);
}
let { name: str, files } = elem;
let { key, files } = elem;
for (let filename of files) {
await toggleFile(filename, str);
await toggleFile(filename, key);
}
}

Expand Down
Loading

0 comments on commit 2f5c151

Please sign in to comment.