diff --git a/.gitignore b/.gitignore index 53602099..81bbc18c 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/src/configs/assorted/npm-opensource.json b/src/configs/assorted/npm-opensource.json index 0de32b48..b8db7ceb 100644 --- a/src/configs/assorted/npm-opensource.json +++ b/src/configs/assorted/npm-opensource.json @@ -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" ] } diff --git a/src/configs/badges/js-gardener.json b/src/configs/badges/js-gardener.json index e1f6e3ac..59729c6c 100644 --- a/src/configs/badges/js-gardener.json +++ b/src/configs/badges/js-gardener.json @@ -2,10 +2,7 @@ "target": "README.md", "strategy": "merge-below-title", "snippets": [ - { - "name": "js-gardener", - "variables": {} - } + "js-gardener" ], "variables": {} } diff --git a/src/configs/badges/recommended.json b/src/configs/badges/npm-opensource.json similarity index 100% rename from src/configs/badges/recommended.json rename to src/configs/badges/npm-opensource.json diff --git a/src/configs/badges/semantic-release.json b/src/configs/badges/semantic-release.json index 54ada873..594399e6 100644 --- a/src/configs/badges/semantic-release.json +++ b/src/configs/badges/semantic-release.json @@ -2,10 +2,7 @@ "target": "README.md", "strategy": "merge-below-title", "snippets": [ - { - "name": "semantic-release", - "variables": {} - } + "semantic-release" ], "variables": {} } diff --git a/src/configs/circleci/npm-release.json b/src/configs/circleci/npm-release.json index 678bf027..5818fbff 100644 --- a/src/configs/circleci/npm-release.json +++ b/src/configs/circleci/npm-release.json @@ -2,10 +2,7 @@ "target": ".circleci/config.yml", "strategy": "overwrite", "snippets": [ - { - "name": "00-base", - "variables": {} - }, + "00-base", { "name": "01-gally-create-staging-pr", "variables": { diff --git a/src/configs/gitignore/npm-opensource.json b/src/configs/gitignore/npm-opensource.json new file mode 100644 index 00000000..df2f4de7 --- /dev/null +++ b/src/configs/gitignore/npm-opensource.json @@ -0,0 +1,13 @@ +{ + "target": ".gitignore", + "strategy": "merge-top", + "snippets": [ + "jetbrains", + "spacer-small", + "osx", + "spacer-small", + "nodejs", + "spacer-big" + ], + "variables": {} +} diff --git a/src/configs/gitignore/snippets/jetbrains.txt b/src/configs/gitignore/snippets/jetbrains.txt new file mode 100644 index 00000000..72f4d988 --- /dev/null +++ b/src/configs/gitignore/snippets/jetbrains.txt @@ -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 diff --git a/src/configs/gitignore/snippets/nodejs.txt b/src/configs/gitignore/snippets/nodejs.txt new file mode 100644 index 00000000..2afecd39 --- /dev/null +++ b/src/configs/gitignore/snippets/nodejs.txt @@ -0,0 +1,4 @@ +# NodeJs Specific +node_modules +npm-debug.log +yarn-error.log diff --git a/src/configs/gitignore/snippets/osx.txt b/src/configs/gitignore/snippets/osx.txt new file mode 100644 index 00000000..71ea5166 --- /dev/null +++ b/src/configs/gitignore/snippets/osx.txt @@ -0,0 +1,2 @@ +# OSX Specific +.DS_Store diff --git a/src/configs/gitignore/snippets/spacer-big.txt b/src/configs/gitignore/snippets/spacer-big.txt new file mode 100644 index 00000000..4365415e --- /dev/null +++ b/src/configs/gitignore/snippets/spacer-big.txt @@ -0,0 +1,5 @@ + +# ---------------------------------------- +# ---------------------------------------- +# ---------------------------------------- + diff --git a/src/configs/gitignore/snippets/spacer-small.txt b/src/configs/gitignore/snippets/spacer-small.txt new file mode 100644 index 00000000..c8e07095 --- /dev/null +++ b/src/configs/gitignore/snippets/spacer-small.txt @@ -0,0 +1,3 @@ + +# ---------------------------------------- + diff --git a/src/configs/semantic-release/commit-convention.json b/src/configs/semantic-release/commit-convention.json index 199c8ece..9f19f9fe 100644 --- a/src/configs/semantic-release/commit-convention.json +++ b/src/configs/semantic-release/commit-convention.json @@ -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": {} } diff --git a/src/util/config.js b/src/util/config.js index a7a03424..af6d8527 100644 --- a/src/util/config.js +++ b/src/util/config.js @@ -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') @@ -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))); } diff --git a/src/util/strategies.js b/src/util/strategies.js index d50c5dc3..e0ee3fb9 100644 --- a/src/util/strategies.js +++ b/src/util/strategies.js @@ -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 }; diff --git a/test/util/strategies.spec.js b/test/util/strategies.spec.js index 8c424527..54a66756 100644 --- a/test/util/strategies.spec.js +++ b/test/util/strategies.spec.js @@ -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']); + }); });