Skip to content

Commit dec5300

Browse files
committed
added support for Deno runtime.
1 parent 6f6c9c7 commit dec5300

10 files changed

+135
-12
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018-2021 Nexss.com
3+
Copyright (c) 2018-2022 Nexss.com
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,29 @@ Each language in the Nexss Programmer has predefined templates which can be used
1515

1616
Enter command 'nexss file add myfile.js'
1717
and type learn for finding templates which starts with 'learn' keyword. [Picture above]
18+
19+
## JavaScript Runtimes
20+
21+
- Node.js - <https://nodejs.org/en/>
22+
- Deno - <https://deno.land>
23+
24+
## To change runtimes/compilers
25+
26+
```sh
27+
nexss js default compiler # displays all available runtimes/compilers
28+
nexss js default compiler deno # to set the Deno compiler
29+
nexss js default compiler node # to set the Node.js compiler
30+
nexss lua default compiler unset # to reset to defaults (Node.js)
31+
32+
nexss js default compiler --nocache # use --nocache if you have changed configuration files manually
33+
34+
nexss f a my.js --compiler=deno --nocache
35+
```
36+
37+
OR put at the top of your file/program. If will install compiler on 'nexss yourprogram.js'
38+
39+
```js
40+
// nexss-compiler: deno
41+
42+
console.log(`Hello from Deno! ${Deno.version.deno}`);
43+
```

nodejs.darwin.nexss.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ languageConfig.compilers = {
77
args: "<file>",
88
help: ``,
99
},
10+
deno: {
11+
install:
12+
process.replacePMByDistro(`${sudo}apt-get install unzip`) +
13+
`
14+
curl -fsSL https://deno.land/x/install/install.sh | sh`,
15+
command: "deno",
16+
args: "run <file>",
17+
help: ``,
18+
templates: "templates_deno",
19+
},
1020
};
1121

1222
module.exports = languageConfig;

nodejs.freebsd.nexss.config.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
let languageConfig = Object.assign({}, require("./nodejs.win32.nexss.config"));
2+
3+
let sudo = process.sudo;
4+
5+
languageConfig.compilers = {
6+
node: {
7+
install: `${sudo}pkg update && pkg install node12`, // but this is installed already.
8+
command: "node",
9+
args: "<file>",
10+
help: ``,
11+
},
12+
deno: {
13+
install:
14+
process.replacePMByDistro(`${sudo}apt-get install unzip`) +
15+
`
16+
curl -fsSL https://deno.land/x/install/install.sh | sh`,
17+
command: "deno",
18+
args: "run <file>",
19+
help: ``,
20+
templates: "templates_deno",
21+
},
22+
};
23+
24+
const distro = process.distro;
25+
26+
// This function just replace all apt-get,apt to the right distribution pkg installer.
27+
languageConfig.compilers.node.install = process.replacePMByDistro(
28+
languageConfig.compilers.node.install
29+
);
30+
31+
languageConfig.dist = distro;
32+
33+
module.exports = languageConfig;

nodejs.linux.nexss.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ languageConfig.compilers = {
99
args: "<file>",
1010
help: ``,
1111
},
12+
deno: {
13+
install:
14+
process.replacePMByDistro(`${sudo}apt-get install unzip`) +
15+
`
16+
curl -fsSL https://deno.land/x/install/install.sh | sh`,
17+
command: "deno",
18+
args: "run <file>",
19+
help: ``,
20+
templates: "templates_deno",
21+
},
1222
};
1323

1424
const distro = process.distro;

nodejs.win32.nexss.config.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ languageConfig.compilers = {
4242
args: "<file>",
4343
help: ``,
4444
},
45+
deno: {
46+
install: "scoop install deno",
47+
command: "deno",
48+
args: "run <file>",
49+
help: ``,
50+
templates: "templates_deno",
51+
},
4552
};
4653
languageConfig.errors = require("./nexss.nodejs.errors");
4754
languageConfig.languagePackageManagers = {
@@ -55,20 +62,27 @@ languageConfig.languagePackageManagers = {
5562
help: "npm help",
5663
version: "npm --version",
5764
init: () => {
58-
if (
59-
!require("fs").existsSync(
60-
require("path").join(process.cwd(), "package.json")
61-
)
62-
) {
63-
require("child_process").execSync("npm init -y", { stdio: "inherit" });
64-
console.log("initialized npm project.");
65+
const { existsSync } = require("fs");
66+
const { join } = require("path");
67+
const { execSync } = require("child_process");
68+
if (!existsSync(join(process.cwd(), "package.json"))) {
69+
console.log("Setup npm project");
70+
execSync("npm init -y");
71+
console.log("Setup npm project: done.");
72+
} else {
73+
console.log("npm project already initialized.");
74+
}
75+
76+
if (!existsSync(join(process.cwd(), ".gitignore"))) {
77+
console.log("Creating .gitignore");
78+
execSync("npx gitignore node"); // creates tsconfig.json with all the descriptions
6579
} else {
66-
console.log("npm already initialized.");
80+
console.log(".gitignore is already setup");
6781
}
6882
},
6983
// if command not found in specification
7084
// run directly on package manager
71-
else: "npm <default> <args>",
85+
else: "npm",
7286
},
7387
yarn: {
7488
installation: "scoop install yarn",

templates/helloWorld.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Nexss PROGRAMMER 2.0.0 - NodeJS
22
// Default template for JSON Data
33
// STDIN
4-
process.stdin.on("data", function(NexssStdin) {
4+
process.stdin.on("data", function (NexssStdin) {
55
let NexssStdout;
66
try {
77
NexssStdout = JSON.parse(NexssStdin.toString());
@@ -16,7 +16,7 @@ process.stdin.on("data", function(NexssStdin) {
1616
process.stdout.write(JSON.stringify(NexssStdout));
1717
});
1818

19-
process.stdin.on("end", function() {
19+
process.stdin.on("end", function () {
2020
//On Windows below is not needed.
2121
process.exit(0);
2222
});

templates_deno/!empty.js

Whitespace-only changes.

templates_deno/default.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Deno runtime default.js for Nexss Programmer 2.x
2+
3+
const buf = new Uint8Array(4096); // Adjust to your needs
4+
5+
const n = await Deno.stdin.read(buf);
6+
if (n == Deno.EOF) {
7+
console.log("No Input");
8+
} else {
9+
const NexssStdin = new TextDecoder().decode(buf.subarray(0, n));
10+
let NexssStdout = JSON.parse(NexssStdin.toString());
11+
12+
NexssStdout.test = `test`;
13+
14+
console.log(JSON.stringify(NexssStdout));
15+
}

templates_deno/helloWorld.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Deno runtime helloWorld.js for Nexss Programmer 2.x
2+
3+
const buf = new Uint8Array(4096); // Adjust to your needs
4+
5+
const n = await Deno.stdin.read(buf);
6+
if (n == Deno.EOF) {
7+
console.log("No Input");
8+
} else {
9+
const NexssStdin = new TextDecoder().decode(buf.subarray(0, n));
10+
let NexssStdout = JSON.parse(NexssStdin.toString());
11+
12+
NexssStdout.DenoOutput = `Hello from Deno! ${Deno.version.deno}`;
13+
14+
console.log(JSON.stringify(NexssStdout));
15+
}

0 commit comments

Comments
 (0)