🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@gasket/plugin-git

Package Overview
Dependencies
Maintainers
6
Versions
211
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gasket/plugin-git - npm Package Compare versions

Comparing version
6.17.0
to
6.18.0
+27
CHANGELOG.md
# `@gasket/plugin-git`
### 6.18.0
- Added gitignore property to context ([#344])
### 6.0.0
- Version alignment
- Upgraded dev dependencies ([#247])
### 5.0.0
- Open Source Release
### 1.1.0
- Align package structure and dependencies
### 1.0.0
- Separate git setup from core and cli
- Initial release.
[#247]: https://github.com/godaddy/gasket/pull/247
[#344]: https://github.com/godaddy/gasket/pull/344
/**
* Class to add content to gitignore
*
* @type {Gitignore}
* @property {Object} _content - Content to add to gitignore
*/
module.exports = class Gitignore {
constructor() {
this._content = {
dependencies: new Set(['node_modules']),
testing: new Set(['coverage', 'reports']),
production: new Set(['dist', 'build', '.next']),
misc: new Set(['.env', '.idea', '*.iml', '*.log', '*.bak', '.DS_Store']),
special: new Set(['app.config.local.js*', 'gasket.config.local.js*', '.docs'])
};
}
/**
* Adds content to gitignore
*
* @param {String|String[]} name - name of file or directory to add to gitignore
* @param {String} category - category of gitignore content
*/
add(name, category = '') {
if (Array.isArray(name)) {
name.forEach(n => this.add(n, category));
} else {
this._content[category] ?
this._content[category].add(name) :
this._content[category] = new Set([name]);
}
}
};
+44
-1

@@ -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;
};
+2
-3
{
"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