1
|
|
|
'use strict' |
2
|
|
|
|
3
|
|
|
const util = require('../util') |
4
|
|
|
const output = require('../output') |
5
|
|
|
const email = require('git-user-email') |
6
|
|
|
const name = require('git-user-name') |
7
|
|
|
const path = require('path') |
8
|
|
|
const fs = require('fs') |
9
|
|
|
|
10
|
|
|
module.exports = function (boxName) { |
11
|
|
|
var userName = (util.getSystemUsername() || 'user').toLowerCase() |
12
|
|
|
if (boxName.match(/^[a-z0-9-]+\/[a-z0-9-]+$/)) { |
13
|
|
|
userName = boxName.split('/')[0] |
14
|
|
|
boxName = boxName.split('/')[1] |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
if (!boxName.match(/^[a-z0-9-]+$/)) { |
18
|
|
|
output.err('Module name should only contain lowercase letters, numbers and dashes.') |
19
|
|
|
return |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
try { |
23
|
|
|
// Create directory |
24
|
|
|
output.log('Creating directories') |
25
|
|
|
fs.mkdirSync(boxName) |
26
|
|
|
|
27
|
|
|
// Write module.json |
28
|
|
|
output.log('Writing module.json') |
29
|
|
|
var json = util.moduleJSON(boxName, userName, name({ |
30
|
|
|
type: 'global' |
31
|
|
|
}), email({ |
32
|
|
|
type: 'global' |
33
|
|
|
})) |
34
|
|
|
fs.writeFileSync(path.join(boxName, 'module.json'), JSON.stringify(json, null, 3), 'utf8') |
35
|
|
|
fs.writeFileSync(path.join(boxName, 'composer.json'), JSON.stringify({ |
36
|
|
|
'require': {} |
37
|
|
|
}, null, 3), 'utf8') |
38
|
|
|
|
39
|
|
|
// Write .gitignore |
40
|
|
|
fs.createReadStream(path.join(__dirname, '..', 'templates', 'gitignore')).pipe(fs.createWriteStream(path.join(boxName, '.gitignore'))) |
41
|
|
|
|
42
|
|
|
// Create directories |
43
|
|
|
fs.mkdirSync(path.join(boxName, 'api')) |
44
|
|
|
fs.mkdirSync(path.join(boxName, 'hooks')) |
45
|
|
|
fs.mkdirSync(path.join(boxName, 'manager')) |
46
|
|
|
fs.mkdirSync(path.join(boxName, 'web')) |
47
|
|
|
fs.mkdirSync(path.join(boxName, 'web', 'templates')) |
48
|
|
|
|
49
|
|
|
// Write web example contents |
50
|
|
|
output.log('Seeding template') |
51
|
|
|
fs.createReadStream(path.join(__dirname, '..', 'templates', 'web', 'index.php')).pipe(fs.createWriteStream(path.join(boxName, 'web', 'index.php'))) |
52
|
|
|
fs.createReadStream(path.join(__dirname, '..', 'templates', 'web', 'templates_hello.hbs')).pipe(fs.createWriteStream(path.join(boxName, 'web', 'templates', 'hello.hbs'))) |
53
|
|
|
|
54
|
|
|
// Write readme.md |
55
|
|
|
fs.writeFileSync(path.join(boxName, 'README.md'), '# ' + util.boxNameDisplay(boxName) + '\n\nA Incluable app for ' + util.boxNameDisplay(boxName) + '.', 'utf8') |
56
|
|
|
|
57
|
|
|
// Git init |
58
|
|
|
output.log('Initializing git repository') |
59
|
|
|
require('child_process').exec('cd "' + boxName + '" && git init') |
60
|
|
|
|
61
|
|
|
// Download IDE helper |
62
|
|
|
output.log('Downloading IDE helper') |
63
|
|
|
util.downloadHelper(function () { |
64
|
|
|
output.notice('Done!') |
65
|
|
|
}, boxName) |
66
|
|
|
} catch (e) { |
67
|
|
|
output.err(e) |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|