Skip to content

Commit

Permalink
Attempt to rearrange repo, package.json etc to make this a 'real' npm…
Browse files Browse the repository at this point in the history
… package
  • Loading branch information
mcclure committed Aug 24, 2016
1 parent 10f7ba1 commit 31c25f3
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 62 deletions.
43 changes: 25 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
# Start by running: npm install -g typescript typings && npm install

all: install/app.js install/tsGlue.js install/index.html install/style.css
all: bin/dts2nim.js

# Clean

# Clean.
clean:
rm -f install/* src/tsGlue.nim tools/dts2nim.js
rm -f bin/* tests/test.js tests/tsGlue.js tests/tsGlue.nim tests/testMain.js

# Build app

install/tsGlue.js: src/tsGlue.ts
bin/dts2nim.js: typings/index.d.ts src/dts2nim.ts
mkdir -p $(@D)
tsc

install/app.js: src/app.nim src/tsGlue.nim
mkdir -p $(@D)
nim js -o:$@ $<
typings/index.d.ts: typings.json
typings install

install/index.html: static/index.html
mkdir -p $(@D)
cp $< $@
# Tests

install/style.css: static/style.css
test: tests/test.js
node ./tests/test.js

tests/test.js: tests/tsGlue.js tests/testMain.js
echo "#!/usr/bin/env node" > $@
cat tests/tsGlue.js >> $@
cat tests/testMain.js >> $@

tests/tsGlue.js: tests/tsGlue.ts
mkdir -p $(@D)
cp $< $@
tsc -p $(@D)

src/tsGlue.nim: src/tsGlue.ts install/tsGlue.js tools/dts2nim.js
node tools/dts2nim.js -q $< > $@
tests/tsGlue.nim: tests/tsGlue.ts tests/tsGlue.js bin/dts2nim.js
node bin/dts2nim.js -q $< > $@

tools/dts2nim.js: tools/typings/index.d.ts tools/dts2nim.ts
tsc -p tools
tests/testMain.js: tests/testMain.nim tests/tsGlue.nim
mkdir -p $(@D)
nim js -o:$@ $<

tools/typings/index.d.ts: tools/typings.json
cd tools && typings install
29 changes: 28 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,32 @@
"commander.js-error": "^1.1.0",
"graphlib": "^2.1.1",
"typescript": "^1.8.10"
}
},
"name": "dts2nim",
"description": "Binding generator from TypeScript to the Nim programming language",
"version": "0.0.1",
"main": "bin/dts2nim.js",
"devDependencies": {},
"bin": {
"dts2nim" : "bin/dts2nim.js"
},
"scripts": {
"prepublish": "make all",
"test": "make test"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/mcclure/dts2nim.git"
},
"keywords": [
"nim",
"typescript",
"binding"
],
"author": "Andi McClure",
"license": "MIT",
"bugs": {
"url": "https://github.com/mcclure/dts2nim/issues"
},
"homepage": "https://github.com/mcclure/dts2nim"
}
File renamed without changes.
20 changes: 0 additions & 20 deletions static/index.html

This file was deleted.

17 changes: 0 additions & 17 deletions static/style.css

This file was deleted.

10 changes: 10 additions & 0 deletions tests/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head><title>dts2nim test</title>
</head>
<body>
This HTML file can be used to run the dts2nim <tt>make test</tt> script in a browser. Run <tt>make test</tt> to build the js files, then open this file in a browser and check the JavaScript console for errors.
<script src="tsGlue.js"></script>
<script src="testMain.js"></script>
</body>
</html>
2 changes: 2 additions & 0 deletions src/app.nim → tests/testMain.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import tsGlue

# Nim side of tests-- calls into functions defined in tsGlue.ts

# POST

var failed = false
Expand Down
8 changes: 6 additions & 2 deletions src/tsGlue.ts → tests/tsGlue.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TypeScript side of tests-- defines functions called by testMain.nim

function testAssert(condition: boolean, message:string) {
if (!condition)
throw new Error("Test failed: " + message)
Expand Down Expand Up @@ -98,8 +100,10 @@ let QFvarcallback : (x: number, y: (z: number) => number) => number

QFvarcallback = (x, y) => y(x + 1) + 1

// Ugly way to access global variable
let QFbackflow = () : number => (<any>this).QBbackflow
// This will allow QFbackflow through the type checker, but will not declare a variable
declare var QBbackflow : number

let QFbackflow = () : number => QBbackflow

// A pattern lib.d.ts frequently follows.
interface QCproto {
Expand Down
3 changes: 1 addition & 2 deletions tools/tsconfig.json → tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"outDir": "."
},
"files": [
"typings/index.d.ts",
"dts2nim.ts"
"tsGlue.ts"
]
}
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"compilerOptions": {
"module": "commonjs",
"outDir": "install"
"outDir": "bin"
},
"files": [
"src/tsGlue.ts"
"typings/index.d.ts",
"src/dts2nim.ts"
]
}
File renamed without changes.

0 comments on commit 31c25f3

Please sign in to comment.