Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V5 take one #149

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7b4f1b7
json cleanup
anithri Aug 18, 2019
bd8dd62
Merge remote-tracking branch 'upstream/master'
anithri Sep 4, 2019
641625b
noodling for v5
anithri Sep 20, 2019
b613645
flesh out a few things
anithri Sep 20, 2019
5c73059
flesh out a few things
anithri Sep 20, 2019
6be2794
undo changes to existing files
anithri Sep 21, 2019
174e45e
beginnings
anithri Sep 21, 2019
b2d0e9a
base setup getting there
anithri Sep 21, 2019
d29eb17
walkers & pathTo
anithri Sep 21, 2019
5ca451c
scattered work on everything
anithri Sep 21, 2019
a314969
learning and rabbitholing
anithri Sep 22, 2019
1565e30
tweak template
anithri Sep 22, 2019
db0c19a
fleshing things out
anithri Sep 22, 2019
82d37a6
yargs
anithri Sep 22, 2019
a52c8e0
more shotgun approach work. start over for real thing and we can che…
anithri Sep 23, 2019
cedf360
filling in holes is easy when you know it does not need to
anithri Sep 23, 2019
e0e19e1
coding before bed
anithri Sep 27, 2019
85a8064
noodle
anithri Sep 27, 2019
c5b148e
reorg, config and typescript
anithri Sep 29, 2019
80734a7
more type investigations
anithri Sep 30, 2019
02d0d22
need convention for types
anithri Sep 30, 2019
e469d38
types and resolvers
anithri Oct 1, 2019
938fa73
mergeConfig
anithri Oct 2, 2019
3ae8de3
strip flow
anithri Oct 2, 2019
552353e
reorg
anithri Oct 3, 2019
ea9a42a
types and making things match types
anithri Oct 7, 2019
55129fe
work on logger type
anithri Oct 7, 2019
2d0de8a
more types work
anithri Oct 14, 2019
28edae5
rewrite YargsType
anithri Oct 15, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
"@babel/env",
{
"targets": {
"node": "6.0"
"node": "current"
}
}
],
"@babel/react",
"@babel/preset-flow"
"@babel/preset-typescript"
]
}
}
46 changes: 0 additions & 46 deletions .eslintrc

This file was deleted.

29 changes: 29 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'prettier/@typescript-eslint',
],
parserOptions: {
project: './tsconfig.json',
ecmaVersion: 2015,
sourceType: 'module',
},
rules: {
'prettier/prettier': [
'error',
{
semi: false,
singleQuote: true,
},
],
'prettier/semi': 0,
'space-before-function-paren': 0,
'comma-dangle': 0,
'jsx-quotes': 0,
'react/jsx-filename-extension': 'off',
},
settings: {},
}
15 changes: 0 additions & 15 deletions .flowconfig

This file was deleted.

1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all"
}
193 changes: 193 additions & 0 deletions Vision-v5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# Version 5
An update for hygen.js that expands functionality and modularity.

## Goals
* streamline and standardize into a pipeline
* improve configuration
* standardize config
* lifecycle hooks
* main process the result of a series of resolvers
* supporting behavior the result of a series of modules
* standardize fully to flow (or typescript?)
* use promises/async/await throughout
* flow same data through entire process.
* add additional layers of generator and action specific config

## Config Object
The config object will be passed from hook to module to resolver, building it
, changing it, adding tools...

As such it needs a standard set of keys and instructions on how to merge two
together. Additionally, that makes it possible to use multiple .hygen.js
files in your projects.
```javascript
/* REPLACE = older value replaces newer */
/* SHALLOW = merging objects ({...one, ...two}), subObjects replaced */
/* JOIN = when merging, the object keys and array values are SHALLOW */
/* in all cases, the data can be manipulated however you like, but you could break some things */
const config = {
/*REPLACE data about runtime environment */
env: {argv,cwd,templatesDir,configFilename},

/*REPLACE logger to be used throughout */
logger: mkLogger(),

/*REPLACE metadata about config file used */
configFile: {globalPaths: [], localPaths: []},

/*JOIN modules to use */
modules: [],
/*JOIN localConfigFiles */
localConfigFilenames: [],
/*JOIN directives */
directives: [],

/*JOIN metadata about generator, actions, subactions, files, ignores... */
generator: {name, action, subaction,
templates: [],ignored: [], paramFiles: []},

/*SHALLOW helper functions and constants to be made available in templates */
helpers: {},
/*SHALLOW helper functions and constants meant for non template usage */
tools: {exec,createPrompter,path,io,fs},

/*SHALLOW parsed argv */
/* the yargsOptionResolver resolves global options like --help, --trace, --dry-run */
/* the yargsParamsResolver resolves for action specific values like --name */
params: {},
options: {},

/*JOIN lifecycle hooks */
hooks: {postConfig: [], preTemplates: [], ...},
/*JOIN path parts to be ignored in generator discovery */
ignored: { generators: [], actions: [], files: [], patterns: [] },
}
```
### Promises everywhere
promises will be used to chain resolvers and hook

## Resolvers
A resolver receives and returns a config object, and in between accomplishes
one of the major tasks of hygen.

#### Config
The config Resolver sets the default config, then crawls from `cwd` to
`/` seeking `process.env.HYGEN_CONFIG_FILE || '.hygen.js` files, and reading
the ones it does find.

###### Hooks
* postConfig - after all config files read and merged
* this is the first hook run

#### Module
The module resolve find and loads all modules defined in `config.modules`
each module is merged with config.

Modules may be defined in a few ways depending on the type of the module
* strings will be used as the name of a built in module and loaded internally
* functions will be executed and result merged with config
* objects will be merged with config

###### Hooks
* preModule - before the array of modules is read
* eachModule - after each module is read
* postModule - after all of the modules are loaded
* postModuleYargs - after yargs is run again with module options

#### ~~YargsOptions~~
Parsing argv for options, and using hooks to provide a way to chain call and
use more of the power of `yargs-parser`. Result is merged specifically into
`config.options`

###### ~~Hooks~~
* preYargsOptionsParser
* yargsOptionParsers for adding parsers before parsing
* postYargsOptionsParser

#### Generator
Find the correct directory for the given generator and action, and create a
metadata object about it. The data in `config.ignored` is used to skip
specific directories and files.

Any paramFiles found between `_templates` and `_templates/gen/action` will be
read and merged.
```generator: {name, action, subaction,templates: [],ignored: [], paramFiles: []}```

###### Hooks
* preGenerator
* missingGenerator
* postGenerator

#### YargsParams
As yargsOptions, but run after the generator has loaded. The result is merged
specifically into `config.params`

###### Hooks
* preParamsParsers
* yargsParamsParsers for adding parsers before parsing
* postParamsParsers

#### Params
Processing the params is only a matter of running all of the hooks.

###### Hooks
* preParams
* eachParams
* params
* postParams

#### templates
Find and load all of the necessary templates.

###### Hooks
* preTemplates
* eachTemplate
* missingTemplates
* postTemplates

#### directives
Directives define specific render actions for each template file. The
frontmatter of each template is parsed for the various directives available
(as below), and RenderActions are created. Any keys found in the frontmatter
not related to a directive will be added to the context for the template
generation.

Additional directives could be added.

###### current directives
* inject
* message
* sh
* writeFile

###### Hooks
* preDirectives
* eachDirective
* failedDirective
* postDirectives

#### render - render templates
Loop through all RenderActions and execute each one.

###### Hooks
* preRender
* eachRender
* failedRender
* postRender

## Modules
A module is a packaged set of helpers, tools, hooks, and ignored. A module is
just another config file, merged into the rest.

* logging - an advanced logger that respect `cli --quiet, --trace, --logLevel 4`
* help - a system wide help system
* pathTo - path creation utility
* nameMaker - a name mutation utility
* jsonSource - read a json file and add to config, also yml, csv...
* prompt - interactive prompt system

#### Promises
All resolvers and hooks are expected to return either a config object or a
promise to deliver one. All resolvers and hooks are then chained for
execution.

15 changes: 15 additions & 0 deletions _templates/directive/new/directive.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
to: <%- [process.cwd(), 'v5', 'directives', `${name}.ts`].join('/') %>
---
import { HygenConfig } from './hygen'


export const <%- `${name}Directive` %> = (config: HygenConfig): Promise<HygenConfig> => {
const {frontMatter} = config
// find keys from frontMatter that matter, return if you don't
// perform appropriate actions based on data

return config
}

export default <%- ${name}Directive %>
5 changes: 5 additions & 0 deletions _templates/generator/help/index.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
message: |
hygen {bold generator new} --name [NAME] --action [ACTION]
hygen {bold generator with-prompt} --name [NAME] --action [ACTION]
---
18 changes: 18 additions & 0 deletions _templates/generator/new/hello.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
to: _templates/<%= name %>/<%= action || 'new' %>/hello.ejs.t
---
---
to: app/hello.js
---
const hello = ```
Hello!
This is your first hygen template.

Learn what it can do here:

https://github.com/jondot/hygen
```

console.log(hello)


18 changes: 18 additions & 0 deletions _templates/generator/with-prompt/hello.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
to: _templates/<%= name %>/<%= action || 'new' %>/hello.ejs.t
---
---
to: app/hello.js
---
const hello = ```
Hello!
This is your first prompt based hygen template.

Learn what it can do here:

https://github.com/jondot/hygen
```

console.log(hello)


14 changes: 14 additions & 0 deletions _templates/generator/with-prompt/prompt.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
to: _templates/<%= name %>/<%= action || 'new' %>/prompt.js
---

// see types of prompts:
// https://github.com/enquirer/enquirer/tree/master/examples
//
module.exports = [
{
type: 'input',
name: 'message',
message: "What's your message?"
}
]
Loading