Crystal JS 0.18.0
code generator for every language, framework and platform
Table of Contents
Install
Choose your favorite way to install things:
npm
npm install crystal
GitHub
git clone https://github.com/crystal/crystal
Hello World
Input
Create a file called helloworld.js
and add these contents:
var Crystal = ;var project = name: 'My App' description: 'This is my app.' path: './output/myapp' imports: 'crystal/license': '~0.2.4' 'crystal/readme': '~0.2.2' outputs: // generate a LICENSE file generator: 'license.MITGenerator' spec: copyright: '2015 Crystal' // generate a README.md file generator: 'readme.ReadmeGenerator' spec: name: '$name' description: '$description' ;
Output
Now run your helloworld.js
script:
node helloworld.js
This will create 2 files: README.md and LICENSE
README.md
# My API this is my API
LICENSE
The MIT License (MIT) Copyright (c) 2015 Crystal Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.
Usage
- Load Crystal
- Create Project
- Save Project
- Load Project
- Update Project
- Build Project
- Run Project
- Modularize Project
Load Crystal
var Crystal = ;
Create Project
var project = name: 'My App' description: 'This is my app.' path: './output/myapp' imports: 'crystal/license': '~0.2.4' 'crystal/readme': '~0.2.2' outputs: // generate a LICENSE file generator: 'license.MITGenerator' spec: copyright: '2015 Crystal' // generate a README.md file generator: 'readme.ReadmeGenerator' spec: name: '$name' description: '$description' ;
Save Project
project;
Load Project
var project = '/path/to/project';
Update Project (and its Imports)
project;
Build Project
project;
Run Project
project;
Modularize Project
Modularize your project for other projects to use:
var mod = name: 'My Module' description: 'This is my module.' path: './output/mymod' imports: 'crystal/handlebars': '~0.2.3' exports: ReadmeGenerator: engine: 'handlebars.HandlebarsEngine' filename: 'README.md' schema: type: 'object' properties: name: required: true type: 'string' description: required: true type: 'string' template: "# {{{name}}}\n\n{{{description}}}" type: 'generator' ;
Examples
JavaScript
Python
Ruby
Other
API Reference
build([opts])
Builds your project.
Options
Name | Type |
`force` | boolean |
Example
var project = '/path/to/project';project;
generate([opts])
Generates your project's files.
Options
Name | Type |
`force` | boolean |
Example
var project = '/path/to/project';project;
init([opts])
Initializes your project.
Example
var project = '/path/to/project';project;
install([opts])
Installs a module.
Example
var project = '/path/to/project';project;
load([opts])
Loads your project's configuration.
Example
var project = ;project;
run([opts])
Runs your project.
Example
var project = '/path/to/project';project;
search([opts])
Search for modules.
Example
var project = '/path/to/project';project;
test([opts])
Example
var project = '/path/to/project';project;
Test your project.
update([opts])
Updates your project.
Example
var project = '/path/to/project';project;
validate()
Validates your project.
Example
var project = '/path/to/project';project;
Official Documentation
View Crystal's Official Documentation here:
Live Editor
Use Crystal Editor to try Crystal online:
Top 10 Features
(1) Crystal unifies all technologies with a standardized input written in YAML, JSON, CSON and/or XML.
(2) Crystal generates code for:
- Any application: APIs, Apps, Websites, Frontends, Backends + more
- Any language: JavaScript, PHP, Ruby, Python, Swift, Java + more
- Any framework: Express, Hapi, Laravel, Yii, Rails, Sinatra, Django + more
- Any platform: Twitter, Facebook, Mailchimp, Pinterest, Google + more
- Any runtime/server: Node.js, Apache, Nginx, HAPROXY + more
- Any CMS: Wordpress, Drupal, Joomla, Plone, Keystone + more
- Any datastore: MySQL, PostgreSQL, Redis, MongoDB, DynamoDB + more
- Any file: README, LICENSE, AUTHORS, HOSTS + more
- ...and any other software!!
(3) Crystal is made up of 8 elements that make code generation more flexible and powerful than ever before:
(4) Crystal is meant to be used on an ongoing basis - beyond project creation and scaffolding.
(5) Crystal has its own registry (the Crystal Hub) and package manager built-in which makes it easy to search, install and update modules.
(6) All of Crystal's elements can be modularized and published to the Crystal Hub for you or others to use.
(7) You can use multiple modules together such as a:
- README generator for documentation
- MIT generator for licensing
- Composer generator for frontend dependencies
- Bower generator for backend dependencies
- Laravel generator for business logic
- Ember generator for UI
(8) You can add/remove modules to/from a project at anytime.
(9) To prevent vendor lock-in and becoming dependent of Crystal, it's kept in its own directory: .crystal/
. If you wish to no longer use Crystal, simply delete this directory and continue using the generated code (and making changes) without Crystal.
(10) Crystal makes language integration and/or migration easier.