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

Meep script refactor #69

Merged
merged 5 commits into from
Nov 14, 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 @@ -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
Loading