skeleton 0.1.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +18 -19
- package/README.md +13 -111
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.mjs +1164 -0
- package/package.json +45 -16
- package/.npmignore +0 -5
- package/TODO.md +0 -1
- package/bin/skeleton +0 -10
- package/lib/skeleton/helpers.coffee +0 -22
- package/lib/skeleton/index.coffee +0 -180
- package/lib/skeleton/option_parser.coffee +0 -61
- package/lib/skeleton/template.coffee +0 -408
|
@@ -1,408 +0,0 @@
|
|
|
1
|
-
class Template
|
|
2
|
-
|
|
3
|
-
constructor: (@appName, @opts) ->
|
|
4
|
-
# Directory defaults to `.` and remove trailing slash
|
|
5
|
-
@appDirectory = if @opts.directory != '' then @opts.directory else '.'
|
|
6
|
-
@appDirectory = @appDirectory.replace /\/$/, ''
|
|
7
|
-
|
|
8
|
-
@files = this.setFiles()
|
|
9
|
-
|
|
10
|
-
setFiles: ->
|
|
11
|
-
files = {}
|
|
12
|
-
|
|
13
|
-
# ./myapp
|
|
14
|
-
files["#{@appDirectory}/#{@appName}/.gitignore"] = """
|
|
15
|
-
node_modules/
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
files["#{@appDirectory}/#{@appName}/package.json"] = """
|
|
19
|
-
{
|
|
20
|
-
"name": "#{@appName}"
|
|
21
|
-
, "version": "0.0.1"
|
|
22
|
-
, "dependencies": {
|
|
23
|
-
"express": "3.0.0beta4"
|
|
24
|
-
, "connect-assets": "2.1.x"
|
|
25
|
-
#{this.getTemplateModule()}
|
|
26
|
-
#{this.getCssModule()}
|
|
27
|
-
#{this.getJsModule()}
|
|
28
|
-
}
|
|
29
|
-
, "scripts": {
|
|
30
|
-
"start": "server.js"
|
|
31
|
-
}
|
|
32
|
-
, "engines": {
|
|
33
|
-
"node": "#{process.version.replace 'v', ''}"
|
|
34
|
-
, "npm": "1.1.x"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
"""
|
|
38
|
-
|
|
39
|
-
files["#{@appDirectory}/#{@appName}/Procfile"] = """
|
|
40
|
-
web: node server.js
|
|
41
|
-
"""
|
|
42
|
-
|
|
43
|
-
files["#{@appDirectory}/#{@appName}/README.md"] = """
|
|
44
|
-
# #{@appName}
|
|
45
|
-
***
|
|
46
|
-
App structure generated by [Skeleton](https://github.com/EtienneLem/skeleton)
|
|
47
|
-
"""
|
|
48
|
-
|
|
49
|
-
files["#{@appDirectory}/#{@appName}/server.js"] = """
|
|
50
|
-
require("coffee-script")
|
|
51
|
-
require("./app/app.coffee")
|
|
52
|
-
"""
|
|
53
|
-
|
|
54
|
-
# ./myapp/app
|
|
55
|
-
files["#{@appDirectory}/#{@appName}/app/app.coffee"] = """
|
|
56
|
-
# Modules
|
|
57
|
-
express = require 'express'
|
|
58
|
-
http = require 'http'
|
|
59
|
-
#{ if @opts.renderer != 'jade' then "partials = require 'express-partials'\n" else ''}app = express()
|
|
60
|
-
|
|
61
|
-
# Boot setup
|
|
62
|
-
require("\#{__dirname}/../config/boot")(app)
|
|
63
|
-
|
|
64
|
-
# Configuration
|
|
65
|
-
app.configure ->
|
|
66
|
-
port = process.env.PORT || 3000
|
|
67
|
-
if process.argv.indexOf('-p') >= 0
|
|
68
|
-
port = process.argv[process.argv.indexOf('-p') + 1]
|
|
69
|
-
|
|
70
|
-
app.set 'port', port
|
|
71
|
-
app.set 'views', "\#{__dirname}/views"
|
|
72
|
-
app.set 'view engine', '#{@opts.renderer}'
|
|
73
|
-
app.use express.static("\#{__dirname}/../public")
|
|
74
|
-
app.use express.favicon()
|
|
75
|
-
app.use express.logger('dev')
|
|
76
|
-
app.use express.bodyParser()
|
|
77
|
-
app.use express.methodOverride()
|
|
78
|
-
#{ if @opts.renderer != 'jade' then 'app.use partials()\n ' else ''}app.use require('connect-assets')(src: "\#{__dirname}/assets")
|
|
79
|
-
app.use app.router
|
|
80
|
-
|
|
81
|
-
app.configure 'development', ->
|
|
82
|
-
app.use express.errorHandler()
|
|
83
|
-
|
|
84
|
-
# Routes
|
|
85
|
-
require("\#{__dirname}/routes")(app)
|
|
86
|
-
|
|
87
|
-
# Server
|
|
88
|
-
http.createServer(app).listen app.get('port'), ->
|
|
89
|
-
console.log "Express server listening on port \#{app.get 'port'} in \#{app.settings.env} mode"
|
|
90
|
-
"""
|
|
91
|
-
|
|
92
|
-
# ./myapp/app/assets/css
|
|
93
|
-
# Stylus
|
|
94
|
-
if @opts.css == 'stylus'
|
|
95
|
-
files["#{@appDirectory}/#{@appName}/app/assets/css/styles.styl"] = """
|
|
96
|
-
// Based on <https://github.com/heliom/stylus-utils/blob/master/styles.styl-sample>
|
|
97
|
-
// @import "nib"
|
|
98
|
-
|
|
99
|
-
// Reset ---------------------------------------------------------------------
|
|
100
|
-
*
|
|
101
|
-
margin: 0; padding: 0
|
|
102
|
-
-webkit-box-sizing: border-box
|
|
103
|
-
-moz-box-sizing: border-box
|
|
104
|
-
box-sizing: border-box
|
|
105
|
-
|
|
106
|
-
// Base ----------------------------------------------------------------------
|
|
107
|
-
$background-color = #f4f4f4
|
|
108
|
-
|
|
109
|
-
html
|
|
110
|
-
font-size: 62.5%
|
|
111
|
-
height: 100%
|
|
112
|
-
|
|
113
|
-
body
|
|
114
|
-
font-size: 16px
|
|
115
|
-
font-size: 1.6rem
|
|
116
|
-
background-color: $background-color
|
|
117
|
-
|
|
118
|
-
body, legend, input, textarea, button
|
|
119
|
-
font-family: 'Helvetica Neue'
|
|
120
|
-
line-height: 1.4
|
|
121
|
-
color: #333
|
|
122
|
-
|
|
123
|
-
a:link, a:visited { color: deeppink }
|
|
124
|
-
a:focus, a:hover, a:visited:hover { color: hotpink }
|
|
125
|
-
"""
|
|
126
|
-
|
|
127
|
-
# Less
|
|
128
|
-
if @opts.css == 'less'
|
|
129
|
-
files["#{@appDirectory}/#{@appName}/app/assets/css/styles.less"] = """
|
|
130
|
-
// Based on <https://github.com/heliom/stylus-utils/blob/master/styles.styl-sample>
|
|
131
|
-
|
|
132
|
-
// Reset ---------------------------------------------------------------------
|
|
133
|
-
* {
|
|
134
|
-
margin: 0; padding: 0;
|
|
135
|
-
-webkit-box-sizing: border-box;
|
|
136
|
-
-moz-box-sizing: border-box;
|
|
137
|
-
box-sizing: border-box;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// Base ----------------------------------------------------------------------
|
|
141
|
-
@background-color: #f4f4f4;
|
|
142
|
-
|
|
143
|
-
html {
|
|
144
|
-
font-size: 62.5%;
|
|
145
|
-
height: 100%;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
body {
|
|
149
|
-
font-size: 16px;
|
|
150
|
-
font-size: 1.6rem;
|
|
151
|
-
background-color: @background-color;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
body, legend, input, textarea, button {
|
|
155
|
-
font-family: 'Helvetica Neue';
|
|
156
|
-
line-height: 1.4;
|
|
157
|
-
color: #333;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
a:link, a:visited { color: deeppink }
|
|
161
|
-
a:focus, a:hover, a:visited:hover { color: hotpink }
|
|
162
|
-
"""
|
|
163
|
-
|
|
164
|
-
# css
|
|
165
|
-
if @opts.css == 'css'
|
|
166
|
-
files["#{@appDirectory}/#{@appName}/app/assets/css/styles.css"] = """
|
|
167
|
-
/* Based on <https://github.com/heliom/stylus-utils/blob/master/styles.styl-sample> */
|
|
168
|
-
|
|
169
|
-
/* Reset --------------------------------------------------------------------- */
|
|
170
|
-
* {
|
|
171
|
-
margin: 0; padding: 0;
|
|
172
|
-
-webkit-box-sizing: border-box;
|
|
173
|
-
-moz-box-sizing: border-box;
|
|
174
|
-
box-sizing: border-box;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/* Base ---------------------------------------------------------------------- */
|
|
178
|
-
html {
|
|
179
|
-
font-size: 62.5%;
|
|
180
|
-
height: 100%;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
body {
|
|
184
|
-
font-size: 16px;
|
|
185
|
-
font-size: 1.6rem;
|
|
186
|
-
background-color: #f4f4f4;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
body, legend, input, textarea, button {
|
|
190
|
-
font-family: 'Helvetica Neue';
|
|
191
|
-
line-height: 1.4;
|
|
192
|
-
color: #333;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
a:link, a:visited { color: deeppink }
|
|
196
|
-
a:focus, a:hover, a:visited:hover { color: hotpink }
|
|
197
|
-
"""
|
|
198
|
-
|
|
199
|
-
# ./myapp/app/assets/js
|
|
200
|
-
# CoffeeScript
|
|
201
|
-
if @opts.js == 'coffee'
|
|
202
|
-
files["#{@appDirectory}/#{@appName}/app/assets/js/scripts.coffee"] = """
|
|
203
|
-
# console.log '#{@appName}'
|
|
204
|
-
"""
|
|
205
|
-
|
|
206
|
-
# JavaScript
|
|
207
|
-
if @opts.js == 'js'
|
|
208
|
-
files["#{@appDirectory}/#{@appName}/app/assets/js/scripts.js"] = """
|
|
209
|
-
// console.log('#{@appName}')
|
|
210
|
-
"""
|
|
211
|
-
|
|
212
|
-
# ./myapp/app/controllers
|
|
213
|
-
files["#{@appDirectory}/#{@appName}/app/controllers/application_controller.coffee"] = """
|
|
214
|
-
module.exports = (app) ->
|
|
215
|
-
class app.ApplicationController
|
|
216
|
-
|
|
217
|
-
# GET /
|
|
218
|
-
@index = (req, res) ->
|
|
219
|
-
res.render 'index',
|
|
220
|
-
view: 'index'
|
|
221
|
-
"""
|
|
222
|
-
|
|
223
|
-
# ./myapp/app/helpers
|
|
224
|
-
files["#{@appDirectory}/#{@appName}/app/helpers/index.coffee"] = """
|
|
225
|
-
fs = require 'fs'
|
|
226
|
-
|
|
227
|
-
# Recursively require a folder’s files
|
|
228
|
-
exports.autoload = autoload = (dir, app) ->
|
|
229
|
-
fs.readdirSync(dir).forEach (file) ->
|
|
230
|
-
path = "\#{dir}/\#{file}"
|
|
231
|
-
stats = fs.lstatSync(path)
|
|
232
|
-
|
|
233
|
-
# Go through the loop again if it is a directory
|
|
234
|
-
if stats.isDirectory()
|
|
235
|
-
autoload path, app
|
|
236
|
-
else
|
|
237
|
-
require(path)?(app)
|
|
238
|
-
|
|
239
|
-
# Return last item of an array
|
|
240
|
-
# ['a', 'b', 'c'].last() => 'c'
|
|
241
|
-
Array::last = ->
|
|
242
|
-
this[this.length - 1]
|
|
243
|
-
|
|
244
|
-
# Capitalize a string
|
|
245
|
-
# string => String
|
|
246
|
-
String::capitalize = () ->
|
|
247
|
-
this.replace /(?:^|\\s)\\S/g, (a) -> a.toUpperCase()
|
|
248
|
-
|
|
249
|
-
# Classify a string
|
|
250
|
-
# application_controller => ApplicationController
|
|
251
|
-
String::classify = (str) ->
|
|
252
|
-
classified = []
|
|
253
|
-
words = str.split('_')
|
|
254
|
-
for word in words
|
|
255
|
-
classified.push word.capitalize()
|
|
256
|
-
|
|
257
|
-
classified.join('')
|
|
258
|
-
"""
|
|
259
|
-
|
|
260
|
-
# ./myapp/app/routes
|
|
261
|
-
files["#{@appDirectory}/#{@appName}/app/routes/index.coffee"] = """
|
|
262
|
-
module.exports = (app) ->
|
|
263
|
-
# Index
|
|
264
|
-
app.get '/', app.ApplicationController.index
|
|
265
|
-
|
|
266
|
-
# Error handling (No previous route found. Assuming it’s a 404)
|
|
267
|
-
app.get '/*', (req, res) ->
|
|
268
|
-
NotFound res
|
|
269
|
-
|
|
270
|
-
NotFound = (res) ->
|
|
271
|
-
res.render '404', status: 404, view: 'four-o-four'
|
|
272
|
-
"""
|
|
273
|
-
|
|
274
|
-
# ./myapp/app/views
|
|
275
|
-
# Ejs
|
|
276
|
-
if @opts.renderer == 'ejs'
|
|
277
|
-
files["#{@appDirectory}/#{@appName}/app/views/404.ejs"] = "<h1>Nothing here…</h1>"
|
|
278
|
-
|
|
279
|
-
files["#{@appDirectory}/#{@appName}/app/views/index.ejs"] = """
|
|
280
|
-
<h1>This page has been generated by <a href="https://github.com/EtienneLem/skeleton">Skeleton</a></h1>
|
|
281
|
-
<p>Edit in <span>#{@appName}/views/index.ejs</span></p>
|
|
282
|
-
"""
|
|
283
|
-
|
|
284
|
-
files["#{@appDirectory}/#{@appName}/app/views/layout.ejs"] = """
|
|
285
|
-
<!DOCTYPE html>
|
|
286
|
-
<html lang="en">
|
|
287
|
-
<head>
|
|
288
|
-
<meta charset="utf-8">
|
|
289
|
-
<title>#{@appName}</title>
|
|
290
|
-
<%- css('styles.css') %>
|
|
291
|
-
</head>
|
|
292
|
-
<body data-view="<%= view %>">
|
|
293
|
-
<%- body %>
|
|
294
|
-
<script>
|
|
295
|
-
document.write('<script src=' +
|
|
296
|
-
('__proto__' in {} ? 'http://zeptojs.com/zepto.min.js' : 'http://code.jquery.com/jquery-1.7.2.min.js') +
|
|
297
|
-
'><\\/script>')
|
|
298
|
-
</script>
|
|
299
|
-
<%- js('scripts.js') %>
|
|
300
|
-
</body>
|
|
301
|
-
</html>
|
|
302
|
-
"""
|
|
303
|
-
|
|
304
|
-
# Jade
|
|
305
|
-
if @opts.renderer == 'jade'
|
|
306
|
-
files["#{@appDirectory}/#{@appName}/app/views/404.jade"] = """
|
|
307
|
-
extends layout
|
|
308
|
-
|
|
309
|
-
block content
|
|
310
|
-
h1 Nothing here…
|
|
311
|
-
"""
|
|
312
|
-
|
|
313
|
-
files["#{@appDirectory}/#{@appName}/app/views/index.jade"] = """
|
|
314
|
-
extends layout
|
|
315
|
-
|
|
316
|
-
block content
|
|
317
|
-
h1 This page has been generated by <a href="https://github.com/EtienneLem/skeleton">Skeleton</a>
|
|
318
|
-
p Edit in <span>#{@appName}/views/index.jade</span>
|
|
319
|
-
"""
|
|
320
|
-
|
|
321
|
-
files["#{@appDirectory}/#{@appName}/app/views/layout.jade"] = """
|
|
322
|
-
doctype 5
|
|
323
|
-
html(lang="en")
|
|
324
|
-
head
|
|
325
|
-
meta(charset="utf-8")
|
|
326
|
-
title #{@appName}
|
|
327
|
-
!= css('styles.css')
|
|
328
|
-
|
|
329
|
-
body(data-view="\#{view}")
|
|
330
|
-
block content
|
|
331
|
-
|
|
332
|
-
| <script>
|
|
333
|
-
| document.write('<script src=' +
|
|
334
|
-
| ('__proto__' in {} ? 'http://zeptojs.com/zepto.min.js' : 'http://code.jquery.com/jquery-1.7.2.min.js') +
|
|
335
|
-
| '><\\/script>')
|
|
336
|
-
| </script>
|
|
337
|
-
|
|
338
|
-
!= js('scripts.js')
|
|
339
|
-
"""
|
|
340
|
-
|
|
341
|
-
# ./myapp/config
|
|
342
|
-
files["#{@appDirectory}/#{@appName}/config/boot.coffee"] = """
|
|
343
|
-
module.exports = (app) ->
|
|
344
|
-
# Helpers
|
|
345
|
-
app.helpers = require "\#{__dirname}/../app/helpers"
|
|
346
|
-
|
|
347
|
-
# Lib
|
|
348
|
-
app.helpers.autoload "\#{__dirname}/../lib", app
|
|
349
|
-
|
|
350
|
-
# Controllers
|
|
351
|
-
app.helpers.autoload "\#{__dirname}/../app/controllers", app
|
|
352
|
-
"""
|
|
353
|
-
|
|
354
|
-
# ./myapp/lib/myapp
|
|
355
|
-
files["#{@appDirectory}/#{@appName}/lib/#{@appName}/my_custom_class.coffee"] = """
|
|
356
|
-
# module.exports = (app) ->
|
|
357
|
-
# # Your code
|
|
358
|
-
#
|
|
359
|
-
#
|
|
360
|
-
# Or if you want this to be a class
|
|
361
|
-
#
|
|
362
|
-
# module.exports = (app) ->
|
|
363
|
-
# class app.MyCustomClass
|
|
364
|
-
#
|
|
365
|
-
# constructor: (args) ->
|
|
366
|
-
# # Your code
|
|
367
|
-
#
|
|
368
|
-
# Usage: new app.MyCustomClass(args)
|
|
369
|
-
"""
|
|
370
|
-
|
|
371
|
-
# ./myapp/public
|
|
372
|
-
files["#{@appDirectory}/#{@appName}/public/empty"] = ""
|
|
373
|
-
|
|
374
|
-
# Return the files object
|
|
375
|
-
files
|
|
376
|
-
|
|
377
|
-
getTemplateModule: ->
|
|
378
|
-
module = ''
|
|
379
|
-
spaces = ' '
|
|
380
|
-
|
|
381
|
-
# Jade doesn’t need express-partials
|
|
382
|
-
if @opts.renderer != 'jade'
|
|
383
|
-
module = """
|
|
384
|
-
, "express-partials": ">= 0.0.5"\n#{spaces}
|
|
385
|
-
"""
|
|
386
|
-
|
|
387
|
-
module += """
|
|
388
|
-
, "#{@opts.renderer}": "*"
|
|
389
|
-
"""
|
|
390
|
-
|
|
391
|
-
module
|
|
392
|
-
|
|
393
|
-
getCssModule: ->
|
|
394
|
-
if @opts.css != 'css'
|
|
395
|
-
"""
|
|
396
|
-
, "#{@opts.css}": "*"
|
|
397
|
-
"""
|
|
398
|
-
else ''
|
|
399
|
-
|
|
400
|
-
getJsModule: ->
|
|
401
|
-
if @opts.js == 'coffee'
|
|
402
|
-
"""
|
|
403
|
-
, "coffee-script": "*"
|
|
404
|
-
"""
|
|
405
|
-
else ''
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
module.exports = Template
|