Conditions | 4 |
Paths | 44 |
Total Lines | 60 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | 'use strict' |
||
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 |