Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subfolder anywhere #83

Merged
merged 9 commits into from
Jan 13, 2021
4 changes: 4 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ _(Write your answer here.)_

---

<!--
$ uname -v ; yarn -v ; node -v ; sgd --version ; git --version
-->

**Operating System:** …

**Yarn version:** …
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ jobs:

- name: 'Code Climate coverage publishing'
run: ./cc-test-reporter after-build -t lcov -r ${{ secrets.CC_TEST_REPORTER_ID }}
continue-on-error: true
9 changes: 9 additions & 0 deletions __tests__/unit/lib/service/customObjectHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const testContext = {
'force-app/main/default/objects/Account/Account.object-meta.xml',
new Set(['Account']),
],
[
'objects',
'force-app/main/default/objects/Test/Account/Account.object-meta.xml',
new Set(['Account']),
],
[
'territory2Models',
'force-app/main/default/territory2Models/EU/EU.territory2Model-meta.xml',
Expand All @@ -30,6 +35,10 @@ describe('test CustomObjectHandler', () => {
'force-app/main/default/objects/Account/Account.object-meta.xml': 'test',
'force-app/main/default/objects/Account/fields/test__c.field-meta.xml':
SubCustomObjectHandler.MASTER_DETAIL_TAG,
'force-app/main/default/objects/Test/Account/Account.object-meta.xml':
'test',
'force-app/main/default/objects/Test/Account/fields/test__c.field-meta.xml':
SubCustomObjectHandler.MASTER_DETAIL_TAG,
})
})

Expand Down
16 changes: 16 additions & 0 deletions __tests__/unit/lib/service/inFileHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const testContext = {
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>${os.EOL}<Workflow xmlns="http://soap.sforce.com/2006/04/metadata">${os.EOL}<alerts>${os.EOL}<fullName>TestEA</fullName>${os.EOL}</alerts>${os.EOL}<fieldUpdates>${os.EOL}<fullName>TestFU</fullName>${os.EOL}</fieldUpdates>${os.EOL}<rules>${os.EOL}<fullName>TestRule</fullName>${os.EOL}</rules>${os.EOL}${os.EOL}</Workflow>`,
'{"Workflow":{"$":{"xmlns":"http://soap.sforce.com/2006/04/metadata"},"alerts":[{"fullName":["TestEA"]}],"fieldUpdates":[{"fullName":["TestFU"]}],"rules":[{"fullName":["TestRule"]}]}}',
],
[
'workflows',
'force-app/main/default/workflows/Test/Account.workflow-meta.xml',
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>${os.EOL}<Workflow xmlns="http://soap.sforce.com/2006/04/metadata">${os.EOL}<alerts>${os.EOL}<fullName>TestEA</fullName>${os.EOL}</alerts>${os.EOL}<fieldUpdates>${os.EOL}<fullName>TestFU</fullName>${os.EOL}</fieldUpdates>${os.EOL}<rules>${os.EOL}<fullName>TestRule</fullName>${os.EOL}</rules>${os.EOL}${os.EOL}</Workflow>`,
'{"Workflow":{"$":{"xmlns":"http://soap.sforce.com/2006/04/metadata"},"alerts":[{"fullName":["TestEA"]}],"fieldUpdates":[{"fullName":["TestFU"]}],"rules":[{"fullName":["TestRule"]}]}}',
],
[
'labels',
'force-app/main/default/labels/CustomLabels.labels-meta.xml',
Expand All @@ -33,6 +39,12 @@ const testContext = {
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>${os.EOL}<SharingRules xmlns="http://soap.sforce.com/2006/04/metadata">${os.EOL}<sharingCriteriaRules>${os.EOL}<fullName>TestCBS</fullName>${os.EOL}</sharingCriteriaRules>${os.EOL}<sharingOwnerRules>${os.EOL}<fullName>TestOBS</fullName>${os.EOL}</sharingOwnerRules>${os.EOL}</SharingRules>`,
'{"SharingRules":{"$":{"xmlns":"http://soap.sforce.com/2006/04/metadata"},"sharingCriteriaRules":[{"fullName":["TestCBS"]}],"sharingOwnerRules":[{"fullName":["TestOBS"]}]}}',
],
[
'sharingRules',
'force-app/main/default/sharingRules/Test/Account.sharingRules-meta.xml',
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>${os.EOL}<SharingRules xmlns="http://soap.sforce.com/2006/04/metadata">${os.EOL}<sharingCriteriaRules>${os.EOL}<fullName>TestCBS</fullName>${os.EOL}</sharingCriteriaRules>${os.EOL}<sharingOwnerRules>${os.EOL}<fullName>TestOBS</fullName>${os.EOL}</sharingOwnerRules>${os.EOL}</SharingRules>`,
'{"SharingRules":{"$":{"xmlns":"http://soap.sforce.com/2006/04/metadata"},"sharingCriteriaRules":[{"fullName":["TestCBS"]}],"sharingOwnerRules":[{"fullName":["TestOBS"]}]}}',
],
],
expectedData: {
workflows: { 'workflows.alerts': new Set(['Account.TestEA']) },
Expand All @@ -51,12 +63,16 @@ fsMocked.__setMockFiles({
[testContext.testData[0][1]]: testContext.testData[0][2],
[testContext.testData[1][1]]: testContext.testData[1][2],
[testContext.testData[2][1]]: testContext.testData[2][2],
[testContext.testData[3][1]]: testContext.testData[3][2],
[testContext.testData[4][1]]: testContext.testData[4][2],
})

xml2jsMocked.__setMockContent({
[testContext.testData[0][2]]: testContext.testData[0][3],
[testContext.testData[1][2]]: testContext.testData[1][3],
[testContext.testData[2][2]]: testContext.testData[2][3],
[testContext.testData[3][2]]: testContext.testData[3][3],
[testContext.testData[4][2]]: testContext.testData[4][3],
})

// eslint-disable-next-line no-undef
Expand Down
10 changes: 10 additions & 0 deletions __tests__/unit/lib/service/inResourceHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ const testContext = {
'force-app/main/default/waveTemplates/WaveTemplateTest/template-info.json',
new Set(['WaveTemplateTest']),
],
[
'lwc',
'force-app/main/default/lwc/component/component.js-meta.xml',
new Set(['component']),
],
[
'aura',
'force-app/main/default/aura/component/component.cmp-meta.xml',
new Set(['component']),
],
],
work: {
config: { output: '', repo: '', generateDelta: true },
Expand Down
6 changes: 2 additions & 4 deletions __tests__/unit/lib/service/inTranslationHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ const testContext = {
describe('test inTranslation with delta generation', () => {
beforeAll(() => {
require('fs').__setMockFiles({
'force-app/main/default/objectTranslations/Account-es/Account-es.objectTranslation-meta.xml':
'test',
'force-app/main/default/objectTranslations/Account-es/BillingFloor__c.fieldTranslation-meta.xml':
'test',
[testContext.testData[0][1]]: 'test',
[testContext.testData[1][1]]: 'test',
})
})

Expand Down
26 changes: 0 additions & 26 deletions __tests__/unit/lib/service/lightningHandler.test.js

This file was deleted.

35 changes: 35 additions & 0 deletions __tests__/unit/lib/service/standardHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,41 @@ const testContext = {
'force-app/main/default/objects/Account/weblinks/ClientStore.weblink-meta.xml',
new Set(['ClientStore']),
],
[
'classes',
'force-app/main/default/classes/controllers/Controller.cls-meta.xml',
new Set(['Controller']),
],
[
'objects',
'force-app/main/default/objects/Test/Account/Account.object-meta.xml',
new Set(['Account']),
],
[
'quickActions',
'force-app/main/default/quickActions/Test/Account.New.quickAction-meta.xml',
new Set(['Account.New']),
],
[
'quickActions',
'force-app/main/default/quickActions/Test/NewGlobal.quickAction-meta.xml',
new Set(['NewGlobal']),
],
[
'customMetadata',
'force-app/main/default/customMetadata/Test/GraphicsPackImages.md_png.md-meta.xml',
new Set(['GraphicsPackImages.md_png']),
],
[
'weblinks',
'force-app/main/default/objects/Test/Account/weblinks/ClientStore.weblink-meta.xml',
new Set(['ClientStore']),
],
[
'classes',
'force-app/main/default/classes/Test/Controller.cls-meta.xml',
new Set(['Controller']),
],
],
work: {
config: { output: '', repo: '', generateDelta: true },
Expand Down
15 changes: 15 additions & 0 deletions __tests__/unit/lib/service/subCustomObjectHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ const testContext = {
'force-app/main/default/territory2Models/EU/territories/France.territory2-meta.xml',
new Set(['EU.France']),
],
[
'fields',
'force-app/main/default/objects/Test/Account/fields/awesome.field-meta.xml',
new Set(['Account.awesome']),
],
[
'rules',
'force-app/main/default/territory2Models/Test/EU/rules/Location.territory2Rule-meta.xml',
new Set(['EU.Location']),
],
[
'territories',
'force-app/main/default/territory2Models/Test/EU/territories/France.territory2-meta.xml',
new Set(['EU.France']),
],
],
work: {
config: { output: '', repo: '', generateDelta: true },
Expand Down
28 changes: 0 additions & 28 deletions __tests__/unit/lib/service/subFolderElementHandler.test.js

This file was deleted.

4 changes: 1 addition & 3 deletions __tests__/unit/lib/service/typeHandlerFactory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const SubCustomObject = require('../../../../src/service/subCustomObjectHandler')
const InResource = require('../../../../src/service/inResourceHandler')
const Lightning = require('../../../../src/service/lightningHandler')
const InFolder = require('../../../../src/service/inFolderHandler')
const Standard = require('../../../../src/service/standardHandler')
const TypeHandlerFactory = require('../../../../src/service/typeHandlerFactory')
Expand All @@ -20,7 +19,6 @@ describe('the type handler factory', () => {
)
})
describe.each([
[Lightning, ['aura', 'lwc']],
[
SubCustomObject,
[
Expand All @@ -36,7 +34,7 @@ describe('the type handler factory', () => {
],
],
[InFolder, ['dashboards', 'documents', 'reports']],
[InResource, ['staticresources']],
[InResource, ['staticresources', 'aura', 'lwc']],
[Standard, ['objects']],
])('give %p handler', (handler, types) => {
test.each(types)('for %s folder', type => {
Expand Down
42 changes: 42 additions & 0 deletions __tests__/unit/lib/service/waveHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,48 @@ const testContext = {
new Set(['WaveXmdTest']),
'WaveXmd',
],
[
'wave',
'force-app/main/default/wave/Test/WaveApplicationTest.wapp',
new Set(['WaveApplicationTest']),
'WaveApplication',
],
[
'wave',
'force-app/main/default/wave/Test/WaveDataflowTest.wdf',
new Set(['WaveDataflowTest']),
'WaveDataflow',
],
[
'wave',
'force-app/main/default/wave/Test/WaveDashboardTest.wdash',
new Set(['WaveDashboardTest']),
'WaveDashboard',
],
[
'wave',
'force-app/main/default/wave/Test/WaveDatasetTest.wds',
new Set(['WaveDatasetTest']),
'WaveDataset',
],
[
'wave',
'force-app/main/default/wave/Test/WaveLensTest.wlens',
new Set(['WaveLensTest']),
'WaveLens',
],
[
'wave',
'force-app/main/default/wave/Test/WaveRecipeTest.wdpr',
new Set(['WaveRecipeTest']),
'WaveRecipe',
],
[
'wave',
'force-app/main/default/wave/Test/WaveXmdTest.xmd',
new Set(['WaveXmdTest']),
'WaveXmd',
],
],
work: {
config: { output: '', repo: '', generateDelta: true },
Expand Down
38 changes: 20 additions & 18 deletions src/service/customObjectHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,29 @@ class CustomObjectHandler extends StandardHandler {
handleAddition() {
super.handleAddition()
if (!this.config.generateDelta || this.type !== OBJECT_TYPE) return
const fieldsFolder = path.join(
path.parse(this.line).dir,
mc.FIELD_DIRECTORY_NAME
const fieldsFolder = path.resolve(
this.config.repo,
path.join(path.parse(this.line).dir, mc.FIELD_DIRECTORY_NAME)
)
fs.readdirSync(path.resolve(this.config.repo, fieldsFolder))
.filter(fieldPath =>
fs
.readFileSync(
path.resolve(this.config.repo, fieldsFolder, fieldPath),
{
encoding: gc.UTF8_ENCODING,
}
if (fs.existsSync(fieldsFolder)) {
fs.readdirSync(fieldsFolder)
.filter(fieldPath =>
fs
.readFileSync(
path.resolve(this.config.repo, fieldsFolder, fieldPath),
{
encoding: gc.UTF8_ENCODING,
}
)
.includes(mc.MASTER_DETAIL_TAG)
)
.forEach(field =>
this._copyFiles(
path.resolve(this.config.repo, fieldsFolder, field),
path.resolve(this.config.output, fieldsFolder, field)
)
.includes(mc.MASTER_DETAIL_TAG)
)
.forEach(field =>
this._copyFiles(
path.resolve(this.config.repo, fieldsFolder, field),
path.resolve(this.config.output, fieldsFolder, field)
)
)
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/service/inResourceHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const StandardHandler = require('./standardHandler')
const path = require('path')
const fs = require('fs')
const mc = require('../utils/metadataConstants')

const elementSrc = {}

Expand Down Expand Up @@ -54,7 +55,15 @@ class ResourceHandler extends StandardHandler {

_getElementName() {
const parsedPath = this._getParsedPath()
return parsedPath.dir + parsedPath.name
return parsedPath.name
}

_getParsedPath() {
return path.parse(
this.splittedLine[this.splittedLine.indexOf(this.type) + 1]
.replace(mc.META_REGEX, '')
.replace(this.suffixRegex, '')
)
}
}

Expand Down
19 changes: 0 additions & 19 deletions src/service/lightningHandler.js

This file was deleted.

Loading