cleanup/generalize generate
This commit is contained in:
parent
3af799af07
commit
0775340b25
11
package.json
11
package.json
@ -1,5 +1,10 @@
|
||||
{
|
||||
"license": "UNLICENSED",
|
||||
"config": {
|
||||
"protobuf_namespace": "PVPokemon",
|
||||
"protobuf_output": "./externals/generated/POGOProtos.generated.proto",
|
||||
"protobuf_js_output": "./externals/generated/PVPogoProtos.js"
|
||||
},
|
||||
"scripts": {
|
||||
"#": "DO NOT ADD '-d' OPTION TO WEBPACK OR ALL SOURCEMAPS WILL BREAK: https://webpack.js.org/api/cli/#shortcuts",
|
||||
"lint": "tslint --project tslint.json",
|
||||
@ -10,9 +15,9 @@
|
||||
"clean": "rm -rf ./dist/*",
|
||||
"tsnode": "node -r ts-node/register -r tsconfig-paths/register",
|
||||
"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",
|
||||
"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",
|
||||
"pbts": "node_modules/.bin/pbts --no-comments -n PVPokemon -o ./externals/generated/PVPogoProtos.d.ts ./externals/generated/PVPogoProtos.js",
|
||||
"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 $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 $npm_package_config_protobuf_namespace -o ./externals/generated/PVPogoProtos.d.ts $npm_package_config_protobuf_js_output",
|
||||
"pokemondata": "yarn tsnode ./src/scripts/generatePokemonData.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@ -5,6 +5,8 @@ let path = require('path');
|
||||
|
||||
let pathToModule = path.dirname(require.resolve('pogo-protos'));
|
||||
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) {
|
||||
let content = '';
|
||||
@ -14,7 +16,7 @@ async function parseDir(directory : string, rel : string) {
|
||||
if (stat.isDirectory()) {
|
||||
content += await parseDir(sub, `${rel}/${child}`);
|
||||
} else if (child.endsWith('.proto')) {
|
||||
if (args.indexOf(child) === -1) {
|
||||
if (imports.indexOf(child) === -1) {
|
||||
continue;
|
||||
}
|
||||
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();
|
||||
|
||||
@ -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 type PokemonId = PVPogoProtos.POGOProtos.Enums.PokemonId;
|
||||
export const PokemonId = PVPokemon.POGOProtos.Enums.PokemonId;
|
||||
export type PokemonId = PVPokemon.POGOProtos.Enums.PokemonId;
|
||||
|
||||
export const PokemonMove = PVPogoProtos.POGOProtos.Enums.PokemonMove;
|
||||
export type PokemonMove = PVPogoProtos.POGOProtos.Enums.PokemonMove;
|
||||
export const PokemonMove = PVPokemon.POGOProtos.Enums.PokemonMove;
|
||||
export type PokemonMove = PVPokemon.POGOProtos.Enums.PokemonMove;
|
||||
|
||||
export const PokemonFamilyId = PVPogoProtos.POGOProtos.Enums.PokemonFamilyId;
|
||||
export type PokemonFamilyId = PVPogoProtos.POGOProtos.Enums.PokemonFamilyId;
|
||||
export const PokemonFamilyId = PVPokemon.POGOProtos.Enums.PokemonFamilyId;
|
||||
export type PokemonFamilyId = PVPokemon.POGOProtos.Enums.PokemonFamilyId;
|
||||
|
||||
export const PokemonType = PVPogoProtos.POGOProtos.Enums.PokemonType;
|
||||
export type PokemonType = PVPogoProtos.POGOProtos.Enums.PokemonType;
|
||||
export const PokemonType = PVPokemon.POGOProtos.Enums.PokemonType;
|
||||
export type PokemonType = PVPokemon.POGOProtos.Enums.PokemonType;
|
||||
|
||||
export const PokemonForm = PVPogoProtos.POGOProtos.Enums.Form;
|
||||
export type PokemonForm = PVPogoProtos.POGOProtos.Enums.Form;
|
||||
export const PokemonForm = PVPokemon.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
|
||||
// export declare const PokemonId : import('pogo-protos').Enums.PokemonId;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user