Open zxti opened 5 years ago
There is currently no way to combine multiple types. I can look into that, perhaps this would be easy with a little refactoring of the collected type format (and can also address #36)
Regarding running typewiz-node without applying the types immediately, it is possible with a small wrapper script, I made a small example repo for you:
https://github.com/urish/typewiz-node-no-apply
I hope that this helps!
Update: refactoring started (#88)
Here's a simple script that seems to do the job in my case, in case it's helpful for others - combines the files in ??.json to a combined.json:
import * as fs from "fs";
import * as glob from "glob";
import * as _ from "lodash";
type Entry = any[];
const blobs: Entry[][] = glob
.sync("??.json")
.map(path => JSON.parse(fs.readFileSync(path, { encoding: "utf8" })));
console.log(blobs.map(blob => blob.length));
const entries = _.flatMap(blobs, blob => blob);
const groups = _.groupBy(entries, entry => `${entry[0]}:${entry[1]}`);
console.log(Object.keys(groups).length);
const consolidated = _.values(groups).map(entries => {
const first = entries[0];
return [
first[0],
first[1],
_.uniqBy(_.flatMap(entries.map(entry => entry[2])), type =>
JSON.stringify(type)
),
first[3]
];
});
const preview = JSON.stringify(consolidated.slice(0, 5), null, 2);
preview;
fs.writeFileSync("combined.json", JSON.stringify(consolidated));
//entries.map(entry => [`${entry[0]}:${entry[1]}`, entry] as [string, Entry]));
Is there an easy way to combine the collected types from typewiz-webpack and multiple typewiz-node runs?
I think there are two specific questions here:
When I go from page to page, typewiz-webpack regenerates a new collected-types.json (it's cleared on page load). Can I combine multiple?
typewiz-node immediately applies types to the codebase on termination. Is there any way to instead get a collected-types.json, in the same fashion as typewiz-webpack?
Even if you had a simple snippet or some such for combining these, that would be fantastic. I tried simply concatenating the .json files, and that did not go over well. :) Thanks!
(My use case: I'm interested in types from many typewiz-webpack outputs over frontend code, typewiz-node outputs over server code, and typewiz-node outputs over jest executions.)