Skip to content

Commit 58f8178

Browse files
authored
Merge pull request #250 from json-schema-tools/feat/cargo-release
Feat/cargo release
2 parents 618d741 + 58e61f8 commit 58f8178

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

.github/workflows/lint.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ jobs:
66
name: lint
77
runs-on: ubuntu-latest
88
steps:
9-
- name: nodenv/setup-nodenv
10-
uses: nodenv/actions-setup-nodenv@v2.0.4
119
- uses: actions/checkout@v1
12-
- name: install eslint
10+
- name: Use Node.js 14.15.1
11+
uses: actions/setup-node@v1
12+
with:
13+
node-version: 14.15.1
14+
- name: npm install
1315
run: npm install
1416
- name: lint
15-
run: ./node_modules/.bin/eslint . --ext .ts
17+
run: npm run lint

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"typescript": "^4.0.5"
3838
},
3939
"dependencies": {
40+
"@iarna/toml": "^2.2.5",
4041
"@json-schema-tools/dereferencer": "^1.4.0",
4142
"@json-schema-tools/transpiler": "^1.5.7",
4243
"lodash": "^4.17.20",

src/index.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as fs from "fs";
77
import { promisify } from "util";
88
import { JSONSchema, JSONSchemaObject } from "@json-schema-tools/meta-schema";
99
import Dereferencer from "@json-schema-tools/dereferencer";
10+
import toml from "@iarna/toml";
1011

1112
const readFile = promisify(fs.readFile);
1213
const writeFile = promisify(fs.writeFile);
@@ -98,6 +99,32 @@ const generateGo = async (transpiler: Transpiler, schema: JSONSchemaObject, outp
9899
return true;
99100
}
100101

102+
const generateRs = async (transpiler: Transpiler, schema: JSONSchemaObject, outpath: string, version: string): Promise<boolean> => {
103+
const crateName = snakeCase(schema.title);
104+
105+
let cargotoml;
106+
107+
try {
108+
cargotoml = toml.parse(await readFile("${outpath}/Cargo.toml", "utf8"));
109+
cargotoml.version = version;
110+
} catch (e) {
111+
cargotoml = {
112+
package: {
113+
name: crateName,
114+
version
115+
},
116+
dependencies: {
117+
serde: "1.0.125"
118+
}
119+
}
120+
}
121+
122+
await writeFile(`${outpath}/Cargo.toml`, toml.stringify(cargotoml));
123+
await writeFile(`${outpath}/src/lib.rs`, transpiler.toRs());
124+
125+
return true;
126+
};
127+
101128
export const prepare: PluginFunction = async (pluginConfig, context): Promise<boolean> => {
102129
if (!verified) {
103130
throw new SemanticReleaseError("Not verified", "ENOTVERIFIED", "Something went wrong and the schemas were not able to be verified."); //tslint:disable-line
@@ -137,7 +164,7 @@ export const prepare: PluginFunction = async (pluginConfig, context): Promise<bo
137164
await generateGo(transpiler, schema, outpath);
138165
}
139166
if (!pluginConfig.languages || pluginConfig.languages.rs) {
140-
await writeFile(`${outpath}/index.rs`, transpiler.toRs());
167+
await generateRs(transpiler, schema, outpath, context.nextRelease.version)
141168
}
142169
if (!pluginConfig.languages || pluginConfig.languages.py) {
143170
await writeFile(`${outpath}/index.py`, transpiler.toPy());

0 commit comments

Comments
 (0)