Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ lib/coffee-script/*.tmp
lib/bootstrap
coffee-script-redux-*.tgz
*.gem
*.log
11 changes: 11 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Changelog

### 0.0.15 (20. sept 2014)

Author: kmandrup@gmail.com

- Split CLI into smaller parts (Single Responsibility)
- Added ability to prepend/append code to output depending on input (using code fragments)
- Code fragments resolve issue #42 (ability to prepend code before ember output)
- Fragmentation turned on by default (can be turned off via options --fragmented switch)
- Added multi-compiler that can be integrated with CLI (see contribution notes)
92 changes: 92 additions & 0 deletions Contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
## Contributing to EmberScript

### General recommendations

- Only make changes in the `/src` folder
- Most behavior changes are to be done in `compiler.coffee`
- Make sure the changed file compiles before you do an entire build
- Always make sure all tests pass before you do a pull request

### Running tests

```bash
$ make build -j
$ make test
```

All tests should pass (green)

### Debugging changes

For debugging changes in general, it is often easier to do it directly by examining output to stdout.
This way, any `console.log`s are displayed without the "pollution" of test suite output.

It is often useful to run ember-script with the `-j` switch, returning bare javascript (without function scope wrapper). Again to avoid "pollution" and keep it clean.

Reading input directly from CLI (string)

```bash
$ make build -j
$ bin/ember-script -j --cli "a = 2"
```

Reading input from a file

```bash
$ make build -j
$ bin/ember-script -j --input sandbox/test-fragmented.em
```

### Architecture

bin/ember-script loads the `ember-runtime` and the `cli` in order to execute. The cli parses the cli commands, reads some input from a file or string and generates some output.

```javascript
#!/usr/bin/env node
require(require('path').join(__dirname, '..', 'lib', 'ember-runtime'));
require(require('path').join(__dirname, '..', 'lib', 'cli'));
```

### CLI architecture

`cli-exclusions`: attempts to resolve cli options where conflicts might occur.
`cli-fragmenter`: used to turn code into fragments that can be treated individually.
`cli-help`: displays help on how to use cli
`cli-input-source-chooser`: determines how to read the input source (file, cli string, ...)
`cli-output`: writes the output to an output target (file, stdout, ...)
`cli-process-input`: processes the input using some strategy depending on options
`cli`: the main cli

The fragmenter is currently turned on by default but can be easily turned off in `cli.coffee`:

```coffeescript
# false to disable script fragments
options.fragmented = true
```

### Script fragmentation

The fragmenter is currently used to enable prepending of javascript before ember-script generated code (resolves issue #42). The fragmenter has been designed to be easy to customize and also allows appending code using the same pattern if necessary. You could even extend it to compile each code fragment separately and merge them all at the end...

### CoffeeScript/LiveScript compilation

See `process-input.coffee` for examples of usage checkout the Coffeescript npm site/repo

To compile *CoffeeScript* to bare *JavaScript* simply do:

`CoffeeScript.compile source, { bare: true }`

Similar for LiveScript:

`LiveScript.compile code, { bare: true }`

This could be used for a multi-fragment solution:

### Multi-script fragmentation

Allow for a mix of scripting languages in one file:

`# (ember)` emberscript fragment starts
`# (js)` javascript
`# (coffee)` coffeescript
`# (live)` livescript
176 changes: 107 additions & 69 deletions dist/ember-script.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ember-script.js.map

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions lib/cli-exclusions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions lib/cli-fragmenter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions lib/cli-help.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions lib/cli-input-source-chooser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions lib/cli-input-source.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions lib/cli-output.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading