-
Notifications
You must be signed in to change notification settings - Fork 356
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
Added process to export protobuf enums for use in webconfig #1279
base: main
Are you sure you want to change the base?
Added process to export protobuf enums for use in webconfig #1279
Conversation
This alias might need additional config. This should be the minimum to make it work {
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@proto/*": ["src_gen/*"]
}
},
"include": ["src"],
"exclude": ["node_modules"]
} There is a chance our setup wont import the alias correctly, it might default to looking for .js. Possible to recreate by adding to import { GpioAction } from '@proto/enums';
const testEnum = GpioAction;
console.log(testEnum); Defining extension order in vite config could be one way to solve this:
Gitignoring the .js file might also be nice to do |
www/package.json
Outdated
"dev-server": "nodemon -r dotenv/config ./server/app.js", | ||
"dev": "concurrently --kill-others \"npm run dev-server\" \"npm start\"", | ||
"dev-board": "cross-env VITE_DEV_BASE_URL=http://192.168.7.1 npm start ", | ||
"format": "prettier --write \"{src,server}/**/*.{tsx,ts,jsx,js,json,scss}\"", | ||
"lint": "eslint src --ext js,jsx,ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"makefsdata": "node makefsdata.js", | ||
"start": "vite" | ||
"start": "npm run build-proto && vite", | ||
"build-proto": "npx pbjs --no-create --no-encode --no-decode --no-convert --no-verify --no-delimited --sparse -t static-module -w commonjs --path ../lib/nanopb/generator/proto/ ../proto/enums.proto -o ./src_gen/enums.js && npx pbts --no-comments -m -o ./src_gen/enums.ts ./src_gen/enums.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could remove npx here:
"build-proto": "pbjs --no-create --no-encode --no-decode --no-convert --no-verify --no-delimited --sparse -t static-module -w commonjs --path ../lib/nanopb/generator/proto/ ../proto/enums.proto -o ./src_gen/enums.js && pbts --no-comments -m -o ./src_gen/enums.ts ./src_gen/enums.js"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the command to pipe the output from pbjs to pbts, skipping the middleman js file. npx was already in use earlier in the run commands so I kept it there. Didn't seem to work without.
www/package.json
Outdated
@@ -52,6 +53,8 @@ | |||
"nodemon": "^2.0.22", | |||
"pako": "^2.1.0", | |||
"prettier": "^3.3.3", | |||
"protobufjs": "^7.4.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be remove, we only use protobufjs-cli
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
www/vite.config.ts
Outdated
@@ -20,7 +20,8 @@ export default defineConfig({ | |||
resolve: { | |||
alias: { | |||
"~bootstrap": path.resolve(__dirname, "node_modules/bootstrap"), | |||
lodash: 'lodash-es' | |||
lodash: 'lodash-es', | |||
proto: path.resolve(__dirname, "src_gen"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's common to use "@" as prefix for own aliases to not collide with other libraries, could be an option here. Would work either way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done as well.
Changed enum generation command to use standard output and skip js file generation
This exports enums from the protobuf definitions for use in development of the webconfig. It will help reduce the need to reproduce these values in locations where they are listed, such as input modes or Display button layouts.