Skip to content

Commit 29f7db2

Browse files
author
Eric Butler
committed
Add NPM Release
Closes #4.
1 parent 84d3d47 commit 29f7db2

File tree

9 files changed

+313
-0
lines changed

9 files changed

+313
-0
lines changed

.circleci/config.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ executors:
1515
environment:
1616
CARGO_HOME: /root/notarize/qlc/.cargo
1717

18+
cross_compiling_host:
19+
docker:
20+
- image: notarize/cross-rust:1.36.0-stretch
21+
working_directory: /root/notarize/qlc
22+
environment:
23+
CARGO_HOME: /root/notarize/qlc/.cargo
24+
25+
github_api_client:
26+
docker:
27+
- image: notarize/github-api-client:ghr-0.12.2
28+
working_directory: /root/notarize/qlc
29+
30+
node_env:
31+
docker:
32+
- image: notarize/node:10.14.0
33+
working_directory: /root/notarize/qlc
34+
1835
jobs:
1936
cargo_init:
2037
executor: default_rust_compiler
@@ -70,6 +87,72 @@ jobs:
7087
name: Testing
7188
command: cargo test -- --test-threads=7
7289

90+
build_release_bin:
91+
executor: cross_compiling_host
92+
steps:
93+
- attach_made_workspace
94+
- run:
95+
name: Building OS X
96+
command: cargo build --release --target=x86_64-apple-darwin
97+
environment:
98+
CC: o64-clang
99+
CXX: o64-clang++
100+
LIBZ_SYS_STATIC: 1
101+
- run:
102+
name: Building Linux Musl
103+
command: cargo build --release --target=x86_64-unknown-linux-musl
104+
- persist_to_workspace:
105+
root: /root/notarize
106+
paths:
107+
- qlc/target/x86_64-apple-darwin/release
108+
- qlc/target/x86_64-unknown-linux-musl/release
109+
110+
create_github_release:
111+
executor: github_api_client
112+
steps:
113+
- attach_made_workspace
114+
- run:
115+
name: Making GitHub Release
116+
command: |
117+
mkdir -p archives
118+
119+
LINUX_MUSL="x86_64-unknown-linux-musl"
120+
cd "$CIRCLE_WORKING_DIRECTORY/target/$LINUX_MUSL/release"
121+
VERSION=$(./qlc --version | sed 's/QL Compiler //g')
122+
tar czf "qlc-$VERSION-$LINUX_MUSL.tar.gz" qlc
123+
mv "qlc-$VERSION-$LINUX_MUSL.tar.gz" "$CIRCLE_WORKING_DIRECTORY/archives/."
124+
125+
MAC_OSX="x86_64-apple-darwin"
126+
cd "$CIRCLE_WORKING_DIRECTORY/target/$MAC_OSX/release"
127+
tar czf "qlc-$VERSION-$MAC_OSX.tar.gz" qlc
128+
mv "qlc-$VERSION-$MAC_OSX.tar.gz" "$CIRCLE_WORKING_DIRECTORY/archives/."
129+
130+
cd "$CIRCLE_WORKING_DIRECTORY"
131+
ls -l archives
132+
ghr \
133+
-t "$GITHUB_TOKEN" \
134+
-n "v$VERSION" \
135+
-c "$CIRCLE_SHA1" \
136+
-delete \
137+
"$VERSION" archives
138+
139+
create_npm_release:
140+
executor: node_env
141+
steps:
142+
- attach_made_workspace
143+
- run:
144+
name: Configuring NPM Token
145+
command: |
146+
echo "registry=https://registry.npmjs.org/" > ~/.npmrc
147+
echo "//registry.npmjs.org/:_authToken=${NOTARBOT_NPM_TOKEN}" >> ~/.npmrc
148+
- run:
149+
name: Publishing Package
150+
command: |
151+
VERSION=$(./target/x86_64-unknown-linux-musl/release/qlc --version | sed 's/QL Compiler //g')
152+
cd pkg/npm
153+
sed -i "s/QLC_VERSION/$VERSION/g" package.json
154+
yarn publish --new-version "$VERSION" --access public
155+
73156
workflows:
74157
version: 2
75158
Everything:
@@ -99,3 +182,26 @@ workflows:
99182
filters:
100183
branches:
101184
ignore: master
185+
186+
- build_release_bin:
187+
requires:
188+
- test
189+
- lint
190+
- fmt
191+
filters:
192+
branches:
193+
only: production
194+
195+
- create_github_release:
196+
requires:
197+
- build_release_bin
198+
filters:
199+
branches:
200+
only: production
201+
202+
- create_npm_release:
203+
requires:
204+
- create_github_release
205+
filters:
206+
branches:
207+
only: production

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "qlc"
33
version = "0.1.0"
44
authors = ["Eric Butler <eric.butler@notarize.com>"]
55
edition = "2018"
6+
license = "MIT"
67
autotests = false
78

89
[[test]]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 Notarize, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# QL Compiler
2+
3+
The QL compiler `qlc` is a super fast and fun codegenerator for GraphQL clients. Specifically, it is capable of
4+
reading `.graphql` queries, mutations, and fragment files and combining this with introspection schema JSON to
5+
produce ad-hoc type defintions for TypeScript. Its similar to tools the [Apollo Tooling CLI](https://github.com/apollographql/apollo-tooling)
6+
and [GraphQL Code Generator](https://github.com/dotansimha/graphql-code-generator), but smaller in scope
7+
(and much faster).
8+
9+
## Example
10+
11+
Say you have a query that looks like this:
12+
13+
```graphql
14+
query MyQuery {
15+
comment {
16+
author {
17+
name
18+
}
19+
content
20+
}
21+
}
22+
```
23+
24+
Using qlc would enable you to codegen the following TypeScript file easily:
25+
26+
```ts
27+
export interface MyQuery_comment_author {
28+
name: string | null;
29+
}
30+
31+
export interface MyQuery_comment {
32+
author: MyQuery_comment_author;
33+
content: string;
34+
}
35+
36+
export interface MyQuery {
37+
comment: MyQuery_comment;
38+
}
39+
```
40+
41+
## Usage
42+
43+
You can use the binary as is see `--help` for various CLI options (there are not many). Additionally,
44+
since you are likely using this from a node project, there is a convience NPM package available.
45+
46+
```sh
47+
yarn add @notarize/qlc-cli
48+
```

pkg/npm/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.tar.gz
2+
bin/

pkg/npm/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# @notarize/qlc-cli
2+
3+
This is an npm module for using [qlc](https://github.com/notarize/qlc) (a rust binary) in a Node project.
4+
5+
### How it works
6+
7+
- QLC is built in CI and binaries are posted with a GitHub release.
8+
- In this module's postinstall task, it determines which platform it is being installed on and downloads the correct binary.

pkg/npm/lib/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"use strict";
2+
3+
module.exports = require("path").join(__dirname, "../bin/qlc");

pkg/npm/lib/postinstall.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
"use strict";
2+
3+
const os = require("os");
4+
const fs = require("fs");
5+
const https = require("https");
6+
const path = require("path");
7+
const util = require("util");
8+
const childProc = require("child_process");
9+
10+
const fsChmod = util.promisify(fs.chmod);
11+
const fsUnlink = util.promisify(fs.unlink);
12+
const fsExists = util.promisify(fs.exists);
13+
const mkdir = util.promisify(fs.mkdir);
14+
15+
const VERSION = require("../package.json").version;
16+
const BIN_PATH = path.join(__dirname, "../bin");
17+
18+
function getTarget() {
19+
switch (os.platform()) {
20+
case "darwin":
21+
return "x86_64-apple-darwin";
22+
case "linux":
23+
return "x86_64-unknown-linux-musl";
24+
default:
25+
throw new Error(`Unsupported platform: ${os.platform()}`);
26+
}
27+
}
28+
29+
function download(url, dest) {
30+
return new Promise((resolve, reject) => {
31+
const outFile = fs.createWriteStream(dest);
32+
const cleanup = (err) => fsUnlink(dest)
33+
.catch(console.error)
34+
.finally(() => {
35+
reject(err);
36+
});
37+
const headers = { Accept: "application/octet-stream" };
38+
https.get(url, { headers }, (response) => {
39+
if (response.statusCode === 302) {
40+
return download(response.headers.location, dest)
41+
.then(resolve).catch(reject);
42+
} else if (response.statusCode !== 200) {
43+
return cleanup(new Error(`Download failed with ${response.statusCode}`));
44+
}
45+
response.pipe(outFile);
46+
outFile.on("finish", () => {
47+
resolve();
48+
});
49+
}).on("error", cleanup);
50+
});
51+
}
52+
53+
function untar(zipPath, destDir) {
54+
return new Promise((resolve, reject) => {
55+
const unzipProc = childProc.spawn(
56+
"tar",
57+
["xf", zipPath, "-C", destDir],
58+
{ stdio: "inherit" },
59+
);
60+
unzipProc.on("error", reject);
61+
unzipProc.on("close", code => {
62+
return code === 0 ? resolve() : reject(new Error(`tar exited with ${code}`));
63+
});
64+
});
65+
}
66+
67+
async function main() {
68+
const fileName = `qlc-${VERSION}-${getTarget()}.tar.gz`;
69+
const url = `https://github.com/notarize/qlc/releases/download/${VERSION}/${fileName}`;
70+
await Promise.all([
71+
fsExists(BIN_PATH).then(exists => {
72+
return exists ? Promise.resolve() : mkdir(BIN_PATH);
73+
}),
74+
download(url, fileName),
75+
]);
76+
await untar(fileName, BIN_PATH);
77+
await Promise.all([
78+
fsUnlink(fileName),
79+
fsChmod(path.join(BIN_PATH, "qlc"), "755"),
80+
]);
81+
}
82+
83+
main()
84+
.catch(err => {
85+
console.error(`Unhandled error: ${err}`);
86+
process.exit(1);
87+
});

pkg/npm/package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "@notarize/qlc-cli",
3+
"version": "QLC_VERSION",
4+
"author": "Notarize Inc.",
5+
"license": "MIT",
6+
"description": "A module for using QLC in a Node project",
7+
"main": "lib/index.js",
8+
"bin": {
9+
"qlc": "bin/qlc"
10+
},
11+
"files": [
12+
"lib"
13+
],
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/notarize/qlc.git"
17+
},
18+
"keywords": [
19+
"gql",
20+
"generator",
21+
"types",
22+
"interfaces",
23+
"graphql",
24+
"codegen",
25+
"apollo",
26+
"typescript",
27+
"ts",
28+
"typings"
29+
],
30+
"bugs": {
31+
"url": "https://github.com/notarize/qlc/issues"
32+
},
33+
"homepage": "https://github.com/notarize/qlc",
34+
"scripts": {
35+
"postinstall": "node ./lib/postinstall.js"
36+
}
37+
}

0 commit comments

Comments
 (0)