@reprex/create-project
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "@reprex/create-project", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"author": "SeyyedKhandon@gmail.com", | ||
@@ -19,3 +19,6 @@ "description": "A CLI to bootstrap my new projects", | ||
"ncp": "^2.0.0", | ||
"pkg-install": "^1.0.0" | ||
"pkg-install": "^1.0.0", | ||
"covgen": "^3.1.0", | ||
"gitignore": "^0.6.0", | ||
"spdx-license-list": "^5.0.0" | ||
}, | ||
@@ -22,0 +25,0 @@ "publishConfig": { |
A simple CLI tool for templating | ||
#try use it: | ||
# try use it: | ||
`npx @reprex/create-project --install` | ||
or | ||
# install it globally: | ||
`npx @reprex/create-project` | ||
``` | ||
npm install -g @reprex/create-project | ||
create-project | ||
``` |
@@ -13,8 +13,7 @@ import arg from 'arg'; | ||
'-i': '--install', | ||
} | ||
const option = { | ||
}; | ||
const options = { | ||
argv: rawArgs.slice(2), | ||
}; | ||
const args = arg(spec, option); | ||
console.log(JSON.stringify(args)); | ||
const args = arg(spec, options); | ||
return { | ||
@@ -27,4 +26,5 @@ skipPrompts: args['--yes'] || false, | ||
} | ||
async function promptForMissingOptions(options) { | ||
const defaultTemplate = 'JavaScript'; | ||
const defaultTemplate = 'javascript'; | ||
if (options.skipPrompts) { | ||
@@ -43,3 +43,3 @@ return { | ||
message: 'Please choose which project template to use', | ||
choices: ['JavaScript', 'TypeScript'], | ||
choices: ['javascript', 'typescript'], | ||
default: defaultTemplate, | ||
@@ -53,3 +53,3 @@ }); | ||
name: 'git', | ||
message: 'Initialize a git repository?', | ||
message: 'Should a git be initialized?', | ||
default: false, | ||
@@ -66,2 +66,3 @@ }); | ||
} | ||
export async function cli(args) { | ||
@@ -68,0 +69,0 @@ let options = parseArgumentsIntoOptions(args); |
import chalk from 'chalk'; | ||
import execa from 'execa'; | ||
import fs from 'fs'; | ||
import gitignore from 'gitignore'; | ||
import Listr from 'listr'; | ||
import ncp from 'ncp'; | ||
import path from 'path'; | ||
import { projectInstall } from 'pkg-install'; | ||
import license from 'spdx-license-list/licenses/MIT'; | ||
import { promisify } from 'util'; | ||
import execa from 'execa'; | ||
import Listr from 'listr'; | ||
import { projectInstall } from 'pkg-install'; | ||
const access = promisify(fs.access); | ||
const writeFile = promisify(fs.writeFile); | ||
const copy = promisify(ncp); | ||
const writeGitignore = promisify(gitignore.writeFile); | ||
@@ -19,2 +23,21 @@ async function copyTemplateFiles(options) { | ||
async function createGitignore(options) { | ||
const file = fs.createWriteStream( | ||
path.join(options.targetDirectory, '.gitignore'), | ||
{ flags: 'a' } | ||
); | ||
return writeGitignore({ | ||
type: 'Node', | ||
file: file, | ||
}); | ||
} | ||
async function createLicense(options) { | ||
const targetPath = path.join(options.targetDirectory, 'LICENSE'); | ||
const licenseContent = license.licenseText | ||
.replace('<year>', new Date().getFullYear()) | ||
.replace('<copyright holders>', `${options.name} (${options.email})`); | ||
return writeFile(targetPath, licenseContent, 'utf8'); | ||
} | ||
async function initGit(options) { | ||
@@ -33,3 +56,5 @@ const result = await execa('git', ['init'], { | ||
...options, | ||
targetDirectory: options.targetDirectory || process.cwd() | ||
targetDirectory: options.targetDirectory || process.cwd(), | ||
email: 'SeyyedKhandon@gmail.com', | ||
name: 'SeyyedKhandon', | ||
}; | ||
@@ -51,24 +76,37 @@ | ||
const tasks = new Listr([ | ||
const tasks = new Listr( | ||
[ | ||
{ | ||
title: 'Copy project files', | ||
task: () => copyTemplateFiles(options), | ||
}, | ||
{ | ||
title: 'Create gitignore', | ||
task: () => createGitignore(options), | ||
}, | ||
{ | ||
title: 'Create License', | ||
task: () => createLicense(options), | ||
}, | ||
{ | ||
title: 'Initialize git', | ||
task: () => initGit(options), | ||
enabled: () => options.git, | ||
}, | ||
{ | ||
title: 'Install dependencies', | ||
task: () => | ||
projectInstall({ | ||
cwd: options.targetDirectory, | ||
}), | ||
skip: () => | ||
!options.runInstall | ||
? 'Pass --install to automatically install dependencies' | ||
: undefined, | ||
}, | ||
], | ||
{ | ||
title: 'Copy project files', | ||
task: () => copyTemplateFiles(options), | ||
}, | ||
{ | ||
title: 'Initialize git', | ||
task: () => initGit(options), | ||
enabled: () => options.git, | ||
}, | ||
{ | ||
title: 'Install dependencies', | ||
task: () => | ||
projectInstall({ | ||
cwd: options.targetDirectory, | ||
}), | ||
skip: () => | ||
!options.runInstall | ||
? 'Pass --install to automatically install dependencies' | ||
: undefined, | ||
}, | ||
]); | ||
exitOnError: false, | ||
} | ||
); | ||
@@ -75,0 +113,0 @@ await tasks.run(); |
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
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
14965
253
11
11
+ Addedcovgen@^3.1.0
+ Addedgitignore@^0.6.0
+ Addedspdx-license-list@^5.0.0
+ Addedany-promise@1.3.0(transitive)
+ Addedbent@7.3.12(transitive)
+ Addedbytesish@0.4.4(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcovgen@3.2.1(transitive)
+ Addedgitignore@0.6.0(transitive)
+ Addedmkdirp@1.0.4(transitive)
+ Addedmz@2.7.0(transitive)
+ Addedspdx-license-list@5.0.0(transitive)
+ Addedthenify@3.3.1(transitive)
+ Addedthenify-all@1.6.0(transitive)