1- // standalone JS - needs Node.js installed; run with node <filename >
1+ // standalone JS - needs Node.js installed; run with node <thisfile >
22//
33// Idea here is to have a program that helps with creation of a new AIA
44// algorithm module. Reads in the algorithm name and an ID used internally
55// in code, filenames, etc. Output unix commands to create all the extra files
66// (currently copy the heapsort files; they will need to be edited for the
77// new algorithm), plus some snippets of code and indications of where to
88// put them so we can just edit a bunch of files and mostly copy+paste.
9+ // XXX It would be nice to be able to say what files to copy (not Heapsort)
10+ // but filenames are not really consistent enough currently.
911
1012const readline = require ( 'readline' ) ;
1113
@@ -20,7 +22,7 @@ const rl = readline.createInterface({
2022
2123let algName ;
2224let algID ;
23- let algCat = 'Sort' ; // XXX Need to input this also
25+ let algCat = 'Sort' ; // XXX Best input this also?
2426console . log ( "What's the name of your new algorithm used in menus etc, eg 2-3-4 Tree? " ) ;
2527
2628rl . on ( 'line' , ( line ) => {
@@ -29,6 +31,7 @@ rl.on('line', (line) => {
2931 console . log ( "What's the ID of your new algorithm used in code, eg tree_234? " ) ;
3032 } else {
3133 algID = line . trim ( ) ;
34+ // XXX Best check for alpha first char then alphanumeric + _ only
3235 doIt ( algName , algID ) ;
3336 process . exit ( 0 ) ;
3437 }
@@ -39,29 +42,72 @@ rl.on('close', () => {
3942 process . exit ( 0 ) ;
4043} ) ;
4144
45+ // let devBranch = "<development branch>"
46+ let devBranch = "2025_sem2"
4247
4348let doIt = ( algName , algID ) => {
4449 console . log ( "" ) ;
45- console . log ( "To add algorithm named " + algName + " with ID " + algID + ":" ) ;
50+ console . log ( "Guide to adding algorithm named " + algName + " with ID " + algID ) ;
51+ console . log ( "(best save this in a file and keep track of your progress)" ) ;
52+ console . log ( "" ) ;
4653 console . log ( "Execute the following commands from the AIA repository directory:" ) ;
4754 console . log ( "" ) ;
55+ console . log ( "git switch " + devBranch + "; git pull" ) ;
4856 console . log ( "git switch +c add_" + algID ) ;
49- console . log ( "# When stable, do git switch <development branch>; git merge add_" + algID ) ;
57+ console . log ( "" ) ;
5058 console . log ( "cp src/algorithms/controllers/heapSort.js src/algorithms/controllers/" + algID + ".js" ) ;
5159 console . log ( "git add src/algorithms/controllers/" + algID + ".js" ) ;
5260 console . log ( "cp src/algorithms/pseudocode/heapSort.js src/algorithms/pseudocode/" + algID + ".js" ) ;
5361 console . log ( "git add src/algorithms/pseudocode/" + algID + ".js" ) ;
54- console . log ( "# The files above will need to be edited during development" + algID + ".js" ) ;
62+ console . log ( "cp src/algorithms/parameters/HSParam.js src/algorithms/parameters/" + algID + ".js" ) ;
63+ console . log ( "git add src/algorithms/parameters/" + algID + ".js" ) ;
64+ console . log ( "cp src/algorithms/explanations/HSExp.md src/algorithms/explanations/" + algID + ".md" ) ;
65+ console . log ( "git add src/algorithms/explanations/" + algID + ".md" ) ;
66+ console . log ( "cp src/algorithms/extra-info/HSInfo.md src/algorithms/extra-info/" + algID + ".md" ) ;
67+ console . log ( "git add src/algorithms/extra-info/" + algID + ".md" ) ;
68+ console . log ( "echo \"export const " + algID + " = sortInstructions;\" >> src/algorithms/instructions/index.js" ) ;
69+ console . log ( "The files above (and others) will need to be edited during development" ) ;
70+ console . log ( "but best defer that until after you have added the new algorithm" ) ;
71+ console . log ( "" ) ;
5572 console . log ( "echo \"export { default as " + algID + "} from './" + algID + "'\" >> src/algorithms/controllers/index.js" ) ;
56- // XXX + other index.js files, explanations, extra-info, edit instructions
73+ console . log ( "echo \"export { default as " + algID + "} from './" + algID + "'\" >> src/algorithms/explanations/index.js" ) ;
74+ console . log ( "echo \"export { default as " + algID + "} from './" + algID + "'\" >> src/algorithms/extra-info/index.js" ) ;
75+ console . log ( "echo \"export { default as " + algID + "} from './" + algID + "'\" >> src/algorithms/parameters/index.js" ) ;
76+ console . log ( "echo \"export { default as " + algID + "} from './" + algID
77+ + "'\" >> src/algorithms/pseudocode/index.js" ) ;
5778 console . log ( "" ) ;
5879 console . log ( "Edit src/algorithms/index.js to add to the allalgs definition; something like:" ) ;
5980 console . log ( " '" + algID + "': {" ) ;
6081 console . log ( " name: '" + algName + "'," ) ;
82+ console . log ( " noDeploy: false," ) ;
6183 console . log ( " category: 'Sort'," ) ;
84+ console . log ( " explanation: Explanation." + algID + "," ) ;
85+ console . log ( " param: <Param." + algID + "/>," ) ;
86+ console . log ( " instructions: Instructions." + algID + "," ) ;
87+ console . log ( " extraInfo: ExtraInfo." + algID + "," ) ;
88+ console . log ( " pseudocode: {" ) ;
89+ console . log ( " sort: Pseudocode." + algID + "," ) ;
90+ console . log ( " }," ) ;
91+ console . log ( " controller: {" ) ;
92+ console . log ( " sort: Controller." + algID + "," ) ;
93+ console . log ( " }," ) ;
6294 // XXX ...
63- console . log ( "...}," ) ;
64- // XXX ...
95+ console . log ( "XXX Above may change with changes to index generation code" ) ;
96+ console . log ( "" ) ;
97+ console . log ( "Make sure the system compiles and existing algorithms run OK." ) ;
98+ console . log ( "This may require checking and re-working some of the steps above." ) ;
99+ console . log ( "" ) ;
100+ console . log ( "git commit -a -m 'Adding new algorithm: " + algID + "'" ) ;
101+ console . log ( "git switch " + devBranch + "; git pull" ) ;
102+ console . log ( "" ) ;
103+ console . log ( "Cross your fingers and hope nobody else has made conflicting changes." ) ;
104+ console . log ( "If you do the steps above quickly, conflicts are less likely." ) ;
105+ console . log ( "" ) ;
106+ console . log ( "git merge add_" + algID ) ;
107+ console . log ( "" ) ;
108+ console . log ( "Resolve any conflicts (eg add extra code of yours plus others)" ) ;
109+ console . log ( "" ) ;
110+ console . log ( "git commit -a; git push" ) ;
65111}
66112
67113/*
0 commit comments