Skip to content

Commit

Permalink
feat: 🎸 Set baseDirectory in config
Browse files Browse the repository at this point in the history
Allow baseDirectory to be set in package.json so all files will be
created in that folder, and can be nested by simply adding the child
folder's name in the command, for example: baseDirectory: src and you
enter 'hendrix' the file will be created in 'src', and if you enter
'hendrix utils' file will be created in 'src/utils'
  • Loading branch information
seanwlawrence committed Sep 28, 2018
1 parent 131a05a commit 0a3c7dc
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 18 deletions.
65 changes: 65 additions & 0 deletions bin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "hendrix",
"version": "0.0.0",
"description": "A CLI scaffolding tool for creating new scripts, pages and configuration files.",
"main": "bin/index.js",
"bin": {
"hendrix": "./bin/index.js"
},
"scripts": {
"test": "make test",
"test-watch": "make test-watch",
"lint": "make lint",
"develop": "make develop",
"build": "make build",
"start": "make start",
"commit": "make commit",
"ci": "make ci",
"create-docs": "make create-docs"
},
"keywords": [
"generator",
"scaffold",
"boilerplate"
],
"author": "Sean W. Lawrence",
"license": "MIT",
"dependencies": {
"chalk": "^2.4.1",
"inquirer": "^6.2.0",
"markdown-it": "^8.4.2",
"markdown-it-anchor": "^5.0.2",
"markdown-it-attrs": "^2.3.1",
"markdown-it-center-text": "^1.0.4",
"markdown-it-container": "^2.0.0",
"markdown-it-front-matter": "^0.1.2",
"markdown-it-header-sections": "^1.0.0",
"markdown-it-replace-link": "^1.0.1",
"markdown-it-responsive": "^0.1.0",
"markdown-it-smartarrows": "^1.0.1",
"markdown-it-toc-done-right": "^2.0.3",
"mdfigcaption": "^0.1.1",
"mustache": "^2.3.2",
"rxjs": "^6.3.3"
},
"devDependencies": {
"@types/inquirer": "0.0.43",
"@types/jest": "^23.3.2",
"@types/markdown-it": "0.0.5",
"@types/mustache": "^0.8.31",
"@types/node": "^10.11.0",
"cz-conventional-changelog": "^2.1.0",
"jest": "^23.5.0",
"nodemon": "^1.18.4",
"ts-jest": "^23.10.2",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"typescript": "^3.0.3",
"typescript-formatter": "^7.2.2"
},
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
}
}
}
19 changes: 12 additions & 7 deletions bin/src/cli.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,5 @@
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
}
},
"hendrix": {
"outputPath": "./public"
}
}
19 changes: 13 additions & 6 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { logSuccess } from './utils/log';
import { formatFilename, formatProps } from './utils/format';
import { Answers } from './globals';
const packageJSON = require(join(process.cwd(), 'package.json'));

function createPage(answers: Answers) {
const {
Expand All @@ -27,22 +28,28 @@ function createPage(answers: Answers) {

const [, , ...args] = process.argv;

const outputDirectory: string = join(process.cwd(), args[0] ? args[0] : '');
const baseUrl = packageJSON.hendrix ? packageJSON.hendrix.baseDirectory : '';
const additionalPath = args[0] || '';
const outputDirectory: string = join(process.cwd(), baseUrl, additionalPath);

console.log('PATH', baseUrl, additionalPath, outputDirectory);

const outputPath: string = join(
outputDirectory,
`${outputName}.${extension}`,
);

if (existsSync(outputDirectory)) {
console.log('FILE EXISTS', outputDirectory);
writeFileSync(outputPath, fileContent);
} else {
mkdirSync(join(process.cwd(), args[0]));

writeFileSync(outputPath, fileContent);
return logSuccess(answers.template.prettyName, outputDirectory);
}

logSuccess(answers.template.prettyName, outputPath);
console.log('FILE NO EXISTS', outputDirectory);
mkdirSync(outputDirectory);

writeFileSync(outputPath, fileContent);
return logSuccess(answers.template.prettyName, outputDirectory);
}

const getTemplate = {
Expand Down
7 changes: 5 additions & 2 deletions src/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @flow

/**
* @typedef Answers
* @property {string} type - Type of generator
Expand All @@ -22,3 +20,8 @@ export type Answers = {
outputName: string;
props: Array<{ name: string; value: string }>;
};

declare module '*.json' {
const value: any;
export default value;
}

0 comments on commit 0a3c7dc

Please sign in to comment.