Skip to content

Commit a14506f

Browse files
committed
first commit
0 parents  commit a14506f

File tree

8 files changed

+231
-0
lines changed

8 files changed

+231
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/bower_components/
2+
/node_modules/
3+
/.pulp-cache/
4+
/output/
5+
/.psci*
6+
/src/.webpack.js

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: node_js
2+
sudo: false
3+
node_js:
4+
- stable
5+
install:
6+
- npm install purescript pulp bower -g
7+
- bower install
8+
script:
9+
- pulp build

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Thimoteus (https://github.com/Thimoteus)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
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, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# purescript-node-os [![Build Status](https://travis-ci.org/Thimoteus/purescript-node-os.svg?branch=master)](https://travis-ci.org/Thimoteus/purescript-node-os)
2+
3+
Bindings for node's "os" module.
4+
5+
Documentation is available on [Pursuit](http://pursuit.purescript.org/packages/purescript-node-os).

bower.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "purescript-node-os",
3+
"version": "1.0.0",
4+
"license": "MIT",
5+
"moduleType": [
6+
"node"
7+
],
8+
"ignore": [
9+
"**/.*",
10+
"node_modules",
11+
"bower_components",
12+
"output"
13+
],
14+
"dependencies": {
15+
"purescript-maps": "^0.5.7",
16+
"purescript-datetime": "^0.9.2"
17+
}
18+
}

src/Node/OS.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use strict";
2+
3+
// module Node.OS
4+
5+
var os = require('os');
6+
7+
exports.eol = os.EOL;
8+
exports.archImpl = os.arch;
9+
exports.cpus = os.cpus;
10+
exports.endiannessImpl = os.endianness;
11+
exports.freemem = os.freemem;
12+
exports.homedir = os.homedir;
13+
exports.hostname = os.hostname;
14+
exports.loadavgImpl = os.loadavg;
15+
exports.networkInterfaces = os.networkInterfaces;
16+
exports.platformImpl = os.platform;
17+
exports.release = os.release;
18+
exports.tmpdir = os.tmpdir;
19+
exports.totalmem = os.totalmem;
20+
exports.ostype = os.type;
21+
exports.uptime = os.uptime;

src/Node/OS.purs

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
module Node.OS
2+
( OS, NetworkInterface, CPU
3+
, eol
4+
, Arch(..), arch
5+
, cpus
6+
, Endianness(..), endianness
7+
, freemem
8+
, loadavg
9+
, homedir
10+
, hostname
11+
, Platform(..), platform
12+
, release
13+
, tmpdir
14+
, totalmem
15+
, ostype
16+
, uptime
17+
, networkInterfaces
18+
) where
19+
20+
import Prelude
21+
22+
import Data.Array ((!!))
23+
import Data.Maybe (fromMaybe)
24+
import Data.StrMap (StrMap)
25+
import Data.Time (Milliseconds, Seconds)
26+
27+
import Control.Bind ((=<<))
28+
import Control.Monad.Eff (Eff)
29+
30+
type NetworkInterface = { address :: String
31+
, netmask :: String
32+
, family :: String
33+
, mac :: String
34+
, internal :: Boolean
35+
}
36+
37+
type CPU = { model :: String
38+
, speed :: Int
39+
, times :: { user :: Milliseconds
40+
, nice :: Milliseconds
41+
, sys :: Milliseconds
42+
, idle :: Milliseconds
43+
, irq :: Milliseconds } }
44+
45+
foreign import data OS :: !
46+
47+
foreign import eol :: Char
48+
49+
foreign import archImpl :: forall eff. Eff ( os :: OS | eff ) String
50+
51+
foreign import cpus :: forall eff. Eff ( os :: OS | eff ) (Array CPU)
52+
53+
foreign import endiannessImpl :: forall eff. Eff ( os :: OS | eff ) String
54+
55+
foreign import freemem :: forall eff. Eff ( os :: OS | eff ) Number
56+
57+
foreign import homedir :: forall eff. Eff ( os :: OS | eff ) String
58+
59+
foreign import hostname :: forall eff. Eff ( os :: OS | eff ) String
60+
61+
foreign import loadavgImpl :: forall eff. Eff ( os :: OS | eff ) (Array Number)
62+
63+
foreign import platformImpl :: forall eff. Eff ( os :: OS | eff ) String
64+
65+
foreign import release :: forall eff. Eff ( os :: OS | eff ) String
66+
67+
foreign import tmpdir :: forall eff. Eff ( os :: OS | eff ) String
68+
69+
foreign import totalmem :: forall eff. Eff ( os :: OS | eff ) Number
70+
71+
foreign import ostype :: forall eff. Eff ( os :: OS | eff ) String
72+
73+
foreign import uptime :: forall eff. Eff ( os :: OS | eff ) Seconds
74+
75+
foreign import networkInterfaces :: forall eff. Eff ( os :: OS | eff ) (StrMap (Array NetworkInterface))
76+
77+
loadavg :: forall eff. Eff ( os :: OS | eff ) { one :: Number, five :: Number, fifteen :: Number }
78+
loadavg = pure <<< fromMaybe {one: 0.0, five: 0.0, fifteen: 0.0} <<< extract =<< loadavgImpl
79+
where
80+
extract xs = do
81+
one <- xs !! 0
82+
five <- xs !! 1
83+
fifteen <- xs !! 2
84+
pure {one, five, fifteen}
85+
86+
data Arch = X64 | ARM | IA32 | UnknownArch
87+
88+
derive instance eqArch :: Eq Arch
89+
90+
instance showArch :: Show Arch where
91+
show X64 = "X64"
92+
show ARM = "ARM"
93+
show IA32 = "IA32"
94+
show UnknownArch = "UnknownArch"
95+
96+
arch :: forall eff. Eff ( os :: OS | eff ) Arch
97+
arch = do
98+
a <- archImpl
99+
pure case a of
100+
"x64" -> X64
101+
"arm" -> ARM
102+
"ia32" -> IA32
103+
_ -> UnknownArch
104+
105+
data Endianness = LittleEndian | BigEndian | UnknownEndian
106+
107+
derive instance eqEndianness :: Eq Endianness
108+
109+
instance showEndianness :: Show Endianness where
110+
show LittleEndian = "LittleEndian"
111+
show BigEndian = "BigEndian"
112+
show UnknownEndian = "UnknownEndian"
113+
114+
endianness :: forall eff. Eff ( os :: OS | eff ) Endianness
115+
endianness = do
116+
e <- endiannessImpl
117+
pure case e of
118+
"BE" -> BigEndian
119+
"LE" -> LittleEndian
120+
_ -> UnknownEndian
121+
122+
data Platform = Darwin | FreeBSD | Linux | SunOS | Win32 | UnknownPlatform
123+
124+
derive instance eqPlatform :: Eq Platform
125+
126+
instance showPlatform :: Show Platform where
127+
show Darwin = "Darwin"
128+
show FreeBSD = "FreeBSD"
129+
show Linux = "Linux"
130+
show SunOS = "SunOS"
131+
show Win32 = "Win32"
132+
show UnknownPlatform = "UnknownPlatform"
133+
134+
platform :: forall eff. Eff ( os :: OS | eff ) Platform
135+
platform = do
136+
p <- platformImpl
137+
pure case p of
138+
"linux" -> Linux
139+
"darwin" -> Darwin
140+
"win32" -> Win32
141+
"freebsd" -> FreeBSD
142+
"sunos" -> SunOS
143+
_ -> UnknownPlatform

test/Main.purs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Test.Main where
2+
3+
import Prelude (Unit)
4+
import Control.Monad.Eff (Eff)
5+
import Control.Monad.Eff.Console (CONSOLE, log)
6+
7+
main :: forall e. Eff (console :: CONSOLE | e) Unit
8+
main = do
9+
log "You should add some tests."

0 commit comments

Comments
 (0)