Skip to content

Commit fd7f834

Browse files
authored
Merge pull request #1 from jevko/shebang-v2
v0.2
2 parents 2221c55 + 2aaa0bd commit fd7f834

File tree

3 files changed

+188
-138
lines changed

3 files changed

+188
-138
lines changed

README.md

Lines changed: 66 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,104 +20,128 @@ It can be used to easily integrate Jevko formats into applications that deal wit
2020

2121
<!-- In the future, JevkoML could also be used directly by various tools, for increased efficiency. -->
2222

23-
## Usage
23+
## Installation
2424

25-
If Jevko CLI is [installed](#installation-with-deno) you can invoke it as:
25+
These instructions will guide you through installing Deno and then using it to install `jevko` as a command in your system, so that you can invoke it from anywhere.
26+
27+
### Install Deno
28+
29+
Jevko CLI has one dependency: [Deno](https://deno.land/).
30+
31+
Fortunately Deno is very nice and [easy to install](https://deno.land/[email protected]/getting_started/installation). Deno is distributed as a single binary executable with no external dependencies.
32+
33+
This command will run Deno's official installation script on Linux or macOS:
2634

2735
```
28-
jevko
36+
curl -fsSL https://deno.land/x/install/install.sh | sh
2937
```
3038

31-
Without arguments, `jevko` will accept input from standard input until you press CTRL+D.
39+
This one will do the same on Windows, if PowerShell is available:
3240

33-
<!-- todo?: mvp console highlighting? -->
41+
```
42+
irm https://deno.land/install.ps1 | iex
43+
```
3444

35-
You can also provide a path to a file as an argument:
45+
For more installation options or if you run into any problems, see the official instructions on [deno.land](https://deno.land/[email protected]/getting_started/installation) and on [denoland GitHub](https://github.com/denoland/deno_install).
3646

37-
<!-- get syntax highlighting for vscode -->
47+
### Install Jevko CLI with Deno
48+
49+
If you have [Deno installed](#install-deno) and Deno's installation root's bin directory (something like `/home/USER/.deno/bin`) [added to `PATH`](#tip-get-a-list-of-directories-in-your-path) then you can use the following command to install `jevko` directly from GitHub master branch:
3850

3951
```
40-
jevko filename.jevkoml
52+
deno install --allow-read --allow-write --allow-run https://raw.githubusercontent.com/jevko/jevko-cli/master/jevko.js
4153
```
4254

43-
This will convert a file named `filename.jevkoml` into HTML/XML and output the result to standard output.
55+
Note: if you haven't added Deno's installation root to `PATH`, then `jevko` won't be recognized as a command.
4456

45-
To output to a file instead of the standard output, you can either use the redirect facility of your shell:
57+
To install a specific version of the Jevko CLI, specify it in the URL in place of master:
4658

4759
```
48-
jevko filename.jevkoml > outputfile.html
60+
deno install --allow-read --allow-write --allow-run https://raw.githubusercontent.com/jevko/jevko-cli/v0.1.0/jevko.js
4961
```
5062

51-
Or you can put an `/output` directive with the output file name at the top of the input file:
63+
See the [Jevko CLI GitHub Releases](https://github.com/jevko/jevko-cli/releases) for a list of available versions.
64+
65+
### Alternative: install without editing PATH
66+
67+
If you can't or prefer not to change your `PATH`, you can alternatively install `jevko` to a [directory that is already in the `PATH`](#tip-get-a-list-of-directories-in-your-path), by adding the `--root` option to `deno install`. E.g. if your `PATH` contains `~/.local/bin`, then you can run:
5268

5369
```
54-
/output [outputfile.html]
70+
deno install --root ~/.local/ --allow-read --allow-write --allow-run https://raw.githubusercontent.com/jevko/jevko-cli/master/jevko.js
5571
```
5672

57-
now if you run:
73+
to install `jevko` under `~/.local/bin`.
74+
75+
### Tip: get a list of directories in your PATH
76+
77+
You can get a list of directories in your `PATH` by running:
5878

5979
```
60-
jevko filename.jevkoml
80+
echo $PATH
6181
```
6282

63-
it will output to `outputfile.html` instead of standard output.
64-
65-
By default, Jevko CLI infers the Jevko format of the input file by extension. You can also specify the format by putting the `/jevko` directive at the top of the input file:
83+
This should print something like:
6684

6785
```
68-
/jevko [jevkoml]
86+
/home/USER/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin
6987
```
7088

71-
## Dependencies
89+
## Usage
7290

73-
Jevko CLI has one dependency: [Deno](https://deno.land/).
91+
If Jevko CLI is [installed](#installation-with-deno) you can invoke it as:
7492

75-
Fortunately Deno is very nice and [easy to install](https://deno.land/[email protected]/getting_started/installation).
93+
```
94+
jevko
95+
```
7696

77-
<!-- I recommend installing it, as it makes installing and managing `jevko` easy and efficient. -->
97+
Without arguments, `jevko` will accept input from standard input until you press CTRL+D.
7898

79-
## Installation with Deno
99+
<!-- todo?: mvp console highlighting? -->
80100

81-
These instructions will guide you through using Deno to install `jevko` as a command in your system, so that you can invoke it from anywhere.
101+
You can also provide a path to a file as an argument:
82102

83-
If you have [Deno installed](#dependencies) and Deno's installation root's bin directory (something like `/home/USER/.deno/bin`) [added to `PATH`](#tip-get-a-list-of-directories-in-your-path) then you can use the following command to install `jevko` directly from GitHub master branch:
103+
<!-- get syntax highlighting for vscode -->
84104

85105
```
86-
deno install --allow-read --allow-write --allow-run https://raw.githubusercontent.com/jevko/jevko-cli/master/jevko.js
106+
jevko filename.jevkoml
87107
```
88108

89-
Note: if you haven't added Deno's installation root to `PATH`, then `jevko` won't be recognized as a command.
109+
This will convert a file named `filename.jevkoml` into HTML/XML and output the result to standard output.
90110

91-
To install a specific version of jevko-cli, specify it in the URL in place of master:
111+
To output to a file instead of the standard output, you can either use the redirect facility of your shell:
92112

93113
```
94-
deno install --allow-read --allow-write --allow-run https://raw.githubusercontent.com/jevko/jevko-cli/v0.1.0/jevko.js
114+
jevko filename.jevkoml > outputfile.html
95115
```
96116

97-
### Alternative: install without editing PATH
117+
Or you can put an `output` directive with the output file name at the top of the input file:
98118

99-
If you can't or prefer not to change your `PATH`, you can alternatively install `jevko` to a [directory that is already in the `PATH`](#tip-get-a-list-of-directories-in-your-path), by adding the `--root` option to `deno install`. E.g. if your `PATH` contains `~/.local/bin`, then you can run:
119+
<!-- todo: describe the new way of doing directives -- probly change name of directives to sth else -->
100120

101121
```
102-
deno install --root ~/.local/ --allow-read --allow-write --allow-run https://raw.githubusercontent.com/jevko/jevko-cli/master/jevko.js
122+
[
123+
output [outputfile.html]
124+
]
103125
```
104126

105-
to install `jevko` under `~/.local/bin`.
106-
107-
## Tip: get a list of directories in your PATH
108-
109-
You can get a list of directories in your `PATH` by running:
127+
now if you run:
110128

111129
```
112-
echo $PATH
130+
jevko filename.jevkoml
113131
```
114132

115-
This should print something like:
133+
it will output to `outputfile.html` instead of standard output.
134+
135+
By default, Jevko CLI infers the Jevko format of the input file by extension. You can also specify the format by putting the `format` directive at the top of the input file:
116136

117137
```
118-
/home/USER/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin
138+
[
139+
format [jevkoml]
140+
]
119141
```
120142

121-
# Features coming soon
122143

144+
## Features coming soon
145+
146+
<!-- todo: this should be a separate lib (perhaps local to this repo) -->
123147
* import files as jevkos or text (currently implemented in jevkoml)

jevko.js

Lines changed: 20 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,34 @@
1-
import {jevkoml} from 'https://raw.githubusercontent.com/jevko/jevkoml/v0.3.4/jevkoml.js'
2-
import {jevkocfg} from 'https://raw.githubusercontent.com/jevko/jevkoconfig1.js/v0.1.1/jevkocfg.js'
3-
import {jevkodata} from 'https://raw.githubusercontent.com/jevko/jevkodata/v0.1.0/jevkodata.js'
1+
import {map, prep as prepdata} from 'https://raw.githubusercontent.com/jevko/jevkodata/v0.2.1/mod.js'
42

53
import {parseJevkoWithHeredocs} from 'https://cdn.jsdelivr.net/gh/jevko/[email protected]/mod.js'
64

7-
import {readTextFileSync, readStdinText, writeTextFileSync} from './io.js'
5+
import {main as main_v0_2_0} from 'https://raw.githubusercontent.com/jevko/jevko-cli/v0.2.0/main.js'
86

9-
import { dirname, join, extname } from "https://deno.land/[email protected]/path/mod.ts";
7+
import {main} from './main.js'
108

11-
// todo: exactly 1?
12-
let source
13-
let dir
14-
let format
15-
if (Deno.args.length > 0) {
16-
const fileName = Deno.args[0]
17-
source = readTextFileSync(fileName)
18-
dir = dirname(fileName)
19-
format = extname(fileName).slice(1)
20-
} else {
21-
source = await readStdinText()
22-
dir = '.'
23-
// todo: read format from /jevko directive
24-
}
25-
26-
const jevko = parseJevkoWithHeredocs(source)
9+
const getArgmap = () => {
10+
if (Deno.args.length === 0) return Object.create(null)
11+
const argj = prepdata(parseJevkoWithHeredocs(Deno.args.join(' ')))
12+
const argmap = map(argj.subjevkos)
2713

28-
const string = jevko => {
29-
const {subjevkos, suffix} = jevko
14+
const fileName = argj.suffix.trim()
3015

31-
if (subjevkos.length > 0) throw Error("oops")
32-
33-
return suffix
34-
}
35-
36-
const listOfString = jevko => {
37-
const {subjevkos, suffix} = jevko
38-
39-
if (subjevkos.length === 0) return [suffix]
40-
41-
const ret = []
42-
for (const {prefix, jevko} of subjevkos) {
43-
if (prefix !== '') throw Error('oops')
44-
ret.push(string(jevko))
16+
if (fileName !== '') {
17+
if ('input' in argmap) throw Error('oops')
18+
argmap.input = fileName
4519
}
46-
return ret
20+
return argmap
4721
}
4822

49-
//?todo: rename /output to /to file
50-
const prep = jevko => {
51-
const {subjevkos, ...rest} = jevko
52-
53-
let output, format
54-
const subs = []
55-
for (const sub of subjevkos) {
56-
const {prefix, jevko} = sub
23+
const argmap = getArgmap()
5724

58-
const trimmed = prefix.trim()
25+
const {version} = argmap
26+
if (version !== undefined) {
27+
if (version === '0.2.0') {
28+
// const main = await import('https://raw.githubusercontent.com/jevko/jevko-cli/v0.2.0/main.js')
5929

60-
// top-level directives
61-
//?todo: perhaps stop reading when trimmed.startsWith('/') === false (i.e., they must all appear at the very top to be valid; otoh should allow hashbang, so perhaps sth like breakPrefix should be utilized)
62-
if (trimmed.startsWith('/')) {
63-
const directive = trimmed.slice(1).trim()
64-
// todo: maybe support import & paste here as well
65-
// paste: how to be consistent accross formats?
66-
if (directive === 'jevko') {
67-
// enforce only one occurence of the directive
68-
if (format !== undefined) throw Error('oops')
69-
format = string(jevko)
70-
continue
71-
} else if (directive === 'output') {
72-
// enforce only one occurence of the directive
73-
if (output !== undefined) throw Error('oops')
74-
output = string(jevko)
75-
continue
76-
}
77-
// else throw Error(`unknown directive: ${tag}`)
78-
}
79-
80-
subs.push(sub)
81-
}
82-
83-
return {
84-
jevko: {subjevkos: subs, ...rest},
85-
output,
86-
format,
87-
}
88-
}
89-
90-
const {jevko: preppedJevko, output, format: f} = prep(jevko)
91-
92-
if (format === undefined) {
93-
format = f
30+
main_v0_2_0(argmap)
31+
} else throw Error(`Unknown version: ${version}`)
9432
} else {
95-
if (f !== undefined && format !== f) throw Error(`extension and declared format inconsistent`)
33+
main(argmap)
9634
}
97-
98-
let result
99-
if (format === 'jevkoml') {
100-
// todo: impl jevkoml which takes in a jevko as first arg
101-
const document = await jevkoml(preppedJevko, dir)
102-
result = document
103-
} else if (format === 'jevkocfg') {
104-
result = jevkocfg(preppedJevko)
105-
} else if (format === 'jevkodata') {
106-
result = jevkodata(preppedJevko)
107-
} else throw Error(`Unrecognized format: ${format}`)
108-
109-
if (output === undefined) console.log(result)
110-
else writeTextFileSync(join(dir, output), result)

0 commit comments

Comments
 (0)