Skip to content

Commit

Permalink
Merge pull request #38 from blackflux/dev
Browse files Browse the repository at this point in the history
[Gally]: master <- dev
  • Loading branch information
simlu committed Mar 12, 2019
2 parents d677c89 + d08d2c8 commit a0f85fc
Show file tree
Hide file tree
Showing 16 changed files with 208 additions and 33 deletions.
83 changes: 77 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,89 @@
# IDE Specific
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# OS Specific
# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

# ----------------------------------------

# OSX Specific
.DS_Store

# Node Specific
# ----------------------------------------

# NodeJs Specific
node_modules
npm-debug.log
yarn-error.log

# ----------------------------------------
# ----------------------------------------
# ----------------------------------------

# Test Specific
# Custom
coverage/
.coveralls.yml
lib/
yarn-error.log
release.tar.gz
.idea/dictionaries
5 changes: 3 additions & 2 deletions src/configs/assorted/npm-opensource.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"configs": [
"badges/npm-opensource",
"gitignore/npm-opensource",
"gally/two-branch",
"circleci/npm-release",
"dependabot/nodejs-instant",
"semantic-release/commit-convention",
"editor/two-space",
"badges/recommended"
"editor/two-space"
]
}
5 changes: 1 addition & 4 deletions src/configs/badges/js-gardener.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"target": "README.md",
"strategy": "merge-below-title",
"snippets": [
{
"name": "js-gardener",
"variables": {}
}
"js-gardener"
],
"variables": {}
}
File renamed without changes.
5 changes: 1 addition & 4 deletions src/configs/badges/semantic-release.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"target": "README.md",
"strategy": "merge-below-title",
"snippets": [
{
"name": "semantic-release",
"variables": {}
}
"semantic-release"
],
"variables": {}
}
5 changes: 1 addition & 4 deletions src/configs/circleci/npm-release.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"target": ".circleci/config.yml",
"strategy": "overwrite",
"snippets": [
{
"name": "00-base",
"variables": {}
},
"00-base",
{
"name": "01-gally-create-staging-pr",
"variables": {
Expand Down
13 changes: 13 additions & 0 deletions src/configs/gitignore/npm-opensource.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"target": ".gitignore",
"strategy": "merge-top",
"snippets": [
"jetbrains",
"spacer-small",
"osx",
"spacer-small",
"nodejs",
"spacer-big"
],
"variables": {}
}
66 changes: 66 additions & 0 deletions src/configs/gitignore/snippets/jetbrains.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
4 changes: 4 additions & 0 deletions src/configs/gitignore/snippets/nodejs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# NodeJs Specific
node_modules
npm-debug.log
yarn-error.log
2 changes: 2 additions & 0 deletions src/configs/gitignore/snippets/osx.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# OSX Specific
.DS_Store
5 changes: 5 additions & 0 deletions src/configs/gitignore/snippets/spacer-big.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

# ----------------------------------------
# ----------------------------------------
# ----------------------------------------

3 changes: 3 additions & 0 deletions src/configs/gitignore/snippets/spacer-small.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# ----------------------------------------

10 changes: 2 additions & 8 deletions src/configs/semantic-release/commit-convention.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@
"target": ".releaserc.json",
"strategy": "overwrite",
"snippets": [
{
"name": "angular",
"variables": {}
},
{
"name": "build-deps-as-patch",
"variables": {}
}
"angular",
"build-deps-as-patch"
],
"variables": {}
}
13 changes: 8 additions & 5 deletions src/util/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ const configSchema = Joi.object().keys({
target: Joi.string(),
strategy: Joi.string().valid(...Object.keys(strategies)),
variables: Joi.object(),
snippets: Joi.array().items(Joi.object().keys({
name: Joi.string().required(),
variables: Joi.object().required()
}).unknown(false).required()),
snippets: Joi.array().items(
Joi.string(),
Joi.object().keys({
name: Joi.string().required(),
variables: Joi.object().min(1).required()
}).unknown(false)
).min(1),
configs: Joi.array().items(Joi.string())
})
.and('target', 'strategy', 'variables', 'snippets')
Expand Down Expand Up @@ -56,7 +59,7 @@ module.exports.loadConfig = (configName, variables) => {
// load and merge config snippets into config
const snippetDir = path.join(__dirname, '..', 'configs', configName.split('/')[0], 'snippets');
config.toWrite = deepmerge.all(config.snippets
.map(m => [m.name, m.variables])
.map(m => (typeof m === 'string' ? [m, {}] : [m.name, m.variables]))
.map(([snippetName, snippetVars]) => [snippetName, populateVars(snippetVars, config.variables, true)])
.map(([snippetName, snippetVars]) => loadSnippet(snippetDir, snippetName, config, snippetVars)));
}
Expand Down
15 changes: 15 additions & 0 deletions src/util/strategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,20 @@ module.exports = {
existing.splice(injectAt, 0, ...changeset.filter(line => !existing.includes(line)));
return existing;
},
'merge-top': (existing, changeset) => {
changeset.forEach((line) => {
for (let idx = 0; idx < existing.length; idx += 1) {
const l = existing[idx];
if (line === l) {
existing.splice(idx, 1);
idx -= 1;
if (l === '') {
break; // line has now caused exactly one removal
}
}
}
});
return changeset.concat(existing);
},
overwrite: (existing, changeset) => changeset
};
7 changes: 7 additions & 0 deletions test/util/strategies.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ describe('Integration strategies.js', () => {
expect(strategies['merge-below-title'](existing, changeset))
.to.deep.equal(['title1', 'title2', '', 'new', 'text']);
});

it('Testing Merge Strategy: merge-top', () => {
const existing = ['title1', 'title2', '', 'new', 'text'];
const changeset = ['new'];
expect(strategies['merge-top'](existing, changeset))
.to.deep.equal(['new', 'title1', 'title2', '', 'text']);
});
});

0 comments on commit a0f85fc

Please sign in to comment.