use of io.crnk.gen.typescript.TSNpmConfiguration in project crnk-framework by crnk-project.
the class TSGenerator method writePackaging.
protected void writePackaging() throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
ObjectNode packageJson = mapper.createObjectNode();
TSNpmConfiguration npm = config.getNpm();
packageJson.put("name", npm.getPackageName());
packageJson.put("version", npm.getPackageVersion());
packageJson.put("description", npm.getDescription());
packageJson.put("license", npm.getLicense());
if (npm.getGitRepository() != null) {
ObjectNode repository = packageJson.putObject("repository");
repository.put("type", "git");
repository.put("url", npm.getGitRepository());
}
ObjectNode peerDependencies = packageJson.putObject("peerDependencies");
ObjectNode devDependencies = packageJson.putObject("devDependencies");
for (Map.Entry<String, String> entry : npm.getPeerDependencies().entrySet()) {
peerDependencies.put(entry.getKey(), entry.getValue());
devDependencies.put(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, String> entry : npm.getDevDependencies().entrySet()) {
devDependencies.put(entry.getKey(), entry.getValue());
}
File packageJsonFile = new File(outputDir, "package.json");
packageJsonFile.getParentFile().mkdirs();
ObjectNode scripts = packageJson.putObject("scripts");
scripts.put("build", "npm run build:js");
scripts.put("build:js", "tsc -p ./src --declaration");
packageJson.put("name", npm.getPackageName());
packageJson.put("version", npm.getPackageVersion());
// match what is expected by NPM. Otherwise NPM will reformat it and up-to-date checking will fail
// the first time (also platform specific)
String text = mapper.writer().writeValueAsString(packageJson);
text = text.replace(" : ", ": ");
text = text + "\n";
text = text.replace(System.lineSeparator(), "\n");
try (FileWriter writer = new FileWriter(packageJsonFile)) {
writer.write(text);
}
}
Aggregations