Skip to content

Commit 5417aeb

Browse files
committed
chore: first commit
0 parents  commit 5417aeb

File tree

11 files changed

+240
-0
lines changed

11 files changed

+240
-0
lines changed

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
*.exe
2+
*.obj
3+
*.out
4+
*.compile
5+
*.native
6+
*.byte
7+
*.cmo
8+
*.annot
9+
*.cmi
10+
*.cmx
11+
*.cmt
12+
*.cmti
13+
*.cma
14+
*.a
15+
*.cmxa
16+
*.obj
17+
*~
18+
*.annot
19+
*.cmj
20+
*.bak
21+
lib/bs
22+
*.mlast
23+
*.mliast
24+
.merlin
25+
.bsb.lock
26+
/node_modules/
27+
lib
28+
src/**/*.d.ts

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.vscode
2+
scripts
3+
src
4+
bsconfig.json

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"files.exclude": {
3+
"**/.git": true,
4+
"**/.svn": true,
5+
"**/.hg": true,
6+
"**/CVS": true,
7+
"**/.DS_Store": true,
8+
"**/src/**/*.d.ts": true,
9+
}
10+
}

.vscode/tasks.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "npm",
6+
"script": "start",
7+
"problemMatcher": [],
8+
"label": "npm: start",
9+
"detail": "rescript start -w"
10+
}
11+
]
12+
}

LICENSE

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

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Rescript module template
2+
========================
3+
4+
- It's Rescript! ❤️
5+
- Builds fast
6+
- Generates `.d.ts` files using gentype
7+
- Builds both to commonjs and es6 spec
8+
9+
## scripts
10+
11+
# Build
12+
13+
Builds files, generates typings and copy all necessaries files into the lib dir (ready to be published on a registry)
14+
15+
```
16+
npm run build
17+
```
18+
19+
20+
# Watch
21+
22+
If you are using the rescript lang plugin for vscode, it adds intellisense and other beautiful stuff in realtime inside your editor. Oh, builds files too (but not ready to be published on a registry)
23+
24+
```
25+
npm run watch
26+
```
27+

bsconfig.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "rescript-module-template",
3+
"version": "0.1.0",
4+
"sources": {
5+
"dir" : "src",
6+
"subdirs" : true
7+
},
8+
"bs-dependencies": [
9+
],
10+
"bs-dev-dependencies": [],
11+
"package-specs": [
12+
{
13+
"module": "es6",
14+
"suffix": ".mjs",
15+
"in-source": false
16+
},
17+
{
18+
"module": "commonjs",
19+
"suffix": ".js",
20+
"in-source": false
21+
}
22+
],
23+
"gentypeconfig": {
24+
"language": "typescript",
25+
"generatedFileExtension": ".d.ts"
26+
},
27+
"generate-merlin": true
28+
}

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "rescript-module-template",
3+
"version": "0.0.0",
4+
"main": "lib/js/index.js",
5+
"module": "lib/es6/index.mjs",
6+
"license": "MIT",
7+
"dependencies": {
8+
"rescript": "^9.1.4"
9+
},
10+
"scripts": {
11+
"build": "npm run clean && rescript build && npm run postbuild",
12+
"clean": "rescript clean && gentype -clean",
13+
"deploy": "npm run build && cd lib && npm run publish",
14+
"postbuild": "node scripts/postbuild.js",
15+
"start": "rescript build -w"
16+
},
17+
"devDependencies": {
18+
"gentype": "^4.1.0"
19+
}
20+
}

scripts/postbuild.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const packagejson = require('../package.json');
4+
5+
// project dir
6+
const projectdir = path.join(__dirname, '..');
7+
// source dir
8+
const srcdir = path.join(__dirname, '..', 'src');
9+
// output dir
10+
const outdir = path.join(__dirname, '..', 'lib');
11+
// cjs output dir
12+
const cjsoutdir = path.join(outdir, 'js');
13+
// es6 output dir
14+
const es6outdir = path.join(outdir, 'es6');
15+
// out maps
16+
const outmap = {
17+
js: cjsoutdir,
18+
es6: es6outdir,
19+
};
20+
21+
//#region fns
22+
23+
const isdirectory = arg => fs.statSync(arg).isDirectory();
24+
const isfile = arg => fs.statSync(arg).isFile();
25+
26+
const ensuredir = dir => {
27+
const chunks = dir.replace(projectdir, '').split(path.sep);
28+
let current = chunks[0];
29+
30+
for (let i = 1; i < chunks.length; i++) {
31+
current = path.join(current, chunks[i]);
32+
if (!fs.existsSync(current)) {
33+
fs.mkdirSync(current);
34+
}
35+
}
36+
}
37+
38+
const readdirectoryrecursive = (dir, files = []) => {
39+
if (isdirectory(dir)) {
40+
return fs.readdirSync(dir)
41+
.map(content => readdirectoryrecursive(path.join(dir, content), files))
42+
.reduce((s, c) => s.concat(c), files);
43+
}
44+
45+
return files.concat(dir);
46+
}
47+
48+
//#endregion
49+
50+
const typedefs = readdirectoryrecursive(srcdir, []).filter(a => a.endsWith('.d.ts'));
51+
52+
// copy typings
53+
typedefs.forEach(typedef => {
54+
if (isfile(typedef)) {
55+
Object.keys(outmap).forEach(key => {
56+
const destfile = typedef.replace('src', path.join('lib', key));
57+
ensuredir(path.dirname(destfile));
58+
fs.copyFileSync(typedef, destfile);
59+
});
60+
}
61+
});
62+
63+
// cycle througt outmap and copy files
64+
Object.keys(outmap).forEach(key => {
65+
const outdirbase = outmap[key];
66+
const files = readdirectoryrecursive(outdirbase).filter(a => !a.endsWith('.d.ts'));
67+
68+
files.forEach(filename => {
69+
const destfile = filename.replace('src', '');
70+
ensuredir(path.dirname(destfile));
71+
fs.renameSync(filename, destfile);
72+
})
73+
});
74+
75+
// copy package.json
76+
fs.writeFileSync(path.join(outdir, 'package.json'), JSON.stringify(packagejson, null, 2));
77+
78+
fs.copyFileSync(path.join(projectdir, 'README.md'), path.join(outdir, 'README.md'));
79+
fs.copyFileSync(path.join(projectdir, 'LICENSE'), path.join(outdir, 'LICENSE'));
80+
fs.copyFileSync(path.join(projectdir, '.gitignore'), path.join(outdir, '.gitignore'));
81+
fs.copyFileSync(path.join(projectdir, '.npmignore'), path.join(outdir, '.npmignore'));

src/index.res

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@genType
2+
type foo = Value1 | Value2 | Value3
3+
4+
"helloworld"
5+
->Js.log
6+
7+
42
8+
->Belt.Int.toString
9+
->String.concat(list{"The answer is"})
10+
->Js.log

yarn.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
gentype@^4.1.0:
6+
version "4.1.0"
7+
resolved "https://registry.yarnpkg.com/gentype/-/gentype-4.1.0.tgz#ebc194894ec0aa637b082661419c6101bb0139b5"
8+
integrity sha512-M3Dqd2tokJ7X1KLyMP0bqwk/TvOPI5hYW24j2Jy5RMToWfdKvdqoxWsMTWuPxWauSi/CBQjJS/AOhqsd0Sy1Mw==
9+
10+
rescript@^9.1.4:
11+
version "9.1.4"
12+
resolved "https://registry.yarnpkg.com/rescript/-/rescript-9.1.4.tgz#1eb126f98d6c16942c0bf0df67c050198e580515"
13+
integrity sha512-aXANK4IqecJzdnDpJUsU6pxMViCR5ogAxzuqS0mOr8TloMnzAjJFu63fjD6LCkWrKAhlMkFFzQvVQYaAaVkFXw==

0 commit comments

Comments
 (0)