Skip to content

Commit

Permalink
build: Change format of spec version
Browse files Browse the repository at this point in the history
Generate the version automatically.
keep them in step with the npm package version
which is also the github release tag/version.
Which is "semver"

there's currently  no straigtforward way to
compile time send variables into a spec.

So we generate a variables.tsp file from a "template"
The template is

`printf 'alias Version = \"%s\";\n' $npm_package_version > variables.tsp``
  • Loading branch information
laduke committed Feb 14, 2024
1 parent 047d90a commit 7259935
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/.DS_Store
/dist/
.DS_Store
variables.tsp
3 changes: 2 additions & 1 deletion main.tsp
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import "@typespec/http";
import "@typespec/openapi";
import "@typespec/json-schema";
import "./variables.tsp";

using TypeSpec.Http;
using TypeSpec.OpenAPI;
using TypeSpec.JsonSchema;

@service({
title: "ZeroTierOne Service",
version: "2024-02-13::1.12.2",
version: Version,
})
@info({
license: {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"test": "tsx test/*test.ts",
"build": "run-s pre-compile compile lint build:*",
"lint": "run-p lint:*",
"pre-compile": "run-p depcheck format-spec format-code",
"pre-compile": "run-p depcheck format-spec format-code variables",
"build:doc-html": "redocly build-docs tsp-output/@typespec/openapi3/openapi.yaml -o ./dist/index.html",
"pretest": "openapi-typescript tsp-output/@typespec/openapi3/openapi.yaml -o /tmp/schema.ts",
"clean": "rm -rf dist tsp-output",
Expand All @@ -19,6 +19,7 @@
"gh:tag": "git tag -d v${npm_package_version}; git tag v${npm_package_version}",
"release": "npm run gh:tag && git push --tags && gh-release -y -a=tsp-output/@typespec/openapi3/openapi.yaml,tsp-output/@typespec/json-schema/json-schema.json",
"version": "auto-changelog -p --template keepachangelog auto-changelog --breaking-pattern 'BREAKING CHANGE:' && git add CHANGELOG.md",
"variables": "printf 'alias Version = \"%s\";\n' $npm_package_version > variables.tsp",
"watch": "run-p watch:*",
"watch:compile": "npm run compile -- --watch",
"watch:serve": "redocly preview-docs ./tsp-output/@typespec/openapi3/openapi.yaml --use-community-edition"
Expand Down

0 comments on commit 7259935

Please sign in to comment.