Git Product home page Git Product logo

khaos's Introduction

The simplest project scaffolder. http://khaos.io

Build Status

Installation

$ npm install -g khaos

Documentation

Usage

The quickest way to start using Khaos is to create a new project from a template on GitHub. For example, using the segmentio/khaos-node template...

$ khaos create segmentio/khaos-node my-new-project

...that will prompt you to fill in some placeholders...

            name: ware
           owner: segmentio
     description: Easily create your own middleware layer.

...and voilà! Your new node.js project directory is created including a package.json, Readme.md, Makefile, and everything.

Local Usage

Khaos can also use local templates at ~/.khaos and there's a simple command for download GitHub repositories there. Here's the same example from above, but locally...

$ khaos install segmentio/khaos-node node

That installs Segment's node template and aliases it as node, so then from now on you can easily...

$ khaos create node my-new-project

...and fill out a few fields and your new project directory is created!

How does it work?

Khaos templates are just plain old directories where any file or filename can have handlebars placeholders. When you create a new project, Khaos will scan the template for placeholders and prompt you to fill in a value for each one.

For example, say you have a package.json in your template...

{
  "name": "{{ name }}",
  "repository": "{{ owner }}/{{ name }}",
  "description": "{{ description }}",
  "dependencies": {}
}

Khaos sees that and knows to prompt you for a name, owner, and description when generating the template, like so...

            name: ware
           owner: segmentio
     description: Easily create your own middleware layer.

You can use handlebars conditional blocks too, so if you wanted to add an optional private flag...

{
  "name": "{{ name }}",
  {{#private}}
  "private": true,
  {{/private}}
  "repository": "{{ owner }}/{{ name }}",
  "description": "{{ description }}",
  "dependencies": {}
}

...and Khaos is smart enough to know that private is a boolean when it prompts you...

            name: ware
         private: (y/n) y
           owner: segmentio
     description: Easily create your own middleware layer.

What's cool about all this is it makes creating new templates incredibly easy. Just copy an existing project and replace the filled-in values with placeholders... now you can automate more things!

Examples

To give you an idea for what's possible, check out a few examples:

Javascript API

In addition to using the simple CLI to create new projects, you can use Khaos straight from node.js in case you want to bake it into your own, more custom, scaffolding process. Checkout the logo creation CLI for an example of this in action.

new Khaos(src, dest)

Create a new Khaos instance with a src template directory, and that will output to a dest directory.

#run(callback)

Run the prompting and scaffolding process and then callback(err).

#use(plugin)

Use a custom plugin function. Khaos uses Metalsmith internally, so the plugin is just a regular Metalsmith plugin, and all of the prompted answers are available as global metadata.

Thanks!

Thank you so much to Sorella for letting us use the khaos name on npm!

License (MIT)

Copyright © 2013, Segment.io <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 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 THE SOFTWARE.

khaos's People

Contributors

dgreif avatar gjohnson avatar ianstormtaylor avatar juliangruber avatar lambtron avatar matthewmueller avatar robloach avatar yields avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

khaos's Issues

race condition in directory creation

$ khaos integration trackduck

      alias: (y/N) n
      group: (y/N)
   identify: (y/N) y
       page: (y/N)
     screen: (y/N)
      track: (y/N)
     mapper: (y/N) y
       docs: https://docs.trackduck.com
   endpoint: https://api.trackduck.com
   khaos · { [Error: EISDIR, open '/Users/calvinfo/dev/scratch/trackduck/test/fixtures/']
  errno: -21,
  code: 'EISDIR',
  path: '/Users/calvinfo/dev/scratch/trackduck/test/fixtures/' }

Fails to parse on certain characters and combination of characters

This is a heading

  • The heading above would trigger front-matter, which in turn would result in an error. I'm used to writing sub-headings like this in markdown instead of the usual ##.

  • If there's a .DS_Store file in there, handlebars will throw an error with a message that's kind of useless.

    Error: Lexical error on line 1. Unrecognized text.
    

There's really no way of knowing what file causes the issue from that message.

So perhaps a validation-system or better error-reporting would be a good idea?

install faild because of the dependence [case]

Hi,

When i install npm install khaos -g, an error occured:

npm ERR! Error: Command failed: fatal: ambiguous argument '1.0.0': unknown revis
ion or path not in the working tree.

it cased by:

"case": "git://github.com/ianstormtaylor/case#1.0.0"

add aliasing?

would be kind of cool to make the github use case the primary one, but the downside is the verbose naming. aka with github you have to do:

$ khaos segmentio/khaos-node my-project

instead of just:

$ khaos node my-project

but what if there was a way to store simple aliases for new projects like so:

$ khaos alias segmentio/khaos-node node

which would let you use github (so that you dont have to manage downloading the files to your own machine) and still get simple installs

Can't install khaos

I haven't been able to install npm i -g khaos in any environment.

I fired up a fresh centos 6.5 droplet on DO to have a blank slate.
When running npm install -dd khaos it consistently freezes after this:

npm info install [email protected]
npm info postinstall [email protected]
npm verb unlock done using /root/.npm/_locks/uglify-js-60ae3fb922a1e9a7.lock for /root/analytics.js-integrations/node_modules/khaos/node_modules/handlebars/node_modules/uglify-js
npm verb about to build /root/analytics.js-integrations/node_modules/khaos/node_modules/handlebars
npm info build /root/analytics.js-integrations/node_modules/khaos/node_modules/handlebars
npm verb linkStuff [ false,
npm verb linkStuff   false,
npm verb linkStuff   false,
npm verb linkStuff   '/root/analytics.js-integrations/node_modules/khaos/node_modules' ]
npm info linkStuff [email protected]
npm verb linkBins [email protected]
npm verb link bins [ { handlebars: 'bin/handlebars' },
npm verb link bins   '/root/analytics.js-integrations/node_modules/khaos/node_modules/.bin',
npm verb link bins   false ]
npm verb linkMans [email protected]
npm verb rebuildBundles [email protected]
npm verb rebuildBundles [ '.bin', 'optimist', 'uglify-js' ]
npm verb gentlyRm vacuuming /root/analytics.js-integrations/node_modules/khaos/node_modules/.bin/handlebars
npm info install [email protected]
npm info postinstall [email protected]
npm verb unlock done using /root/.npm/_locks/handlebars-84bf8adcb828316d.lock for /root/analytics.js-integrations/node_modules/khaos/node_modules/handlebars

My npm version is 2.3.0 and node is v0.11.16

Thanks.

error

So, fresh install of Khaos, get this error:

C:\Dev\Projects\Misc>khaos create segmentio/khaos-node my-new-project

events.js:141
throw er; // Unhandled 'error' event
^
Error: spawn C:\Users\Jo\AppData\Roaming\npm\node_modules\khaos\bin\khaos-create
ENOENT
at exports._errnoException (util.js:734:11)
at Process.ChildProcess._handle.onexit (child_process.js:1022:32)
at child_process.js:1114:20
at process._tickCallback (node.js:349:13)
at Function.Module.runMain (module.js:487:11)
at startup (node.js:112:16)
at node.js:865:3

khaos list

command to list the currently installed templates when u forget

search

search will help this project really take off and promote reusability.

This is the search query I've been using for components for a while and it's been working wonderfully.

Searching for tip:

https://github.com/search?q=tip+path%3A%2Fcomponent.json

More abstract:

https://github.com/search?q={query}+path%3A%2F{manifest}

nicer conditional files ?

i just figured we could just check for file extensions and ask

  css ? (y/n) : 
  js ? (y/n)  : 

thoughts ?

also ? is kinda weird cuz you already have (y/n) i vote we remove one of them :D

update all installed modules

Hi,

When you khaos update, it shows the khaos-update help message

It can be nice if khaos-update prompt you something like would you update all you local module ? (Y/n)

If you reply n, the help is printed, otherwise, it updates all your installed repos

What do you think ?

add mustache helpers

## Example

    var {{name|toCamelCase}} = require('{{name}}');

not super necessary though

lists

wanted to add something like:

  channels: server, mobile, client

and have it render as:

var Integration = module.exports = integration('Integration')
  .channels(['server', 'mobile', 'client']);

is this possible ?

handle individual files

i think this is necessary if we want Khaos to be as useful as possible for templating everything we want to template. for example, it would be nice to be able to template lib/integrations/google-analytics.js so that people can get it started super easily

there's isn't a zero-debt way to do this in terms of the abstraction. but i think i found a decent? way:

if a folder has a single file in it, and the file is named the same thing as the folder, then at the very end of the output we can swap it to be a file instead of a folder

so if we had:

analytics-integration.js/
  analytics-integration.js

that would result in a single file being added to the output dir instead of a folder with the file in it

customizing format

would be cool if .format() took a template option that defaulted to:

:prefix:label:separator:hint

instead of being hardcoded, so that it's completely customizable by the end user. at which point we could even remove :prefix and make that user-controlled instead, and event :hint maybe

cache?

if we decide that downloading each time from github is too wasteful, or slow

downside is just extra complexity, and then people needing to know to do no-cache if they are updating the github repo

custom handlebars helpers

So that we don't have to add every single handlebars case, it would be nice to just let people require in their own somehow instead of having put all of the useful ones in core.

add default values

Something like

"license": "{{license|MIT}}"

or even in file names:

{{#css|true}}style.css

remove need for schema?

from chat:

i was thinking
it wouldve been cool to not need khaos.json
for the schema
i had first written it to just parse the files
for {{ }}
but then i thought the schema might be nice for y/n questoins
so that we could for component say
javascript? (y/n)
and then not even render an index.js somehow
but dunno how wed know not to render the file ...

custom metalsmith plugin logic

Along the same lines as custom Handlebars helpers, it would be much more powerful if we could use existing Metalsmith plugins (or custom ones) and add them into the build steps when working on a directory. Basically that will keep the simple case super quick, but still let us have full flexibility.

Something like this in khaos.json:

{
  "plugins": {
    "metalsmith-minify": {},
    "./lib/something": {}
  }
}

Same issue stands of how to nicely download the node modules here, since we're using just straight up Git to manage the dependencies on the system itself.

swap options to be passed in after

would be nice to handle schema as a filename really easily, since it's annoying to have to read all the time if it already exists in a file on disk. and then people could easily just pass in .schema('path/to/schema.yaml') and not have to worry about converting

add conditional variables

Usecases:

test: @node_modules/.bin/mocha {{#harmony}}--harmony{{/harmony}}

and

## Installation

{{#harmony}}You need to be running node `0.11.x` or above.{{/harmony}}

add a nice plugin system

use case for us is for logos, it would be nice if we could have plugins that take an .ai file that was prompted for, and then convert it to .svg in all the color we need. then also take the size of those SVG and add them to the locals so the CSS file can render them

separate parse and ask

the cli should invoke both i think. that would let you pass in a schema normally without having to go thru the CLI at all for the JS api

hooks api

Need hooks exposed from the API.

  • before the destination directory is created
  • after the destination directory is created

What else?

make install alias optional

can easily smartly make aliases, so that segmentio/khaos-node is installed locally as node for convenience

multiline makefile fails

This:

test:
    @node_modules/.bin/mocha \
        --reporter spec {{#harmony}} \
        --harmony {{/harmony}}

gets turned into:

test:
    @node_modules/.bin/mocha \n     --reporter spec  \n     --harmony

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.