Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

yarn.lock -diff linguist-generated
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

dist/
node_modules/

build/
lib/

/index.html
16 changes: 8 additions & 8 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

/build
/examples
/src

/gulpfile.*
/index.*
/webpack.*
/template.cirru
dist/
examples/
src/
/index.html
webpack.*
template.cirru
upload.edn
yarn.lock
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ The AST transformer of CirruScript is Scirpus https://github.com/Cirru/scirpus .

Here is a demo of calling compiler:

```
npm i --save cirru-script
```bash
yarn add cirru-script
```

```coffee
Expand All @@ -24,31 +24,39 @@ code = "console.log :demo"
script.compile code
```

I use [gulp-cirru-script][gulp] to compile the code.

[gulp]: https://github.com/Cirru/gulp-cirru-script

### Command-line tool

By installing CirruScript at global, you'll get command `cirru-script`(and `crs` for short):
By installing CirruScript at global, you'll get command `cirruscript`(and `crs` for short):

```text
npm i -g cirru-script
```

```text
crs
cirruscript
# enter REPL
cirru-script>
cirruscript>
```

```text
crs a.cirru
cirruscript a.cirru
# evaluates a file
```

File compiling and SourceMaps support might come in the future.

Add `DISPLAY_JS` for displaying compiled js:

```bash
DISPLAY_JS=true cirruscript a.cirru
```

`compile` sub-command can compile code:

```bash
cirruscript compile from-dir to-dir
```

### Syntax

```cirru
Expand Down
File renamed without changes.
62 changes: 0 additions & 62 deletions gulpfile.cirru

This file was deleted.

6 changes: 0 additions & 6 deletions gulpfile.js

This file was deleted.

53 changes: 31 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
{
"name": "cirru-script",
"version": "0.5.5",
"version": "0.6.0-a3",
"description": "Generated JavaScript from Cirru Grammar",
"main": "lib/compiler.js",
"scripts": {
"clean": "rm -rfv dist/*",
"watch": "yarn html && webpack-dev-server --config webpack.dev.cirru",
"release": "yarn clean && webpack --config webpack.release.cirru && yarn release-html && cp -rv examples dist/",
"html": "cirru-script template.cirru",
"release-html": "env=release cirru-script template.cirru",
"up": "yarn release && tiye-up",
"compile": "coffee -o lib/ -bc src/",
"prepare": "yarn compile",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "jiyinyiyong",
Expand All @@ -13,27 +21,27 @@
"javascript"
],
"devDependencies": {
"coffee-loader": "^0.7.2",
"css-loader": "^0.9.1",
"del": "^1.1.1",
"gulp": "^3.8.11",
"gulp-cirru-html": "0.0.4",
"gulp-cirru-script": "0.0.2-2",
"gulp-coffee": "^2.3.1",
"gulp-rename": "^1.2.0",
"json-loader": "^0.5.3",
"rsyncwrapper": "^0.4.2",
"run-sequence": "^1.0.2",
"stir-template": "^0.1.2",
"style-loader": "^0.8.3",
"webpack": "^1.5.3",
"webpack-dev-server": "^1.7.0"
"assets-webpack-plugin": "^3.9.10",
"babel-preset-stage-2": "^6.24.1",
"cirru-script": "^0.5.5",
"coffee-loader": "^0.9.0",
"coffeescript": "^2.4.1",
"css-loader": "^3.4.0",
"duplicate-package-checker-webpack-plugin": "^3.0.0",
"file-loader": "^5.0.2",
"http-server": "^0.12.0",
"stir-template": "^0.2.2",
"style-loader": "^1.1.2",
"webpack": "^4.41.5",
"webpack-bundle-analyzer": "^3.6.0",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.10.1",
"webpack-hud": "^0.1.2"
},
"dependencies": {
"babel-core": "6.11.4",
"babel-preset-es2015": "6.9.0",
"cirru-parser": "0.10.x",
"scirpus": "0.5.3"
"@babel/standalone": "^7.7.7",
"cirru-parser": "^0.10.7",
"scirpus": "^0.5.3"
},
"repository": {
"type": "git",
Expand All @@ -43,8 +51,9 @@
"url": "https://github.com/Cirru/cirru-script/issues"
},
"bin": {
"cirru-script": "./bin/cirru-script.js",
"crs": "./bin/cirru-script.js"
"cirru-script": "./bin/cirruscript.js",
"cirruscript": "./bin/cirruscript.js",
"crs": "./bin/cirruscript.js"
},
"homepage": "https://github.com/Cirru/cirru-script"
}
68 changes: 65 additions & 3 deletions src/command.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,67 @@ m = require 'module'

compiler = require './compiler'

filename = process.argv[2]
seperator = '-----------------'

maybeShowJs = (js, filename) ->
if process.env.DISPLAY_JS is 'true'
console.log()
console.log seperator, filename, seperator
console.log()
console.log js
console.log()
console.log seperator, filename, seperator
console.log()

getAllCirruFiles = (x) ->
if fs.statSync(x).isFile()
if x.match(/\.cirru$/)
return [x]
else
return []
else
children = fs.readdirSync x
children
.flatMap (child) ->
if child is 'node_modules'
return []
else
childPath = path.join x, child
getAllCirruFiles childPath

if process.argv[2] is 'compile'
fromDir = process.argv[3]
toDir = process.argv[4]

if not fromDir? or not toDir?
console.log "cirruscript compile {from dir} {to dir}"
process.exit 1

baseFolder = path.join process.env.PWD, fromDir

allCirruFiles = getAllCirruFiles baseFolder
allCirruFiles.forEach (x) ->
code = fs.readFileSync x, 'utf8'
js = compiler.compile code
relativeOne = path.relative baseFolder, x
toFilepath = (path.join process.env.PWD, toDir, relativeOne).replace /\.cirru$/, '.js'
fs.mkdirSync (path.dirname toFilepath), recursive: true, (err) ->
console.log err
fs.writeFileSync toFilepath, js
console.log (path.relative process.env.PWD, x), '\t->\t', (path.relative process.env.PWD, toFilepath)

else if process.argv[2]?
filename = process.argv[2]
fullpath = path.join process.env.PWD, filename

if not fs.existsSync(fullpath)
console.log "Found no file", fullpath
process.exit 1

if fs.statSync(fullpath).isDirectory()
console.log fullpath, "is a directory. No evaling."
process.exit 1

if filename?
require('./register')

mainModule = require.main
Expand All @@ -18,15 +76,19 @@ if filename?
mainModule.paths = m._nodeModulePaths (path.dirname filename)
code = fs.readFileSync filename, 'utf8'
js = compiler.compile code

maybeShowJs(js)

mainModule._compile js, mainModule.filename

else
repl.start
prompt: 'cirru-script> '
prompt: 'cirruscript> '
eval: (input, context, filename, cb) ->
code = input[...-1]
try
js = compiler.compile code
maybeShowJs js, 'REPL'
cb null, (vm.runInContext js, context)

catch err
Expand Down
2 changes: 1 addition & 1 deletion src/compiler.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

babel = require 'babel-core'
babel = require '@babel/standalone'
parser = require 'cirru-parser'
scirpus = require 'scirpus'

Expand Down
15 changes: 8 additions & 7 deletions src/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ body {
}

textarea {
padding: 8px;
font-size: 14px;
font-family: Menlo;
line-height: 1.5em;
flex: 1;
padding: 8px 8px 120px 8px;
font-size: 13px;
font-family: Source Code Pro, Menlo, Consolas, monospace;
line-height: 20px;
border: 1px solid hsl(0,0%,80%);
outline: none;
resize: none;
}

#source {
width: 50%;
height: 100%;
border: none;
display: block;
}

#compiled {
width: 50%;
height: 100%;
border: none;
}
12 changes: 12 additions & 0 deletions src/register.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@ fs = require 'fs'

compiler = require './compiler'

seperator = '-----------------'

if require.extensions?
require.extensions['.cirru'] = (module, filename) ->
code = fs.readFileSync filename, 'utf8'
js = compiler.compile code

if process.env.DISPLAY_JS is 'true'
console.log()
console.log seperator, filename, seperator
console.log()
console.log js
console.log()
console.log seperator, filename, seperator
console.log()

module._compile js, filename
Loading