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

Added process to export protobuf enums for use in webconfig #1279

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mikepparks
Copy link
Contributor

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.

@mikepparks mikepparks marked this pull request as ready for review January 30, 2025 05:53
@Pelsin
Copy link
Contributor

Pelsin commented Jan 30, 2025

This alias might need additional config.
For typescript to pick up the alias we would need a tsconfig file:

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 Pins.ts

import { GpioAction } from '@proto/enums';
const testEnum = GpioAction;
console.log(testEnum);

Defining extension order in vite config could be one way to solve this:

resolve: {
		extensions: ['.ts', '.tsx', '.jsx', '.js', '.json'],

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"
Copy link
Contributor

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"

Copy link
Contributor Author

@mikepparks mikepparks Jan 31, 2025

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",
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -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"),
Copy link
Contributor

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

Copy link
Contributor Author

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
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

Successfully merging this pull request may close these issues.

2 participants