-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathscaffold.js
51 lines (41 loc) · 1.06 KB
/
scaffold.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* `node scaffold <functioName>` generates a new code file with an empty
* function and another file with a matching test
*/
const fs = require("fs");
const _ = require("lodash");
function scaffold(functionName) {
fs.writeFileSync(
`${_.kebabCase(functionName)}.js`,
scaffoldProductionCode(functionName)
);
fs.writeFileSync(
`${_.kebabCase(functionName)}.test.js`,
scaffoldTestCode(functionName)
);
}
function scaffoldProductionCode(functionName) {
return `const assert = require('assert')
const debug = require('debug')('${functionName}')
const _ = require('lodash')
module.exports = function ${functionName} () {
}
`;
}
function scaffoldTestCode(functionName) {
return `/* eslint-env mocha */
const assert = require('assert')
const ${functionName} = require('./${functionName}')
describe('${functionName}', function () {
it('${functionName}s', function () {
assert.deepEqual(
${functionName}(),
undefined)
})
})
`;
}
module.exports = scaffold;
if (require.main === module) {
scaffold(...process.argv.slice(2));
}