Skip to content

Commit a316ee1

Browse files
author
Miguel Molina
authored
Merge pull request #1 from erizocosmico/feature/driver
Implement typescript native driver
2 parents a513c7e + de71f5f commit a316ee1

17 files changed

+3296
-0
lines changed

.travis.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
language: go
2+
3+
go:
4+
- 1.8
5+
6+
services:
7+
- docker
8+
9+
before_script:
10+
- go get -v github.com/bblfsh/sdk/...
11+
- bblfsh-sdk prepare-build .
12+
- go get -v -t ./...
13+
14+
script:
15+
- make test
16+
17+
after_success:
18+
- make push

Dockerfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Dockerfile represents the container being use to run the driver, should be
2+
# small as possible containing strictly only the tools required to run the
3+
# driver.
4+
5+
# The prefered base image is the lastest stable Alpine image, if alpine doesn't
6+
# meet the requirements you can switch the from to the latest stable slim
7+
# version of Debian (eg.: `debian:jessie-slim`). If the excution environment
8+
# is equals to the build environment the build image can be use as FROM:
9+
# bblfsh/<language>-driver-build
10+
FROM bblfsh/typescript-driver-build
11+
12+
CMD /opt/driver/bin/driver

Dockerfile.build

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Dockerfile.build represents the build environment of the driver, used during
2+
# the development phase to test and in CI to build and test.
3+
4+
# The prefered base image is the lastest stable Alpine image, if alpine doesn't
5+
# meet the requirements you can switch the from to the latest stable slim
6+
# version of Debian (eg.: `debian:jessie-slim`).
7+
FROM node:7-alpine
8+
9+
# To avoid files written in the volume by root or foreign users, we create a
10+
# container local user with the same UID of the user executing the build.
11+
# The following commands are defined to use in busybox based distributions,
12+
# if you are using a standard distributions, replace the `adduser` command with:
13+
# `useradd --uid ${BUILD_UID} --home /opt/driver ${BUILD_USER}`
14+
RUN mkdir -p /opt/driver/src && \
15+
adduser ${BUILD_USER} -u ${BUILD_UID} -D -h /opt/driver/src
16+
17+
18+
# As minimal build tools you need: make, curl and git, install using the same
19+
# command the specific tools required to build the driver.
20+
RUN apk add --no-cache make git curl ca-certificates
21+
RUN apk add
22+
23+
RUN npm install -g yarn
24+
25+
# The volume with the full source code is mounted at `/opt/driver/src` so, we
26+
# set the workdir to this path.
27+
WORKDIR /opt/driver/src

Dockerfile.build.tpl

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Dockerfile.build represents the build environment of the driver, used during
2+
# the development phase to test and in CI to build and test.
3+
4+
# The prefered base image is the lastest stable Alpine image, if alpine doesn't
5+
# meet the requirements you can switch the from to the latest stable slim
6+
# version of Debian (eg.: `debian:jessie-slim`).
7+
FROM alpine:3.5
8+
9+
# To avoid files written in the volume by root or foreign users, we create a
10+
# container local user with the same UID of the user executing the build.
11+
# The following commands are defined to use in busybox based distributions,
12+
# if you are using a standard distributions, replace the `adduser` command with:
13+
# `useradd --uid ${BUILD_UID} --home /opt/driver ${BUILD_USER}`
14+
RUN mkdir -p /opt/driver/src && \
15+
adduser ${BUILD_USER} -u ${BUILD_UID} -D -h /opt/driver/src
16+
17+
18+
# As minimal build tools you need: make, curl and git, install using the same
19+
# command the specific tools required to build the driver.
20+
RUN apk add --no-cache make git curl ca-certificates
21+
22+
23+
# The volume with the full source code is mounted at `/opt/driver/src` so, we
24+
# set the workdir to this path.
25+
WORKDIR /opt/driver/src

Dockerfile.tpl

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Dockerfile represents the container being use to run the driver, should be
2+
# small as possible containing strictly only the tools required to run the
3+
# driver.
4+
5+
# The prefered base image is the lastest stable Alpine image, if alpine doesn't
6+
# meet the requirements you can switch the from to the latest stable slim
7+
# version of Debian (eg.: `debian:jessie-slim`). If the excution environment
8+
# is equals to the build environment the build image can be use as FROM:
9+
# bblfsh/<language>-driver-build
10+
FROM alpine:3.5
11+
12+
CMD /opt/driver/bin/driver

Makefile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
include .sdk/Makefile
2+
3+
test-native:
4+
cd native; \
5+
echo "yarn test"
6+
7+
build-native:
8+
cd native; \
9+
yarn install; \
10+
cp *.js $(BUILD_PATH); \
11+
mv node_modules $(BUILD_PATH); \
12+
mv $(BUILD_PATH)/index.js $(BUILD_PATH)/native; \
13+
chmod +x $(BUILD_PATH)/native

README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# typescript-driver ![Driver Status](https://img.shields.io/badge/status-pre--alpha-d6ae86.svg) [![Build Status](https://travis-ci.org/bblfsh/typescript-driver.svg?branch=master)](https://travis-ci.org/bblfsh/typescript-driver) ![Native Version](https://img.shields.io/badge/typescript%20version-2.2.1-aa93ea.svg) ![Go Version](https://img.shields.io/badge/go%20version-1.8-63afbf.svg)
2+
3+
typescript driver for [babelfish](https://github.com/bblfsh/server).
4+
5+
6+
Development Environment
7+
-----------------------
8+
9+
Requirements:
10+
- `docker`
11+
- [`bblfsh-sdk`](https://github.com/bblfsh/sdk) _(go get -u github.com/bblfsh/sdk/...)_
12+
13+
To initialize the build system execute: `bblfsh-sdk prepare-build`, at the root of the project. This will install the SDK at `.sdk` for this driver.
14+
15+
To execute the tests just execute `make test`, this will execute the test over the native and the go components of the driver. Use `make test-native` to run the test only over the native component or `make test-driver` to run the test just over the go component.
16+
17+
The build is done executing `make build`. To evaluate the result, a docker container, execute:
18+
`docker run -it bblfsh/typescript-driver:dev-<commit[:6]>`
19+
20+
21+
License
22+
-------
23+
24+
GPLv3, see [LICENSE](LICENSE)
25+
26+
27+

driver/main.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/bblfsh/sdk"
8+
9+
_ "github.com/bblfsh/typescript-driver/driver/normalizer"
10+
)
11+
12+
var version string
13+
var build string
14+
15+
func main() {
16+
fmt.Printf("version: %s\nbuild: %s\n", version, build)
17+
18+
_, err := os.Stat(sdk.NativeBin)
19+
if err == nil {
20+
fmt.Println("native: ok")
21+
return
22+
}
23+
24+
fmt.Printf("native: %s\n", err)
25+
}

driver/normalizer/normalizer.go

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package normalizer

driver/normalizer/normalizer_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package normalizer
2+
3+
import (
4+
"os/exec"
5+
"testing"
6+
"time"
7+
8+
"github.com/bblfsh/sdk"
9+
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
func TestNativeBinary(t *testing.T) {
14+
r := require.New(t)
15+
16+
cmd := exec.Command(sdk.NativeBinTest)
17+
err := cmd.Start()
18+
r.Nil(err)
19+
20+
time.Sleep(time.Second)
21+
err = cmd.Process.Kill()
22+
r.Nil(err)
23+
}

manifest.toml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Manifest contains metadata about the driver. To learn about the different
2+
# values in this manifest refer to:
3+
# https://github.com/bblfsh/sdk/blob/master/manifest/manifest.go
4+
5+
language = "typescript"
6+
7+
# status describes the current development status of the driver, the valid
8+
# values for status are: `planning`, `pre-alpha`, `alpha`, `beta`, `stable`,
9+
# `mature` or `inactive`.
10+
status = "pre-alpha"
11+
12+
# documentation block is use to render the README.md file.
13+
[documentation]
14+
description = """
15+
typescript driver for [babelfish](https://github.com/bblfsh/server).
16+
"""
17+
18+
[runtime]
19+
# os defines in with distribution the runtime is executed (and the build
20+
# system). The valid values are `alpine` and `debian`. Alpine is preferred
21+
# since is a micro-distribution, but sometimes is hard or impossible to use
22+
# due to be based on musl and not it libc.
23+
os = "alpine"
24+
25+
# go_version describes the version being use to build the driver Go code.
26+
go_version = "1.8"
27+
28+
# native_version describes the version or versions being use to build and
29+
# execute the native code, you should define at least one. (eg.: "1.8").
30+
native_version = ["2.2.1"]

native/Dockerfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM node:6.10-alpine
2+
3+
RUN mkdir -p /opt/node
4+
ADD . /opt/node
5+
6+
WORKDIR /opt/node
7+
RUN yarn install
8+
9+
CMD node /opt/node/src/index.js
10+

native/package.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "typescript-driver",
3+
"version": "1.0.0",
4+
"description": "TypeScript babelfish driver",
5+
"main": "src/index.js",
6+
"repository": "https://github.com/bblfsh/typescript-driver",
7+
"author": "Miguel Molina <[email protected]>",
8+
"license": "GPLv3",
9+
"dependencies": {
10+
"typescript": "^2.2.1"
11+
},
12+
"ava": {
13+
"files": ["test/*.js"]
14+
},
15+
"scripts": {
16+
"start": "node src/index.js",
17+
"test": "ava -v"
18+
},
19+
"devDependencies": {
20+
"ava": "^0.18.2"
21+
}
22+
}

native/src/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
4+
const { processRequest } = require('./parse');
5+
const readline = require('readline');
6+
7+
const rl = readline.createInterface({
8+
input: process.stdin,
9+
output: process.stdout,
10+
terminal: false
11+
});
12+
13+
rl.on('line', l => console.log(processRequest(l)));

0 commit comments

Comments
 (0)