UNPKG

coffee-toaster

Version:

Minimalist manager and build system for CoffeeScript, an alternative for AMD's or CJS's OOP patterns, but with similar results. Made for those who dare to use class definitions in CoffeeScript while being able to easily inherit from external files. Powered with imports directives that use wildcards facilities, exposed scopes and excluded files filter options. The system can even use folders-as-namespaces to help you avoid naming collisions in architecture.

82 lines (61 loc) 1.95 kB
#<< toaster/generators/question class Config extends toaster.generators.Question # requirements path = require "path" pn = path.normalize fs = require "fs" # variables tpl: """ # => SRC FOLDER toast '%src%' # EXCLUDED FOLDERS (optional) # exclude: ['folder/to/exclude', 'another/folder/to/exclude', ... ] # => VENDORS (optional) # vendors: ['vendors/x.js', 'vendors/y.js', ... ] # => OPTIONS (optional, default values listed) # bare: false # packaging: true # expose: '' # minify: true # => HTTPFOLDER (optional), RELEASE / DEBUG (required) httpfolder: '%httpfolder%' release: '%release%' debug: '%debug%' """ constructor:(@basepath)-> create:()=> q1 = "Path to your src folder? [src] : " q2 = "Path to your release file? [www/js/app.js] : " q3 = "Starting from your webroot '/', what's the folderpath to "+ "reach your release file? (i.e. js) (optional) : " @ask q1.magenta, /.+/, (src)=> @ask q2.magenta, /.+/, (release)=> @ask q3.cyan, /.*/, (httpfolder)=> @write src, release, httpfolder write:(src, release, httpfolder)=> filepath = pn "#{@basepath}/toaster.coffee" rgx = /(\/)?((\w+)(\.*)(\w+$))/ parts = rgx.exec( release ) filename = parts[2] if filename.indexOf(".") > 0 debug = release.replace rgx, "$1$3-debug$4$5" else debug = "#{release}-debug" buffer = @tpl.replace "%src%", src buffer = buffer.replace "%release%", release buffer = buffer.replace "%debug%", debug buffer = buffer.replace "%httpfolder%", httpfolder if fs.existsSync filepath question = "\tDo you want to overwrite the file: #{filepath.yellow}" question += " ? [y/N] : ".white @ask question, /.*?/, (overwrite)=> if overwrite.match /y/i @save filepath, buffer process.exit() else @save filepath, buffer process.exit() save:(filepath, contents)-> fs.writeFileSync filepath, contents log "#{'Created'.green.bold} #{filepath}" process.exit()