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

Mass Conversion of examples to class based syntax #1852

Closed
6 tasks done
Tracked by #1837
bdemann opened this issue Jun 21, 2024 · 3 comments
Closed
6 tasks done
Tracked by #1837

Mass Conversion of examples to class based syntax #1852

bdemann opened this issue Jun 21, 2024 · 3 comments
Assignees

Comments

@bdemann
Copy link
Member

bdemann commented Jun 21, 2024

  • spot check the examples jordan did to make sure my scripts didn't mangle them.
  • keep an eye out while creating the prs that examples that only have some files changed are scrutinized (the will probably end up being the same as the above) (for example if as I am committing and example I notice that only the package.json is updated, then that might be a problem)
  • Make sure all call calls have the param and return idls
  • Remove TEST FETCH stuff
    • in the dfx.json
    • in package.json
@bdemann bdemann self-assigned this Jun 21, 2024
@bdemann
Copy link
Member Author

bdemann commented Jul 3, 2024

I didn't end up saving most of the regex for the conversions I think that would have slowed down the process a lot of not a lot of benefit. After a while of writing regex it started to come more naturally and it felt less important to keep a record as I was feeling confident that I could repeat the process again if I needed to and might even produce better regex. With that being said, here are some of the ones I did save, since they are already saved we might as well record them for posterity instead of deleting them.

  1. Update syntax for canister
    1. Convert canisters to classes
      1. export default Canister({\n*((.\n))});
      2. export default class {\n$1}
    2. Export queries and updates to decorators
      1. (.): ((update)|(query))(([.]),\s*(.),\s((.))\s=>\s*
      2. @$2($5, $6)\n$1$7
    3. Export async queries and updates to decorators
      1. \s*(.): ((update)|(query))(([.]),\s*(.),\s\sasync\s((.))\s=>\s*
      2. @$2($5, $6)\nasync $1$7
    4. Update init and postUpgrade to decorators
      1. (.): ((init)|(postUpgrade))(([.]),\s*\s*((.))\s=>\s*
      2. @$2($5)\n$1$6
    5. Convert async queries and updates with lots of line breaks to decorators
      1. \s*(.):\s((update)|(query))(\n\s*([.]),\n\s*(.),\n\sasync\s((.))\s=>\s*
      2. \n @$2($5, $6)\n async $1$7
    6. Convert queries and updates with lots of line breaks to decorators
      1. \s*(.):\s((update)|(query))(\n\s*([.]),\n\s*(.),\n\s*\s*((.))\s=>\s*
      2. \n @$2($5, $6)\n $1$7
    7. Change all manual return values to manual options args
      1. Manual((.*)))
      2. $1, { manual: true})

@bdemann
Copy link
Member Author

bdemann commented Jul 3, 2024

Here are the steps I used

  1. add name to similar package.json

  2. Copy to new location

  3. Delete node_modules, .dfx, .azle, and test/tests.ts

  4. add "experimentalDecorators": true, "preserveSymlinks": true
    to tsconfig

  5. Add coresponding package to package.json ("audio_recorder_end_to_end_test_functional_syntax": "file:../../../../../examples/audio_recorder",)

  6. Add to pretest the linking hack

import { linkAndInstallPatch } from 'azle/test/jest_link';
import { join } from 'path';
linkAndInstallPatch(join('examples', 'query'));

  1. Update getTests to be from the right package

There will be scripts in script/class_migration that will do a lot of these tasks automatically

The do_all_something.js script will run a given script for all of the projects in a directory
so for example I would start in the examples dir and run ../../scripts/class_migration/do_all_something.js ../../script/class_migration/the_script_I_want_to_run.js and then I would jump down to motoko examples and run it again (with the paths updated to reflect the cd to motoko_examples)

@bdemann
Copy link
Member Author

bdemann commented Jul 9, 2024

closed by #1853

@bdemann bdemann closed this as completed Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant