Comparing version 0.0.0 to 0.0.1
57
index.js
@@ -7,11 +7,13 @@ #! /usr/bin/env node | ||
} = require('fs'); | ||
const yaml = require('js-yaml'); | ||
const { safeLoad } = require('js-yaml'); | ||
const inquirer = require('inquirer'); | ||
const questions = readFileSync(`${__dirname}/questions.yml`); | ||
let packageJSON; | ||
const defaults = {}; | ||
try { | ||
const packageJSON = JSON.parse(readFileSync('package.json')); | ||
defaults.title = packageJSON.name || ''; | ||
packageJSON = JSON.parse(readFileSync('package.json')); | ||
defaults.title = packageJSON.name; | ||
defaults.version = packageJSON.version; | ||
defaults.description = packageJSON.description; | ||
} catch (error) { | ||
@@ -21,13 +23,46 @@ process.stdout.write('You might want to run npm init first!'); | ||
inquirer.prompt(yaml.safeLoad(questions, 'utf8').map(question => { | ||
const questions = safeLoad(readFileSync(`${__dirname}/questions.yml`, 'utf8')).map(question => { | ||
let result = question; | ||
if (defaults[question.name]) { | ||
return Object.assign(question, { | ||
result = Object.assign(result, { | ||
default: defaults[question.name], | ||
}); | ||
} | ||
return question; | ||
})).then(answers => { | ||
if (question.when) { | ||
result = Object.assign(result, { | ||
when: !!packageJSON[question.when], | ||
}); | ||
} | ||
return result; | ||
}); | ||
const onComplete = answers => { | ||
const output = []; | ||
output.push(`# ${answers.title}`); | ||
writeFileSync('README.md', output.join('\n')); | ||
}); | ||
if (answers.title) { | ||
output.push(`# ${answers.title}\n`); | ||
} | ||
if (answers.description) { | ||
output.push(answers.description); | ||
} | ||
if (answers.bin) { | ||
output.push('\n## CLI\n'); | ||
Object.keys(packageJSON.bin).forEach(id => { | ||
output.push('```sh'); | ||
output.push(`$ npm install -g ${packageJSON.bin[id]}`); | ||
output.push(`$ ${packageJSON.bin[id]}`); | ||
output.push('```'); | ||
}); | ||
} | ||
if (answers.scripts) { | ||
output.push(`\n## Scripts\n`); | ||
Object.keys(packageJSON.scripts).forEach(script => { | ||
output.push(`### ${script}\n`); | ||
output.push('```sh'); | ||
output.push(`$ npm run ${script}`); | ||
output.push('```'); | ||
}); | ||
} | ||
writeFileSync('README.md', `${output.join('\n')}\n`); | ||
}; | ||
inquirer.prompt(questions).then(onComplete); |
{ | ||
"name": "emdaer", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "does a README.md", | ||
@@ -10,2 +10,5 @@ "author": "Flip", | ||
}, | ||
"scripts": { | ||
"start": "node ." | ||
}, | ||
"engines": { | ||
@@ -16,3 +19,4 @@ "node": ">=6.0.0" | ||
"inquirer": "^1.0.3", | ||
"js-yaml": "^3.6.1" | ||
"js-yaml": "^3.6.1", | ||
"prompt": "^1.0.0" | ||
}, | ||
@@ -19,0 +23,0 @@ "devDependencies": { |
@@ -1,1 +0,18 @@ | ||
# emdaer | ||
# emdaer | ||
does a README.md | ||
## CLI | ||
```sh | ||
$ npm install -g index.js | ||
$ index.js | ||
``` | ||
## Scripts | ||
### start | ||
```sh | ||
$ npm run start | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2678
60
19
3
1
+ Addedprompt@^1.0.0
+ Added@colors/colors@1.5.0(transitive)
+ Addedasync@2.6.43.2.3(transitive)
+ Addedcolors@1.0.3(transitive)
+ Addedcycle@1.0.3(transitive)
+ Addedeyes@0.1.8(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedprompt@1.3.0(transitive)
+ Addedread@1.0.7(transitive)
+ Addedrevalidator@0.1.8(transitive)
+ Addedstack-trace@0.0.10(transitive)
+ Addedwinston@2.4.7(transitive)