-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·45 lines (38 loc) · 1.2 KB
/
index.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
#!/usr/bin/env node
const chalk = require('chalk');
const { cosmiconfigSync } = require('cosmiconfig');
const fs = require('fs-extra');
const matter = require('gray-matter');
const pkg = require('./package.json');
const program = require('commander');
program.version(pkg.version);
program
.option('-c, --config <configFile>', 'Specify which configuration file you want to use.')
.arguments('<file>')
.action(file => {
const explorer = cosmiconfigSync('jamster');
let config;
if (program.config) {
config = explorer.load(`./${program.config}`);
} else {
config = explorer.search();
}
if (!config) {
config = require('./lib/defaults');
}
const currentWorkingDir = process.cwd();
const filePath = `${currentWorkingDir}/${file}`;
const frontMatterContents = matter.stringify('', config.config);
fs.outputFile(filePath, frontMatterContents, err => {
if (err) {
console.log(err);
console.log(chalk.blueBright('Exiting'));
process.exit(1);
} else {
console.log(
chalk.greenBright.bold(`\n 🎉 A new file was create at: ${filePath} \n`)
);
}
});
});
program.parse(process.argv);