Skip to content

Commit

Permalink
feat: Add build script and publish a version for Deno (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Jan 10, 2020
1 parent f4c1955 commit f2b5697
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ typings/

# Build folders
lib/
deno/
*.sqlite
1 change: 1 addition & 0 deletions packages/hooks/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
test/
tsconfig.json
build/
22 changes: 22 additions & 0 deletions packages/hooks/build/deno.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// A silly build script that converts the incompatible
// TypeScript/Deno module references
const path = require('path');
const fs = require('fs');

const moduleNames = [
'./base', './compose', './decorator',
'./function', './object'
];

const folder = path.join(__dirname, '..', 'src');
const out = path.join(__dirname, '..', 'deno');

for (const fileName of fs.readdirSync(folder)) {
const content = fs.readFileSync(path.join(folder, fileName)).toString();
const replacedContent = moduleNames.reduce((current, mod) =>
current.replace(new RegExp('\'' + mod + '\'', 'g'), `'${mod}.ts'`)
, content);

console.log(path.join(out, fileName))
fs.writeFileSync(path.join(out, fileName), replacedContent);
}
4 changes: 3 additions & 1 deletion packages/hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
"main": "lib/",
"types": "lib/",
"scripts": {
"prepublish": "npm run compile",
"build:deno": "shx mkdir -p deno && node build/deno",
"compile": "shx rm -rf lib/ && tsc",
"build": "npm run compile && npm run build:deno",
"prepublish": "npm run build",
"test": "mocha --opts ../../mocha.opts --recursive test/**.test.ts test/**/*.test.ts"
},
"directories": {
Expand Down
13 changes: 13 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ To a function or class without having to change its original code while also kee

- [@feathersjs/hooks](#feathersjshooks)
- [Installation](#installation)
- [Node](#node)
- [Deno](#deno)
- [Quick Example](#quick-example)
- [JavaScript](#javascript)
- [TypeScript](#typescript)
Expand All @@ -44,10 +46,21 @@ To a function or class without having to change its original code while also kee

## Installation

### Node

```
npm install @feathersjs/hooks --save
yarn add @feathersjs/hooks
```

### Deno

```
import { hooks } from 'https://unpkg.com/@feathersjs/hooks@latest/deno/index.ts';
```

> __Note:__ You might want to replace `latest` with the actual version you want to use (e.g. `https://unpkg.com/@feathersjs/hooks@0.2.0/deno/index.ts`)
## Quick Example

### JavaScript
Expand Down

0 comments on commit f2b5697

Please sign in to comment.