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 , map , prep as prepdata } from 'https://raw.githubusercontent.com/jevko/jevkodata/v0.2.0/mod.js'
1+ import { map , prep as prepdata } from 'https://raw.githubusercontent.com/jevko/jevkodata/v0.2.1/mod.js'
42
53import { parseJevkoWithHeredocs } from 'https://cdn.jsdelivr.net/gh/jevko/parsejevko.js@v0.1.8/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 , isAbsolute } from "https://deno.land/std@0.165.0/path/mod.ts" ;
10-
11- // todo: exactly 1?
12- let source
13- let dir
14- let format
7+ import { main } from './main.js'
158
169const getArgmap = ( ) => {
10+ if ( Deno . args . length === 0 ) return Object . create ( null )
1711 const argj = prepdata ( parseJevkoWithHeredocs ( Deno . args . join ( ' ' ) ) )
1812 const argmap = map ( argj . subjevkos )
1913
@@ -26,112 +20,15 @@ const getArgmap = () => {
2620 return argmap
2721}
2822
29- const withoutShebang = source => {
30- if ( source . startsWith ( '#!' ) ) {
31- const index = source . indexOf ( '\n' )
32- if ( index === - 1 ) return ""
33- return source . slice ( index )
34- }
35- return source
36- }
23+ const argmap = getArgmap ( )
3724
38- let argmap
39- if ( Deno . args . length > 0 ) {
40- argmap = getArgmap ( )
41- } else {
42- argmap = Object . create ( null )
43- }
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')
4429
45- if ( 'format' in argmap ) {
46- format = argmap . format
47- }
48-
49- if ( 'input' in argmap ) {
50- const fileName = argmap . input
51- source = withoutShebang ( readTextFileSync ( fileName ) )
52- dir = dirname ( fileName )
53- // format from args overrides extension
54- // alternatively could error if extension doesn't match
55- if ( format === undefined ) format = extname ( fileName ) . slice ( 1 )
30+ main_v0_2_0 ( argmap )
31+ } else throw Error ( `Unknown version: ${ version } ` )
5632} else {
57- source = await readStdinText ( )
58- dir = '.'
59- }
60-
61- const jevko = parseJevkoWithHeredocs ( source )
62-
63- const string = jevko => {
64- const { subjevkos, suffix} = jevko
65-
66- if ( subjevkos . length > 0 ) throw Error ( "oops" )
67-
68- return suffix
69- }
70-
71- const listOfString = jevko => {
72- const { subjevkos, suffix} = jevko
73-
74- if ( subjevkos . length === 0 ) return [ suffix ]
75-
76- const ret = [ ]
77- for ( const { prefix, jevko} of subjevkos ) {
78- if ( prefix !== '' ) throw Error ( 'oops' )
79- ret . push ( string ( jevko ) )
80- }
81- return ret
33+ main ( argmap )
8234}
83-
84- const prep = jevko => {
85- const { subjevkos, ...rest } = jevko
86-
87- let subs
88- let props = Object . create ( null )
89- if ( subjevkos . length > 0 ) {
90- let i = 0
91- const sub0 = subjevkos [ 0 ]
92- const pref = sub0 . prefix
93-
94- if ( pref . trim ( ) === '' ) {
95- // interpret top-level directives
96- const tjevko = sub0 . jevko
97- const xyz = prepdata ( tjevko )
98- props = map ( xyz . subjevkos )
99-
100- ++ i
101- }
102-
103- subs = subjevkos . slice ( i )
104- } else {
105- subs = [ ]
106- }
107-
108- return {
109- jevko : { subjevkos : subs , ...rest } ,
110- props,
111- }
112- }
113-
114- const { jevko : preppedJevko , props} = prep ( jevko )
115-
116- if ( format === undefined ) {
117- format = props . format
118- } else {
119- const f = props . format
120- if ( f !== undefined && format !== f ) throw Error ( `declared format (${ format } ) inconsistent with command line format or file extension (${ f } )` )
121- }
122-
123- let result
124- if ( format === 'jevkoml' ) {
125- // todo: impl jevkoml which takes in a jevko as first arg
126- const document = await jevkoml ( preppedJevko , dir )
127- result = document
128- } else if ( format === 'jevkocfg' ) {
129- result = jevkocfg ( preppedJevko )
130- } else if ( format === 'jevkodata' ) {
131- result = jevkodata ( preppedJevko )
132- } else throw Error ( `Unrecognized format: ${ format } ` )
133-
134-
135- const { output} = props
136- if ( output === undefined ) console . log ( result )
137- else writeTextFileSync ( join ( dir , output ) , result )
0 commit comments