cleanup/generalize generate

This commit is contained in:
Jeff Colombo 2019-03-19 14:40:48 -04:00
parent 3af799af07
commit 0775340b25
3 changed files with 23 additions and 16 deletions

View File

@ -1,5 +1,10 @@
{ {
"license": "UNLICENSED", "license": "UNLICENSED",
"config": {
"protobuf_namespace": "PVPokemon",
"protobuf_output": "./externals/generated/POGOProtos.generated.proto",
"protobuf_js_output": "./externals/generated/PVPogoProtos.js"
},
"scripts": { "scripts": {
"#": "DO NOT ADD '-d' OPTION TO WEBPACK OR ALL SOURCEMAPS WILL BREAK: https://webpack.js.org/api/cli/#shortcuts", "#": "DO NOT ADD '-d' OPTION TO WEBPACK OR ALL SOURCEMAPS WILL BREAK: https://webpack.js.org/api/cli/#shortcuts",
"lint": "tslint --project tslint.json", "lint": "tslint --project tslint.json",
@ -10,9 +15,9 @@
"clean": "rm -rf ./dist/*", "clean": "rm -rf ./dist/*",
"tsnode": "node -r ts-node/register -r tsconfig-paths/register", "tsnode": "node -r ts-node/register -r tsconfig-paths/register",
"generate": "node_modules/.bin/run-s protobuf pbjs pbts pokemondata", "generate": "node_modules/.bin/run-s protobuf pbjs pbts pokemondata",
"protobuf": "yarn tsnode ./src/scripts/generatePogoProtocolBuffer.ts PokemonId.proto Form.proto PokemonMove.proto PokemonFamilyId.proto PokemonType.proto", "protobuf": "yarn tsnode ./src/scripts/generatePogoProtocolBuffer.ts $npm_package_config_protobuf_output PokemonId.proto Form.proto PokemonMove.proto PokemonFamilyId.proto PokemonType.proto",
"pbjs": "node_modules/.bin/pbjs --keep-case -t static-module --no-verify --no-create --no-delimited -w es6 -r PVPokemon -o ./externals/generated/PVPogoProtos.js ./externals/generated/POGOProtos.generated.proto", "pbjs": "node_modules/.bin/pbjs --keep-case -t static-module --no-verify --no-create --no-delimited -w es6 -r $npm_package_config_protobuf_namespace -o $npm_package_config_protobuf_js_output $npm_package_config_protobuf_output",
"pbts": "node_modules/.bin/pbts --no-comments -n PVPokemon -o ./externals/generated/PVPogoProtos.d.ts ./externals/generated/PVPogoProtos.js", "pbts": "node_modules/.bin/pbts --no-comments -n $npm_package_config_protobuf_namespace -o ./externals/generated/PVPogoProtos.d.ts $npm_package_config_protobuf_js_output",
"pokemondata": "yarn tsnode ./src/scripts/generatePokemonData.ts" "pokemondata": "yarn tsnode ./src/scripts/generatePokemonData.ts"
}, },
"devDependencies": { "devDependencies": {

View File

@ -5,6 +5,8 @@ let path = require('path');
let pathToModule = path.dirname(require.resolve('pogo-protos')); let pathToModule = path.dirname(require.resolve('pogo-protos'));
let args = process.argv.slice(2); let args = process.argv.slice(2);
let output = args[0]; // first argument is the path/name of the output file
let imports = args.slice(1); // the rest of the arguments are the protobufs to import
async function parseDir(directory : string, rel : string) { async function parseDir(directory : string, rel : string) {
let content = ''; let content = '';
@ -14,7 +16,7 @@ async function parseDir(directory : string, rel : string) {
if (stat.isDirectory()) { if (stat.isDirectory()) {
content += await parseDir(sub, `${rel}/${child}`); content += await parseDir(sub, `${rel}/${child}`);
} else if (child.endsWith('.proto')) { } else if (child.endsWith('.proto')) {
if (args.indexOf(child) === -1) { if (imports.indexOf(child) === -1) {
continue; continue;
} }
content += `import public "${pathToModule}/${rel}/${child}";\n`; content += `import public "${pathToModule}/${rel}/${child}";\n`;
@ -37,7 +39,7 @@ async function build() {
} }
} }
await fs.writeFile(path.resolve('externals/generated', 'POGOProtos.generated.proto'), content); await fs.writeFile(path.resolve(output), content);
} }
build(); build();

View File

@ -1,19 +1,19 @@
import * as PVPogoProtos from 'externals/generated/PVPogoProtos'; import PVPokemon from 'externals/generated/PVPogoProtos';
export const PokemonId = PVPogoProtos.POGOProtos.Enums.PokemonId; export const PokemonId = PVPokemon.POGOProtos.Enums.PokemonId;
export type PokemonId = PVPogoProtos.POGOProtos.Enums.PokemonId; export type PokemonId = PVPokemon.POGOProtos.Enums.PokemonId;
export const PokemonMove = PVPogoProtos.POGOProtos.Enums.PokemonMove; export const PokemonMove = PVPokemon.POGOProtos.Enums.PokemonMove;
export type PokemonMove = PVPogoProtos.POGOProtos.Enums.PokemonMove; export type PokemonMove = PVPokemon.POGOProtos.Enums.PokemonMove;
export const PokemonFamilyId = PVPogoProtos.POGOProtos.Enums.PokemonFamilyId; export const PokemonFamilyId = PVPokemon.POGOProtos.Enums.PokemonFamilyId;
export type PokemonFamilyId = PVPogoProtos.POGOProtos.Enums.PokemonFamilyId; export type PokemonFamilyId = PVPokemon.POGOProtos.Enums.PokemonFamilyId;
export const PokemonType = PVPogoProtos.POGOProtos.Enums.PokemonType; export const PokemonType = PVPokemon.POGOProtos.Enums.PokemonType;
export type PokemonType = PVPogoProtos.POGOProtos.Enums.PokemonType; export type PokemonType = PVPokemon.POGOProtos.Enums.PokemonType;
export const PokemonForm = PVPogoProtos.POGOProtos.Enums.Form; export const PokemonForm = PVPokemon.POGOProtos.Enums.Form;
export type PokemonForm = PVPogoProtos.POGOProtos.Enums.Form; export type PokemonForm = PVPokemon.POGOProtos.Enums.Form;
// this worked, until i realized that i needed to access the values of the enums and not just the types // this worked, until i realized that i needed to access the values of the enums and not just the types
// export declare const PokemonId : import('pogo-protos').Enums.PokemonId; // export declare const PokemonId : import('pogo-protos').Enums.PokemonId;