@gasket/plugin-git
Advanced tools
Comparing version 6.17.0 to 6.18.0
@@ -0,2 +1,41 @@ | ||
const Gitignore = require('./gitignore'); | ||
/** | ||
* Formats gitignore content | ||
* | ||
* @param {Object} content - gitignore content | ||
* @returns {string} formatted gitignore content | ||
*/ | ||
function serialize(content) { | ||
let desiredContent = ''; | ||
for (const category in content) { | ||
if (content[category].size) { | ||
category !== '' ? desiredContent += `# ${category}\n` : null; | ||
desiredContent += [...content[category]].join('\n'); | ||
desiredContent += '\n\n'; | ||
} | ||
} | ||
return desiredContent; | ||
} | ||
/** | ||
* Instantiates new Gitignore instance, adds get method to content using the serialize function, adds gitignore to context | ||
* | ||
* @param {CreateContext} context - Create context | ||
*/ | ||
function instantiateGitignore(context) { | ||
const gitignore = new Gitignore(); | ||
Object.defineProperties(gitignore, { | ||
content: { | ||
get() { | ||
return serialize(this._content); | ||
} | ||
} | ||
}); | ||
context.gitignore = gitignore; | ||
} | ||
/** | ||
* Prompt for git settings during gasket create | ||
@@ -11,3 +50,2 @@ * | ||
module.exports = async function promptHook(gasket, context, { prompt }) { | ||
if (!('gitInit' in context)) { | ||
@@ -21,6 +59,11 @@ const { gitInit } = await prompt([ | ||
instantiateGitignore(context); | ||
return { ...context, gitInit }; | ||
} | ||
if ('gitInit' in context) { | ||
instantiateGitignore(context); | ||
} | ||
return context; | ||
}; |
{ | ||
"name": "@gasket/plugin-git", | ||
"version": "6.17.0", | ||
"version": "6.18.0", | ||
"description": "Adds git support to your application", | ||
@@ -66,4 +66,3 @@ "main": "lib", | ||
} | ||
}, | ||
"gitHead": "4c6def3cdc22e351179b24aed0907b243616f9ae" | ||
} | ||
} |
@@ -43,2 +43,52 @@ # @gasket/plugin-git | ||
If you have a plugin which needs to add git ignore rules, in the `create` | ||
lifecycle hook of your plugin, you can access `gitignore` helper to add rules. | ||
Rules can be added to different categories which will group them under comments. | ||
The `gitignore` helper will only be placed on the CreateContext when this plugin | ||
is configured and `gitInit` is true, either by preset config or prompt. | ||
#### Example adding gitignore | ||
```js | ||
module.exports = { | ||
id: 'gasket-plugin-example', | ||
hooks: { | ||
create(gasket, createContext) { | ||
const { gitignore } = createContext; | ||
// See if `gitignore` is on the create context | ||
if(gitignore) { | ||
// ignore a single file | ||
gitignore.add('file-to-be-ignored.js'); | ||
// ignore wildcard rules | ||
gitignore.add('*.tmp'); | ||
// ignore multiple files and/or directories | ||
gitignore.add(['file1.js', 'dir2/']); | ||
// add an ignore under a category | ||
gitignore.add('node_modules', 'dependencies'); | ||
} | ||
} | ||
} | ||
}; | ||
``` | ||
The resulting `.gitignore` that is generated will have all the added gitignore | ||
rules and comments for categories. | ||
```properties | ||
# -- .gitignore file -- | ||
file-to-be-ignored.js | ||
*.tmp | ||
file1.js | ||
dir2/ | ||
# dependencies | ||
node_modules | ||
``` | ||
### postCreate | ||
@@ -63,1 +113,2 @@ | ||
[plugin hook timings]:/packages/gasket-engine/README.md | ||
[Gitignore]: ./lib/gitignore.js |
Sorry, the diff of this file is not supported yet
10386
11
148
113