Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

docworks-repo

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

docworks-repo - npm Package Compare versions

Comparing version 1.6.4 to 1.8.4

.eslintrc.json

74

lib/collection-utils.js

@@ -1,62 +0,70 @@

export function zipByKey(arr1, arr2, makeKey) {
let dict = {};
let res = [];
arr1.forEach(_1 => dict[makeKey(_1)] = _1);
function zipByKey(arr1, arr2, makeKey) {
let dict = {}
let res = []
arr1.forEach(_1 => dict[makeKey(_1)] = _1)
arr2.forEach(_2 => {
if (dict[makeKey(_2)]) {
res.push([dict[makeKey(_2)],_2]);
delete dict[makeKey(_2)];
res.push([dict[makeKey(_2)],_2])
delete dict[makeKey(_2)]
}
else {
res.push([,_2]);
res.push([undefined,_2])
}
});
})
for (let key in dict) {
res.push([dict[key],]);
res.push([dict[key],])
}
return res;
return res
}
export function addRemoveLabels(arr, toAdd, toRemove) {
let newLabels = arr.slice();
toAdd = !!toAdd?(Array.isArray(toAdd)?toAdd:[toAdd]):[];
toRemove = !!toRemove?(Array.isArray(toRemove)?toRemove:[toRemove]):[];
function addRemoveLabels(arr, toAdd, toRemove) {
let newLabels = arr.slice()
toAdd = toAdd?(Array.isArray(toAdd)?toAdd:[toAdd]):[]
toRemove = toRemove?(Array.isArray(toRemove)?toRemove:[toRemove]):[]
toAdd.forEach(item => {
if (newLabels.indexOf(item) === -1)
newLabels.push(item);
});
newLabels.push(item)
})
toRemove.forEach(item => {
let index = newLabels.indexOf(item);
let index = newLabels.indexOf(item)
if (index > -1)
newLabels.splice(index, 1);
});
return newLabels;
newLabels.splice(index, 1)
})
return newLabels
}
export function hasLabel(arr, label) {
return arr.indexOf(label) > -1;
function hasLabel(arr, label) {
return arr.indexOf(label) > -1
}
export function copy() {
const assign = Object.assign({}, ...arguments);
return assign;
function copy() {
const assign = Object.assign({}, ...arguments)
return assign
}
export function compareArraysAsSets(arr1, arr2) {
let set1 = new Set(arr1);
let set2 = new Set(arr2);
let res = {equal: true, onlyIn1: [], onlyIn2: []};
function compareArraysAsSets(arr1, arr2) {
let set1 = new Set(arr1)
let set2 = new Set(arr2)
let res = {equal: true, onlyIn1: [], onlyIn2: []}
for (let item of set1)
if (!set2.has(item))
res.onlyIn1.push(item);
res.onlyIn1.push(item)
for (let item of set2)
if (!set1.has(item))
res.onlyIn2.push(item);
res.onlyIn2.push(item)
res.equal = res.onlyIn1.length + res.onlyIn2.length === 0;
return res;
res.equal = res.onlyIn1.length + res.onlyIn2.length === 0
return res
}
module.exports = {
addRemoveLabels,
compareArraysAsSets,
copy,
hasLabel,
zipByKey
}

@@ -1,11 +0,18 @@

import {readDir} from './operations';
export {saveToDir, serviceFromJson, serviceToJson} from './operations';
export merge from './merge';
const {readDir} = require('./operations')
const {saveToDir, serviceFromJson, serviceToJson} = require('./operations')
const merge = require('./merge')
export function readFromDir(directory) {
function readFromDir(directory) {
return readDir(directory)
.then((services) => {
return {services}
});
})
}
module.exports = {
readFromDir,
merge,
saveToDir,
serviceFromJson,
serviceToJson
}

@@ -1,7 +0,7 @@

import {zipByKey, addRemoveLabels, hasLabel, copy, compareArraysAsSets} from './collection-utils';
import isEqual from 'lodash.isequal';
import {loadPlugins, runPlugins} from './plugins';
const {zipByKey, addRemoveLabels, hasLabel, copy, compareArraysAsSets} = require('./collection-utils')
const {loadPlugins, runPlugins} = require('./plugins')
const isEqual = require('lodash.isequal')
function serviceKey(service) {
return service.memberOf?`${service.memberOf}.${service.name}`:service.name;
return service.memberOf?`${service.memberOf}.${service.name}`:service.name
}

@@ -12,13 +12,13 @@

if (itemKey)
itemKey = ' ' + itemKey + ' ';
itemKey = ' ' + itemKey + ' '
else
itemKey = ' ';
messages.push(`Service ${serviceKey} has changed${itemKey}type`);
return false;
itemKey = ' '
messages.push(`Service ${serviceKey} has changed${itemKey}type`)
return false
}
return true;
return true
}
function compareArrays(sNewArr, sRepoArr, messages, serviceKey, attribute) {
let compareResult = compareArraysAsSets(sNewArr, sRepoArr);
let compareResult = compareArraysAsSets(sNewArr, sRepoArr)
for (let item of compareResult.onlyIn1)

@@ -28,3 +28,3 @@ messages.push(`Service ${serviceKey} has a new ${attribute} ${item}`)

messages.push(`Service ${serviceKey} ${attribute} ${item} was removed`)
return compareResult.equal;
return compareResult.equal
}

@@ -34,45 +34,48 @@

if (sNewValue !== sRepoValue) {
messages.push(`Service ${key} has changed ${attribute}`);
return false;
messages.push(`Service ${key} has changed ${attribute}`)
return false
}
return true;
return true
}
/*
/* unused legacy...
function compareDocs(newDocs, repoDocs, messages, key) {
let summaryEqual = compareAttribute(newDocs.summary, repoDocs.summary, messages, key, 'summary');
let descriptionEqual = compareAttribute(newDocs.description, repoDocs.description, messages, key, 'description');
let linksEqual = compareArrays(newDocs.links, repoDocs.links, messages, key, 'link');
return summaryEqual && descriptionEqual && linksEqual;
let summaryEqual = compareAttribute(newDocs.summary, repoDocs.summary, messages, key, 'summary')
let descriptionEqual = compareAttribute(newDocs.description, repoDocs.description, messages, key, 'description')
let linksEqual = compareArrays(newDocs.links, repoDocs.links, messages, key, 'link')
return summaryEqual && descriptionEqual && linksEqual
}
*/
function mergeExample(newExample, repoExample, messages, key, plugins) {
let titleEqual = compareAttribute(newExample.title, repoExample.title, messages, key, 'title');
let bodyEqual = compareAttribute(newExample.body, repoExample.body, messages, key, 'body');
let extraMerge = runPlugins(plugins, 'docworksMergeExample', newExample.extra || {}, repoExample.extra || {}, messages, key);
let changed = !titleEqual || !bodyEqual || extraMerge.changed;
let titleEqual = compareAttribute(newExample.title, repoExample.title, messages, key, 'title')
let bodyEqual = compareAttribute(newExample.body, repoExample.body, messages, key, 'body')
let extraMerge = runPlugins(plugins, 'docworksMergeExample', newExample.extra || {}, repoExample.extra || {}, messages, key)
let changed = !titleEqual || !bodyEqual || extraMerge.changed
const item = copy(newExample, {
extra: extraMerge.merged
});
return {changed, item: item};
})
return {changed, item: item}
}
function mergeExamples(newExamples, repoExamples, messages, key, plugins) {
let changed = newExamples.length !== repoExamples.length;
let examples = [];
let changed = newExamples.length !== repoExamples.length
let examples = []
for (let i = 0; i < Math.min(newExamples.length, repoExamples.length); i++) {
let mergedExample = mergeExample(newExamples[i], repoExamples[i], messages, key + `[${i}]`, plugins);
changed = changed || mergedExample.changed;
let mergedExample = mergeExample(newExamples[i], repoExamples[i], messages, key + `[${i}]`, plugins)
changed = changed || mergedExample.changed
examples.push(mergedExample.item)
}
if (newExamples.length > repoExamples.length) {
messages.push(`Service ${key} has ${newExamples.length - repoExamples.length} new examples`);
messages.push(`Service ${key} has ${newExamples.length - repoExamples.length} new examples`)
examples = examples.concat(newExamples
.slice(repoExamples.length)
.map(_ => copy(_)));
.map(_ => copy(_)))
}
else if (newExamples.length < repoExamples.length){
messages.push(`Service ${key} has ${repoExamples.length - newExamples.length} examples removed`);
messages.push(`Service ${key} has ${repoExamples.length - newExamples.length} examples removed`)
}
return {changed, examples};
return {changed, examples}
}

@@ -82,8 +85,8 @@

function compareDocs2(newDocs, repoDocs, messages, key, plugins) {
let summaryEqual = compareAttribute(newDocs.summary, repoDocs.summary, messages, key, 'summary');
let descriptionEqual = compareAttribute(newDocs.description, repoDocs.description, messages, key, 'description');
let linksEqual = compareArrays(newDocs.links, repoDocs.links, messages, key, 'link');
let extraMerge = runPlugins(plugins, 'docworksMergeDocs', newDocs.extra || {}, repoDocs.extra || {}, messages, key + '.docs');
let examplesMerge = mergeExamples(newDocs.examples, repoDocs.examples, messages, key + '.examples', plugins);
let changed = !summaryEqual || !descriptionEqual || !linksEqual || extraMerge.changed || examplesMerge.changed;
let summaryEqual = compareAttribute(newDocs.summary, repoDocs.summary, messages, key, 'summary')
let descriptionEqual = compareAttribute(newDocs.description, repoDocs.description, messages, key, 'description')
let linksEqual = compareArrays(newDocs.links, repoDocs.links, messages, key, 'link')
let extraMerge = runPlugins(plugins, 'docworksMergeDocs', newDocs.extra || {}, repoDocs.extra || {}, messages, key + '.docs')
let examplesMerge = mergeExamples(newDocs.examples, repoDocs.examples, messages, key + '.examples', plugins)
let changed = !summaryEqual || !descriptionEqual || !linksEqual || extraMerge.changed || examplesMerge.changed

@@ -93,3 +96,3 @@ let docs = copy(newDocs, {

examples: examplesMerge.examples
});
})
return {changed, merged: docs}

@@ -107,10 +110,10 @@ }

function mergeProperty(newProperty, repoProperty, messages, key, plugins) {
let changedType = !compareType(newProperty.type, repoProperty.type, messages, key);
let changedGetter = !compareAttribute(newProperty.get, repoProperty.get, messages, key, 'getter');
let changedSetter = !compareAttribute(newProperty.set, repoProperty.set, messages, key, 'setter');
let defaultValue = !compareAttribute(newProperty.defaultValue, repoProperty.defaultValue, messages, key, 'default value');
let docsMerge = compareDocs2(newProperty.docs, repoProperty.docs, messages, key, plugins);
let extraMerge = runPlugins(plugins, 'docworksMergeProperty', newProperty.extra || {}, repoProperty.extra || {}, messages, key);
let changedType = !compareType(newProperty.type, repoProperty.type, messages, key)
let changedGetter = !compareAttribute(newProperty.get, repoProperty.get, messages, key, 'getter')
let changedSetter = !compareAttribute(newProperty.set, repoProperty.set, messages, key, 'setter')
let defaultValue = !compareAttribute(newProperty.defaultValue, repoProperty.defaultValue, messages, key, 'default value')
let docsMerge = compareDocs2(newProperty.docs, repoProperty.docs, messages, key, plugins)
let extraMerge = runPlugins(plugins, 'docworksMergeProperty', newProperty.extra || {}, repoProperty.extra || {}, messages, key)
let changed = changedType || changedGetter || changedSetter || defaultValue || docsMerge.changed || extraMerge.changed;
let changed = changedType || changedGetter || changedSetter || defaultValue || docsMerge.changed || extraMerge.changed
let item = copy(repoProperty, {

@@ -125,4 +128,4 @@ labels: updateLabels(repoProperty.labels, changed),

extra: extraMerge.merged
});
delete item.srcDocs;
})
delete item.srcDocs
return {changed, item}

@@ -132,31 +135,31 @@ }

function mergeLists(newList, repoList, messages, sKey, itemName, mergeItem, plugins) {
let zipped = zipByKey(newList, repoList, _ => _.name);
let changed = false;
let zipped = zipByKey(newList, repoList, _ => _.name)
let changed = false
let merged = zipped.map(_ => {
let newItem = _[0];
let repoItem = _[1];
let newItem = _[0]
let repoItem = _[1]
if (newItem && repoItem) {
let mergedItem = mergeItem(newItem, repoItem, messages, `${sKey} ${itemName} ${newItem.name}`, plugins);
changed = changed || mergedItem.changed;
return mergedItem.item;
let mergedItem = mergeItem(newItem, repoItem, messages, `${sKey} ${itemName} ${newItem.name}`, plugins)
changed = changed || mergedItem.changed
return mergedItem.item
}
else if (newItem) {
let mergedItem = copy(newItem, {labels: addRemoveLabels(newItem.labels, 'new')});
messages.push(`Service ${sKey} has a new ${itemName} ${mergedItem.name}`);
changed = true;
return mergedItem;
let mergedItem = copy(newItem, {labels: addRemoveLabels(newItem.labels, 'new')})
messages.push(`Service ${sKey} has a new ${itemName} ${mergedItem.name}`)
changed = true
return mergedItem
}
else {
let mergedItem;
let mergedItem
if (!repoItem.labels.find(_ => _ === 'removed')) {
mergedItem = copy(repoItem, {labels: addRemoveLabels(repoItem.labels, 'removed', 'new')});
messages.push(`Service ${sKey} ${itemName} ${mergedItem.name} was removed`);
changed = true;
return mergedItem;
mergedItem = copy(repoItem, {labels: addRemoveLabels(repoItem.labels, 'removed', 'new')})
messages.push(`Service ${sKey} ${itemName} ${mergedItem.name} was removed`)
changed = true
return mergedItem
}
else
mergedItem = copy(repoItem);
return mergedItem;
mergedItem = copy(repoItem)
return mergedItem
}
});
})
return {changed, merged}

@@ -166,10 +169,10 @@ }

function mergeParam(newParam, repoParam, messages, key) {
let changedName = newParam.name !== repoParam.name;
let changedName = newParam.name !== repoParam.name
if (changedName) {
messages.push(`Service ${key} has changed param name from ${repoParam.name} to ${newParam.name}`);
messages.push(`Service ${key} has changed param name from ${repoParam.name} to ${newParam.name}`)
}
let changedType = !compareType(newParam.type, repoParam.type, messages, key, `param ${newParam.name}`);
let changedDoc = !compareAttribute(newParam.doc, repoParam.doc, messages, key, `param ${newParam.name} doc`);
let changedType = !compareType(newParam.type, repoParam.type, messages, key, `param ${newParam.name}`)
let changedDoc = !compareAttribute(newParam.doc, repoParam.doc, messages, key, `param ${newParam.name} doc`)
let changed = changedName || changedType || changedDoc;
let changed = changedName || changedType || changedDoc
let item = copy(repoParam, {

@@ -179,4 +182,4 @@ name: newParam.name,

doc: newParam.doc
});
delete item.srcDoc;
})
delete item.srcDoc

@@ -187,32 +190,32 @@ return {changed, item}

function mergeParams(newParams, repoParams, messages, key) {
let changed = newParams.length !== repoParams.length;
let params = [];
let changed = newParams.length !== repoParams.length
let params = []
for (let i = 0; i < Math.min(newParams.length, repoParams.length); i++) {
let mergedParam = mergeParam(newParams[i], repoParams[i], messages, key);
changed = changed || mergedParam.changed;
let mergedParam = mergeParam(newParams[i], repoParams[i], messages, key)
changed = changed || mergedParam.changed
params.push(mergedParam.item)
}
for (let i = newParams.length; i < repoParams.length; i++) {
messages.push(`Service ${key} param ${repoParams[i].name} was removed`);
messages.push(`Service ${key} param ${repoParams[i].name} was removed`)
}
for (let i = repoParams.length; i < newParams.length; i++) {
messages.push(`Service ${key} has a new param ${newParams[i].name}`);
params.push(copy(newParams[i]));
messages.push(`Service ${key} has a new param ${newParams[i].name}`)
params.push(copy(newParams[i]))
}
return {changed, params};
return {changed, params}
}
function mergeOperation(newOperation, repoOperation, messages, key, plugins) {
let paramsMerge = mergeParams(newOperation.params, repoOperation.params, messages, key);
let changedReturn = !compareType(newOperation.ret.type, repoOperation.ret.type, messages, key, 'return');
let changedDoc = !compareAttribute(newOperation.ret.doc, repoOperation.ret.doc, messages, key, `return doc`);
let docsMerge = compareDocs2(newOperation.docs, repoOperation.docs, messages, key, plugins);
let extraMerge = runPlugins(plugins, 'docworksMergeOperation', newOperation.extra || {}, repoOperation.extra || {}, messages, key);
let paramsMerge = mergeParams(newOperation.params, repoOperation.params, messages, key)
let changedReturn = !compareType(newOperation.ret.type, repoOperation.ret.type, messages, key, 'return')
let changedDoc = !compareAttribute(newOperation.ret.doc, repoOperation.ret.doc, messages, key, 'return doc')
let docsMerge = compareDocs2(newOperation.docs, repoOperation.docs, messages, key, plugins)
let extraMerge = runPlugins(plugins, 'docworksMergeOperation', newOperation.extra || {}, repoOperation.extra || {}, messages, key)
let changed = paramsMerge.changed || docsMerge.changed || changedReturn || changedDoc || extraMerge.changed;
let changed = paramsMerge.changed || docsMerge.changed || changedReturn || changedDoc || extraMerge.changed
let ret = copy(repoOperation.ret, {
type: newOperation.ret.type,
doc: newOperation.ret.doc
});
delete ret.srcDoc;
})
delete ret.srcDoc
let item = copy(repoOperation, {

@@ -225,4 +228,4 @@ params: paramsMerge.params,

extra: extraMerge.merged
});
delete item.srcDocs;
})
delete item.srcDocs
return {changed, item}

@@ -232,7 +235,7 @@ }

function mergeMessageMember(newMessageMember, repoMessageMember, messages, key) {
let changedType = !compareType(newMessageMember.type, repoMessageMember.type, messages, key);
let docsChanged = !compareAttribute(newMessageMember.doc, repoMessageMember.doc, messages, key, 'doc');
let optionalChanged = !compareAttribute(newMessageMember.optional, repoMessageMember.optional, messages, key, 'optional');
let changedType = !compareType(newMessageMember.type, repoMessageMember.type, messages, key)
let docsChanged = !compareAttribute(newMessageMember.doc, repoMessageMember.doc, messages, key, 'doc')
let optionalChanged = !compareAttribute(newMessageMember.optional, repoMessageMember.optional, messages, key, 'optional')
let changed = changedType || docsChanged || optionalChanged;
let changed = changedType || docsChanged || optionalChanged
let item = copy(repoMessageMember, {

@@ -242,5 +245,5 @@ type: newMessageMember.type,

optional: newMessageMember.optional
});
delete item.docs;
delete item.srcDocs;
})
delete item.docs
delete item.srcDocs
return {changed, item}

@@ -250,26 +253,26 @@ }

function mergeMessageMembers(newMembers, repoMembers, messages, sKey) {
let zipped = zipByKey(newMembers, repoMembers, _ => _.name);
let changed = false;
let merged = [];
let zipped = zipByKey(newMembers, repoMembers, _ => _.name)
let changed = false
let merged = []
zipped.forEach(_ => {
let newItem = _[0];
let repoItem = _[1];
let newItem = _[0]
let repoItem = _[1]
if (newItem && repoItem) {
let mergedItem = mergeMessageMember(newItem, repoItem, messages, `${sKey} member ${newItem.name}`);
changed = changed || mergedItem.changed;
merged.push(mergedItem.item);
let mergedItem = mergeMessageMember(newItem, repoItem, messages, `${sKey} member ${newItem.name}`)
changed = changed || mergedItem.changed
merged.push(mergedItem.item)
}
else if (newItem) {
let mergedItem = copy(newItem);
messages.push(`Service ${sKey} has a new member ${mergedItem.name}`);
changed = true;
merged.push(mergedItem);
let mergedItem = copy(newItem)
messages.push(`Service ${sKey} has a new member ${mergedItem.name}`)
changed = true
merged.push(mergedItem)
}
else {
let mergedItem;
mergedItem = copy(repoItem);
messages.push(`Service ${sKey} member ${mergedItem.name} was removed`);
changed = true;
let mergedItem
mergedItem = copy(repoItem)
messages.push(`Service ${sKey} member ${mergedItem.name} was removed`)
changed = true
}
});
})
return {changed, merged}

@@ -279,7 +282,7 @@ }

function mergeMessage(newMessage, repoMessage, messages, key, plugins) {
let membersMerge = mergeMessageMembers(newMessage.members, repoMessage.members, messages, key);
let docsMerge = compareDocs2(newMessage.docs, repoMessage.docs, messages, key, plugins);
let extraMerge = runPlugins(plugins, 'docworksMergeMessage', newMessage.extra || {}, repoMessage.extra || {}, messages, key);
let membersMerge = mergeMessageMembers(newMessage.members, repoMessage.members, messages, key)
let docsMerge = compareDocs2(newMessage.docs, repoMessage.docs, messages, key, plugins)
let extraMerge = runPlugins(plugins, 'docworksMergeMessage', newMessage.extra || {}, repoMessage.extra || {}, messages, key)
let changed = membersMerge.changed || docsMerge.changed || extraMerge.changed;
let changed = membersMerge.changed || docsMerge.changed || extraMerge.changed
let item = copy(repoMessage, {

@@ -291,4 +294,4 @@ labels: updateLabels(repoMessage.labels, changed),

extra: extraMerge.merged
});
delete item.srcDocs;
})
delete item.srcDocs
return {changed, item}

@@ -298,13 +301,13 @@ }

function mergeService(sNew, sRepo, messages, plugins) {
let sKey = serviceKey(sNew);
let mixesChanged = !compareArrays(sNew.mixes, sRepo.mixes, messages, sKey, 'mixes');
let docsMerge = compareDocs2(sNew.docs, sRepo.docs, messages, sKey, plugins);
let propertiesMerge = mergeLists(sNew.properties, sRepo.properties, messages, sKey, 'property', mergeProperty, plugins);
let operationsMerge = mergeLists(sNew.operations, sRepo.operations, messages, sKey, 'operation', mergeOperation, plugins);
let callbacksMerge = mergeLists(sNew.callbacks, sRepo.callbacks, messages, sKey, 'callback', mergeOperation, plugins);
let messagesMerge = mergeLists(sNew.messages, sRepo.messages, messages, sKey, 'message', mergeMessage, plugins);
let extraMerge = runPlugins(plugins, 'docworksMergeService', sNew.extra || {}, sRepo.extra || {}, messages, sKey);
let sKey = serviceKey(sNew)
let mixesChanged = !compareArrays(sNew.mixes, sRepo.mixes, messages, sKey, 'mixes')
let docsMerge = compareDocs2(sNew.docs, sRepo.docs, messages, sKey, plugins)
let propertiesMerge = mergeLists(sNew.properties, sRepo.properties, messages, sKey, 'property', mergeProperty, plugins)
let operationsMerge = mergeLists(sNew.operations, sRepo.operations, messages, sKey, 'operation', mergeOperation, plugins)
let callbacksMerge = mergeLists(sNew.callbacks, sRepo.callbacks, messages, sKey, 'callback', mergeOperation, plugins)
let messagesMerge = mergeLists(sNew.messages, sRepo.messages, messages, sKey, 'message', mergeMessage, plugins)
let extraMerge = runPlugins(plugins, 'docworksMergeService', sNew.extra || {}, sRepo.extra || {}, messages, sKey)
let changed = mixesChanged || docsMerge.changed || propertiesMerge.changed || operationsMerge.changed ||
callbacksMerge.changed || messagesMerge.changed || extraMerge.changed;
callbacksMerge.changed || messagesMerge.changed || extraMerge.changed
const service = copy(sRepo, {

@@ -320,32 +323,34 @@ labels: updateLabels(sRepo.labels, changed),

extra: extraMerge.merged
});
delete service.srcDocs;
return service;
})
delete service.srcDocs
return service
}
export default function merge(newRepo, repo, pluginModules) {
let zippedServices = zipByKey(newRepo, repo, serviceKey);
let messages = [];
let plugins = loadPlugins(pluginModules);
function merge(newRepo, repo, pluginModules) {
let zippedServices = zipByKey(newRepo, repo, serviceKey)
let messages = []
let plugins = loadPlugins(pluginModules)
let updatedRepo = zippedServices.map(_ => {
let sNew = _[0];
let sRepo = _[1];
let sNew = _[0]
let sRepo = _[1]
if (sNew && sRepo) {
return mergeService(sNew, sRepo, messages, plugins);
return mergeService(sNew, sRepo, messages, plugins)
}
else if (sNew) {
let newService = copy(sNew, {labels: addRemoveLabels(sNew.labels, 'new')});
messages.push(`Service ${serviceKey(newService)} is new`);
return newService;
let newService = copy(sNew, {labels: addRemoveLabels(sNew.labels, 'new')})
messages.push(`Service ${serviceKey(newService)} is new`)
return newService
}
else {
let removedService = copy(sRepo, {labels: addRemoveLabels(sRepo.labels, 'removed', 'new')});
if (!sRepo.labels.find(_ => _ === 'removed'))
messages.push(`Service ${serviceKey(removedService)} was removed`);
return removedService;
let removedService = copy(sRepo, {labels: addRemoveLabels(sRepo.labels, 'removed', 'new')})
if (!sRepo.labels.find(_ => _ === 'removed'))
messages.push(`Service ${serviceKey(removedService)} was removed`)
return removedService
}
});
})
return {repo: updatedRepo, messages}
}
}
module.exports = merge

@@ -1,115 +0,41 @@

import {join} from 'path';
import {toJson, fromJson} from 'docworks-json';
import fs from 'fs-extra';
import flatten from 'array-flatten';
const {join} = require('path')
const {toJson, fromJson} = require('docworks-json')
const flatten = require('array-flatten')
const {serviceSpec} = require('./serviceSpecModel')
const fs = require('fs-extra')
const serviceFileExtension = '.service.json';
const serviceFileExtension = '.service.json'
const docSpec = {
summary: {pos: 1},
description: {pos: 2, multiLine:true},
links: {pos: 3},
examples: {pos: 4,
title: {pos: 1},
body: {pos: 2, multiLine:true},
extra: {pos: 3}
},
extra: {pos: 5}
};
const locationSpec = {
filename: {pos: 1},
lineno: {pos: 2}
};
const propertySpec = {
name: {pos: 1},
labels: {pos: 2},
get: {pos: 3},
set: {pos: 4},
type: {pos: 5},
defaultValue: {pos: 6},
locations: Object.assign({pos: 7}, locationSpec),
docs: Object.assign({pos: 8}, docSpec),
srcDocs: Object.assign({pos: 9}, docSpec),
extra: {pos: 10}
};
const paramSpec = {
name: {pos: 1},
type: {pos: 2},
doc: {pos: 3},
srcDoc: {pos: 4},
optional: {pos: 5},
defaultValue: {pos: 6},
spread: {pos: 7}
};
const operationSpec = {
name: {pos: 1},
labels: {pos: 2},
nameParams: {pos: 3},
params: Object.assign({pos: 4}, paramSpec),
ret: {pos: 5, type: {pos: 1}, doc: {pos: 2}, srcDoc: {pos: 3}},
locations: Object.assign({pos: 6}, locationSpec),
docs: Object.assign({pos: 7}, docSpec),
srcDocs: Object.assign({pos: 8}, docSpec),
extra: {pos: 9}
};
const messageSpec = {
name: {pos: 1},
locations: Object.assign({pos: 2}, locationSpec),
docs: Object.assign({pos: 3}, docSpec),
srcDocs: Object.assign({pos: 4}, docSpec),
members: {pos: 5,
name: {pos: 1},
type: {pos: 2},
doc: {pos: 3},
optional: {pos: 4}
},
extra: {pos: 6}
};
const serviceSpec = {
name: {pos: 1},
memberOf: {pos: 2},
mixes: {pos: 3},
labels: {pos: 4},
location: Object.assign({pos: 5}, locationSpec),
docs: Object.assign({pos: 6}, docSpec),
srcDocs: Object.assign({pos: 7}, docSpec),
properties: Object.assign({pos: 8, orderBy:'name'}, propertySpec),
operations: Object.assign({pos: 9, orderBy:'name'}, operationSpec),
callbacks: Object.assign({pos: 10, orderBy:'name'}, operationSpec),
messages: Object.assign({pos: 11, orderBy:'name'}, messageSpec),
extra: {pos: 12}
};
export function serviceToRepoName(service) {
let memberOf = (service.memberOf || '').split('.');
return join(...memberOf, service.name + serviceFileExtension);
function serviceToRepoName(service) {
let memberOf = (service.memberOf || '').split('.')
return join(...memberOf, service.name + serviceFileExtension)
}
export function serviceToDirName(directory, service) {
let memberOf = (service.memberOf || '').split('.');
return join(directory, ...memberOf);
function serviceToDirName(directory, service) {
let memberOf = (service.memberOf || '').split('.')
return join(directory, ...memberOf)
}
export function serviceToJson(service) {
function serviceToJson(service) {
return toJson(service, 2, serviceSpec)
}
export function serviceFromJson(json) {
return fromJson(json, serviceSpec);
function serviceFromJson(json) {
return fromJson(json, serviceSpec)
}
export async function saveToDir(directory, services) {
async function saveToDir(directory, services) {
let filesAndServices = services.map(service => {
let dirName = serviceToDirName(directory, service);
let repoFileName = serviceToRepoName(service);
let fullFileName = join(directory, repoFileName);
let serviceJson = serviceToJson(service);
return {dirName, fullFileName, repoFileName, serviceJson};
});
let dirName = serviceToDirName(directory, service)
let repoFileName = serviceToRepoName(service)
let fullFileName = join(directory, repoFileName)
let serviceJson = serviceToJson(service)
return {dirName, fullFileName, repoFileName, serviceJson}
})
// ensure all directories are created before starting to save files - we do so one after the other
let dirNames = new Set(filesAndServices.map(_ => _.dirName));
let dirNames = new Set(filesAndServices.map(_ => _.dirName))
let dirsPromise = [...dirNames].reduce(function(cur, next) {
return cur.then(() => fs.ensureDir(next))
}, Promise.resolve());
}, Promise.resolve())

@@ -123,3 +49,3 @@ // now we can save files in parallel

))
});
})
}

@@ -129,18 +55,26 @@

// link - how to use async await https://stackoverflow.com/questions/33527653/babel-6-regeneratorruntime-is-not-defined-with-async-await
export async function readDir(dir) {
async function readDir(dir) {
if (! await fs.pathExists(dir))
return [];
let files = await fs.readdir(dir);
return []
let files = await fs.readdir(dir)
let readFiles = await Promise.all(files.map(async (file) => {
let stat = await fs.stat(join(dir, file));
let stat = await fs.stat(join(dir, file))
if (stat.isDirectory())
return await readDir(join(dir, file));
return await readDir(join(dir, file))
else if (file.endsWith(serviceFileExtension)){
let fileContent = await fs.readFile(join(dir, file), 'utf8');
return serviceFromJson(fileContent);
let fileContent = await fs.readFile(join(dir, file), 'utf8')
return serviceFromJson(fileContent)
}
else return [];
}));
return flatten(readFiles);
else return []
}))
return flatten(readFiles)
}
module.exports = {
serviceToRepoName,
serviceToDirName,
serviceToJson,
serviceFromJson,
saveToDir,
readDir
}

@@ -1,3 +0,3 @@

import path from 'path';
import fs from 'fs';
const path = require('path')
const fs = require('fs')

@@ -7,3 +7,3 @@ function getResourcePath(dirname) {

.map(basePath => path.resolve(basePath, dirname))
.find(dirPath => fs.existsSync(dirPath));
.find(dirPath => fs.existsSync(dirPath))

@@ -19,8 +19,8 @@ // ['', process.cwd()].forEach(basePath => {

function resolvePluginPath(plugin) {
let basename = path.basename(plugin);
let dirname = path.dirname(plugin);
let pluginPath = getResourcePath(dirname);
let basename = path.basename(plugin)
let dirname = path.dirname(plugin)
let pluginPath = getResourcePath(dirname)
if (!pluginPath) {
throw new Error(`Unable to find the plugin ${plugin}`);
throw new Error(`Unable to find the plugin ${plugin}`)
}

@@ -31,3 +31,3 @@

export function loadPlugins(plugins) {
function loadPlugins(plugins) {
return (plugins || [])

@@ -38,20 +38,23 @@ .map(resolvePluginPath)

export function runPlugins(plugins, pluginFunction, newExtra, repoExtra, messages, sKey) {
let extra = Object.assign({}, newExtra);
let extraChanged = false;
let hasExtra = !!newExtra;
function runPlugins(plugins, pluginFunction, newExtra, repoExtra, messages, sKey) {
let extra = Object.assign({}, newExtra)
let extraChanged = false
if (plugins) {
plugins.filter(plugin => !!plugin[pluginFunction] && !!plugin.extendDocworksKey)
.forEach(plugin => {
let {changed, value} = plugin[pluginFunction](newExtra[plugin.extendDocworksKey], repoExtra[plugin.extendDocworksKey]);
let {changed, value} = plugin[pluginFunction](newExtra[plugin.extendDocworksKey], repoExtra[plugin.extendDocworksKey])
if (value) {
extra[plugin.extendDocworksKey] = value;
hasExtra = true;
extra[plugin.extendDocworksKey] = value
}
if (changed)
messages.push(`Service ${sKey} has changed extra.${plugin.extendDocworksKey}`);
extraChanged = extraChanged || changed;
messages.push(`Service ${sKey} has changed extra.${plugin.extendDocworksKey}`)
extraChanged = extraChanged || changed
})
}
return {changed: extraChanged, merged: extra};
}
return {changed: extraChanged, merged: extra}
}
module.exports = {
loadPlugins,
runPlugins
}
{
"name": "docworks-repo",
"version": "1.6.4",
"version": "1.8.4",
"description": "manage service files in a git repo",
"main": "dist/index.js",
"main": "lib/index.js",
"scripts": {
"build": "babel lib --out-dir dist",
"prepublish": "babel lib --out-dir dist",
"test": "mocha --compilers js:babel-core/register --require babel-polyfill ./test/**/*.spec.js"
"clean": "rm -rf ./dist",
"lint": "eslint lib test",
"build": "npm run lint",
"prepublish": "npm run build",
"test": "mocha test/**/*.spec.js --compilers js:babel-core/register --require babel-polyfill"
},

@@ -15,4 +17,4 @@ "author": "Yoav Abrahami",

"array-flatten": "^2.1.1",
"docworks-jsdoc2spec": "^1.6.4",
"docworks-json": "^1.6.4",
"docworks-jsdoc2spec": "^1.8.4",
"docworks-json": "^1.8.4",
"fs-extra": "^3.0.1",

@@ -23,2 +25,3 @@ "lodash.isequal": "^4.5.0"

"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-polyfill": "^6.23.0",

@@ -31,4 +34,6 @@ "babel-preset-es2015": "^6.24.1",

"chai-subset": "^1.5.0",
"eslint": "^6.0.1",
"mocha": "^3.3.0"
}
},
"gitHead": "af20090fc0d9b22e9b504b26e3b2f025ddb05af9"
}

@@ -1,7 +0,7 @@

import chai from 'chai';
import chaiSubset from 'chai-subset';
import {addRemoveLabels} from '../lib/collection-utils';
import chai from 'chai'
import chaiSubset from 'chai-subset'
import {addRemoveLabels} from '../lib/collection-utils'
chai.use(chaiSubset);
const expect = chai.expect;
chai.use(chaiSubset)
const expect = chai.expect

@@ -11,51 +11,51 @@ describe('utilities', function() {

it('should add label to array', function() {
let labels = [];
let labels = []
let newLabels = addRemoveLabels(labels, 'removed');
let newLabels = addRemoveLabels(labels, 'removed')
expect(newLabels).to.include.members(['removed']);
});
expect(newLabels).to.include.members(['removed'])
})
it('should add multiple labels to array', function() {
let labels = ['L3'];
let labels = ['L3']
let newLabels = addRemoveLabels(labels, ['L1', 'L2']);
let newLabels = addRemoveLabels(labels, ['L1', 'L2'])
expect(newLabels).to.include.members(['L1', 'L2', 'L3']);
});
expect(newLabels).to.include.members(['L1', 'L2', 'L3'])
})
it('should not add duplicate label to array', function() {
let labels = ['removed'];
let labels = ['removed']
let newLabels = addRemoveLabels(labels, 'removed');
let newLabels = addRemoveLabels(labels, 'removed')
expect(newLabels).to.deep.equal(['removed']);
});
expect(newLabels).to.deep.equal(['removed'])
})
it('should remove label from array', function() {
let labels = ['removed'];
let labels = ['removed']
let newLabels = addRemoveLabels(labels, undefined, 'removed');
let newLabels = addRemoveLabels(labels, undefined, 'removed')
expect(newLabels).to.deep.equal([]);
});
expect(newLabels).to.deep.equal([])
})
it('should remove multiple labels from array', function() {
let labels = ['L1', 'L2', 'L3'];
let labels = ['L1', 'L2', 'L3']
let newLabels = addRemoveLabels(labels, undefined, ['L1', 'L3']);
let newLabels = addRemoveLabels(labels, undefined, ['L1', 'L3'])
expect(newLabels).to.deep.equal(['L2']);
});
expect(newLabels).to.deep.equal(['L2'])
})
it('should add and remove multiple labels from array', function() {
let labels = ['L1', 'L2', 'L3'];
let labels = ['L1', 'L2', 'L3']
let newLabels = addRemoveLabels(labels, ['L4', 'L5'], ['L1', 'L3']);
let newLabels = addRemoveLabels(labels, ['L4', 'L5'], ['L1', 'L3'])
expect(newLabels).to.deep.equal(['L2', 'L4', 'L5']);
});
});
});
expect(newLabels).to.deep.equal(['L2', 'L4', 'L5'])
})
})
})

@@ -0,3 +1,3 @@

/* eslint-disable no-unused-vars,getter-return */
/**

@@ -43,3 +43,3 @@ * @class ServiceA

export default ServiceA;
export default ServiceA

@@ -0,3 +1,3 @@

/* eslint-disable no-unused-vars,getter-return */
/**

@@ -43,3 +43,3 @@ * @class ServiceB

export default ServiceB;
export default ServiceB

@@ -0,3 +1,3 @@

/* eslint-disable no-unused-vars,getter-return */
/**

@@ -42,3 +42,3 @@ * @class ServiceA

export default ServiceA;
export default ServiceA

@@ -0,3 +1,3 @@

/* eslint-disable no-unused-vars,getter-return */
/**

@@ -42,3 +42,3 @@ * @class ServiceB

export default ServiceB;
export default ServiceB

@@ -0,3 +1,3 @@

/* eslint-disable no-unused-vars,getter-return */
/**

@@ -51,2 +51,2 @@ * @class NoChange

export default Service;
export default Service

@@ -0,1 +1,3 @@

/* eslint-disable no-unused-vars */
/**

@@ -2,0 +4,0 @@ * @class ChangeServiceOperations1

@@ -0,1 +1,3 @@

/* eslint-disable getter-return */
/**

@@ -2,0 +4,0 @@ * @class ChangeServiceProperties1

@@ -0,3 +1,3 @@

/* eslint-disable no-unused-vars,getter-return */
/**

@@ -43,3 +43,3 @@ * @class ServiceA

export default ServiceA;
export default ServiceA

@@ -0,3 +1,3 @@

/* eslint-disable no-unused-vars,getter-return */
/**

@@ -42,3 +42,3 @@ * @class ServiceB

export default ServiceB;
export default ServiceB

@@ -0,3 +1,3 @@

/* eslint-disable no-unused-vars,getter-return */
/**

@@ -42,3 +42,3 @@ * @class ServiceA

export default ServiceA;
export default ServiceA

@@ -0,3 +1,3 @@

/* eslint-disable no-unused-vars,getter-return */
/**

@@ -42,3 +42,3 @@ * @class ServiceC

export default ServiceC;
export default ServiceC

@@ -0,3 +1,3 @@

/* eslint-disable no-unused-vars,getter-return */
/**

@@ -51,2 +51,2 @@ * @class NoChange

export default Service;
export default Service

@@ -0,1 +1,3 @@

/* eslint-disable no-unused-vars */
/**

@@ -2,0 +4,0 @@ * @class ChangeServiceOperations1

@@ -0,1 +1,3 @@

/* eslint-disable getter-return */
/**

@@ -2,0 +4,0 @@ * @class ChangeServiceProperties1

exports.extendDocworksKey = 'thePlugin';
exports.extendDocworksKey = 'thePlugin'

@@ -10,3 +10,3 @@ function mergeThePlugin(newValue, repoValue) {

changed: true
};
}
else

@@ -16,12 +16,12 @@ return {changed: false}

exports.docworksMergeService = mergeThePlugin;
exports.docworksMergeService = mergeThePlugin
exports.docworksMergeProperty = mergeThePlugin;
exports.docworksMergeProperty = mergeThePlugin
exports.docworksMergeOperation = mergeThePlugin;
exports.docworksMergeOperation = mergeThePlugin
exports.docworksMergeMessage = mergeThePlugin;
exports.docworksMergeMessage = mergeThePlugin
exports.docworksMergeDocs = mergeThePlugin;
exports.docworksMergeDocs = mergeThePlugin
exports.docworksMergeExample = mergeThePlugin;
exports.docworksMergeExample = mergeThePlugin

@@ -1,14 +0,13 @@

import chai from 'chai';
import chaiFiles from 'chai-files';
import chaiSubset from 'chai-subset';
import runJsDoc from 'docworks-jsdoc2spec';
import {saveToDir, readFromDir} from '../lib/index';
import fs from 'fs-extra';
import {dump} from './util';
import chai from 'chai'
import chaiFiles from 'chai-files'
import chaiSubset from 'chai-subset'
import runJsDoc from 'docworks-jsdoc2spec'
import {saveToDir, readFromDir} from '../lib/index'
import fs from 'fs-extra'
chai.use(chaiFiles);
chai.use(chaiSubset);
const expect = chai.expect;
const file = chaiFiles.file;
const dir = chaiFiles.dir;
chai.use(chaiFiles)
chai.use(chaiSubset)
const expect = chai.expect
const file = chaiFiles.file
const dir = chaiFiles.dir

@@ -18,37 +17,37 @@

beforeEach(() => {
return fs.remove('tmp');
});
return fs.remove('tmp')
})
it('should save all services to files', async function() {
let jsDocRes = runJsDoc({
"include": [
"test/sources/"
'include': [
'test/sources/'
],
"includePattern": ".+\\.(js)?$",
});
let files = await saveToDir('tmp', jsDocRes.services);
'includePattern': '.+\\.(js)?$',
})
let files = await saveToDir('tmp', jsDocRes.services)
expect(files).containSubset(['aNamespace.service.json', 'aNamespace/aMixes.service.json', 'aNamespace/child.service.json']);
expect(files).containSubset(['aNamespace.service.json', 'aNamespace/aMixes.service.json', 'aNamespace/child.service.json'])
expect(dir('tmp/aNamespace')).to.exist;
expect(file('tmp/aNamespace.service.json')).to.exist;
expect(file('tmp/aNamespace/aMixes.service.json')).to.exist;
expect(file('tmp/aNamespace/child.service.json')).to.exist;
expect(file('tmp/aNamespace/Service.service.json')).to.exist;
expect(file('tmp/aNamespace/ServiceCallbacks.service.json')).to.exist;
expect(file('tmp/aNamespace/ServiceDocs.service.json')).to.exist;
expect(file('tmp/aNamespace/ServiceMessages.service.json')).to.exist;
expect(file('tmp/aNamespace/ServiceOperations.service.json')).to.exist;
expect(file('tmp/aNamespace/ServiceProperties.service.json')).to.exist;
expect(file('tmp/aNamespace/ServiceTypes.service.json')).to.exist;
expect(dir('tmp/aNamespace')).to.exist
expect(file('tmp/aNamespace.service.json')).to.exist
expect(file('tmp/aNamespace/aMixes.service.json')).to.exist
expect(file('tmp/aNamespace/child.service.json')).to.exist
expect(file('tmp/aNamespace/Service.service.json')).to.exist
expect(file('tmp/aNamespace/ServiceCallbacks.service.json')).to.exist
expect(file('tmp/aNamespace/ServiceDocs.service.json')).to.exist
expect(file('tmp/aNamespace/ServiceMessages.service.json')).to.exist
expect(file('tmp/aNamespace/ServiceOperations.service.json')).to.exist
expect(file('tmp/aNamespace/ServiceProperties.service.json')).to.exist
expect(file('tmp/aNamespace/ServiceTypes.service.json')).to.exist
});
})
it('should read all services from files', function() {
let jsDocRes = runJsDoc({
"include": [
"test/sources/mixin-sanity.js"
'include': [
'test/sources/mixin-sanity.js'
],
"includePattern": ".+\\.(js)?$",
});
'includePattern': '.+\\.(js)?$',
})
return saveToDir('tmp', jsDocRes.services)

@@ -59,12 +58,12 @@ .then(() => readFromDir('./tmp'))

let ser2 = readModel.services
.find((ser2) => ser2.name === ser1.name);
expect(ser1).to.containSubset(ser2);
});
});
});
.find((ser2) => ser2.name === ser1.name)
expect(ser1).to.containSubset(ser2)
})
})
})
it('should return empty result if folder does not exist', async function() {
let res = await readFromDir('./non-existing');
expect(res.services).to.deep.equal([]);
let res = await readFromDir('./non-existing')
expect(res.services).to.deep.equal([])
})
});
})

@@ -0,3 +1,3 @@

/* eslint-disable no-unused-vars */
/**

@@ -4,0 +4,0 @@ * @mixin aMixin

@@ -0,3 +1,3 @@

/* eslint-disable no-unused-vars */
/**

@@ -41,4 +41,4 @@ * @namespace aNamespace

}
};
}
export default namespace;
export default namespace

@@ -0,3 +1,3 @@

/* eslint-disable no-unused-vars */
/**

@@ -96,2 +96,2 @@ * @class ServiceCallbacks

export default ServiceCallbacks;
export default ServiceCallbacks

@@ -0,3 +1,3 @@

/* eslint-disable no-unused-vars,getter-return */
/**

@@ -83,2 +83,2 @@ * @class ServiceDocs

export default ServiceDocs;
export default ServiceDocs

@@ -0,3 +1,3 @@

/* eslint-disable no-unused-vars,getter-return,no-dupe-class-members */
/**

@@ -62,2 +62,2 @@ * @class ServiceMessages

export default ServiceMessages;
export default ServiceMessages

@@ -0,3 +1,3 @@

/* eslint-disable no-unused-vars */
/**

@@ -144,2 +144,2 @@ * @class ServiceOperations

export default ServiceOperations;
export default ServiceOperations

@@ -0,3 +1,3 @@

/* eslint-disable getter-return */
/**

@@ -89,2 +89,2 @@ * @class ServiceProperties

export default ServiceProperties;
export default ServiceProperties

@@ -0,3 +1,3 @@

/* eslint-disable no-unused-vars,getter-return */
/**

@@ -47,2 +47,2 @@ * @class Service

export default Service;
export default Service

@@ -0,3 +1,3 @@

/* eslint-disable getter-return */
/**

@@ -108,2 +108,2 @@ * @class ServiceTypes

export default ServiceTypes;
export default ServiceTypes

@@ -1,7 +0,8 @@

import {inspect} from 'util';
import {inspect} from 'util'
export function dump() {
let args = Array.prototype.slice.call(arguments);
let args = Array.prototype.slice.call(arguments)
// eslint-disable-next-line no-console
console.log(...args.map(arg => {
return inspect(arg, {colors: true, depth: 5})
}));
}
}))
}

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc