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

fix: document file copy when metafile is modified #276

Merged
merged 7 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions __tests__/unit/lib/service/inFolderHandler.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict'
const InFolder = require('../../../../src/service/inFolderHandler')
const metadataManager = require('../../../../src/metadata/metadataManager')
const fs = require('fs')
const fse = require('fs-extra')
jest.mock('fs')

// eslint-disable-next-line no-undef
Expand Down Expand Up @@ -54,3 +57,36 @@ testHandlerHelper({
warnings: [],
},
})

describe('InFolderHander', () => {
let globalMetadata
let work
beforeAll(async () => {
globalMetadata = await metadataManager.getDefinition('directoryName', 50)
work = {
config: { output: '', repo: '.', generateDelta: true },
diffs: { package: new Map(), destructiveChanges: new Map() },
warnings: [],
}
})
test('copy special extension', async () => {
fs.__setMockFiles({
'force-app/main/default/documents/folder/test.document-meta.xml':
'content',
'force-app/main/default/documents/folder/test.png-meta.xml': 'content',
})

const handler = new InFolder(
`M force-app/main/default/documents/folder/test.document-meta.xml`,
'documents',
work,
globalMetadata
)
await handler.handle()

expect(work.diffs.package.get('documents')).toEqual(
new Set(['folder/test'])
)
expect(fse.copy).toHaveBeenCalled()
})
})
1 change: 1 addition & 0 deletions src/service/inFileHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const XML_HEADER_TAG_END = '?>'
const XML_PARSER_OPTION = {
ignoreAttributes: false,
ignoreNameSpace: false,
parseTagValue: false,
parseNodeValue: false,
parseAttributeValue: false,
trimValues: true,
Expand Down
27 changes: 24 additions & 3 deletions src/service/inFolderHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,50 @@ const {
META_REGEX,
METAFILE_SUFFIX,
} = require('../utils/metadataConstants')
const { join, normalize, sep } = require('path')
const { join, normalize, parse, sep } = require('path')
const { readdir } = require('fs').promises

const INFOLDER_SUFFIX_REGEX = new RegExp(`${INFOLDER_SUFFIX}$`)
const EXTENSION_SUFFIX_REGEX = new RegExp(/\.[^/.]+$/)
class InFolderHandler extends StandardHandler {
async handleAddition() {
await super.handleAddition()
if (!this.config.generateDelta) return
await this._copyFolderMetaFile()
await this._copySpecialExtension()
}

async _copyFolderMetaFile() {
const [, , folderPath, folderName] = this._parseLine()

const folderFileName = `${folderName}.${
StandardHandler.metadata.get(this.type).xmlName.toLowerCase() +
StandardHandler.metadata.get(this.type).suffix.toLowerCase() +
INFOLDER_SUFFIX +
METAFILE_SUFFIX
}`

this._copyFiles(
await this._copyFiles(
normalize(join(this.config.repo, folderPath, folderFileName)),
normalize(join(this.config.output, folderPath, folderFileName))
)
}

async _copySpecialExtension() {
const parsedLine = parse(this.line)
const dirContent = await readdir(parsedLine.dir)

await Promise.all(
dirContent
.filter(file => file.includes(parsedLine.name))
.map(file =>
this._copyFiles(
normalize(join(this.config.repo, parsedLine.dir, file)),
normalize(join(this.config.output, parsedLine.dir, file))
)
)
)
}

_fillPackage(packageObject) {
if (!packageObject.has(this.type)) {
packageObject.set(this.type, new Set())
Expand Down
4 changes: 1 addition & 3 deletions src/service/standardHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,10 @@ class StandardHandler {
async _copyWithMetaFile(src, dst) {
const file = this._copyFiles(src, dst)
if (StandardHandler.metadata.get(this.type).metaFile === true) {
const metaFile = this._copyFiles(
await this._copyFiles(
this._getMetaTypeFilePath(src),
this._getMetaTypeFilePath(dst)
)
await this._copyFiles(src + METAFILE_SUFFIX, dst + METAFILE_SUFFIX)
await metaFile
}
await file
}
Expand Down
2 changes: 1 addition & 1 deletion src/service/subCustomObjectHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SubCustomObjectHandler extends StandardHandler {
`${customObjectName}.${OBJECT_META_XML_SUFFIX}`
)

this._copyFiles(
await this._copyFiles(
join(this.config.repo, customObjectPath),
join(this.config.output, customObjectPath)
)
Expand Down
70 changes: 35 additions & 35 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -833,9 +833,9 @@
tslib "^2.3.1"

"@oclif/core@^1.3.1", "@oclif/core@^1.3.6", "@oclif/core@^1.5.1", "@oclif/core@^1.5.2":
version "1.6.1"
resolved "https://registry.yarnpkg.com/@oclif/core/-/core-1.6.1.tgz#8300132782fd5845e3f08026f2fbd95917e8c2dd"
integrity sha512-qB33YT3JUc7oH3Mtoov8yRETdMiQKsQNdoB2ozRq8JOCxtqI2f0XiQ6eqes3GpeMZKucl4mmonws5LYraLdQlg==
version "1.6.3"
resolved "https://registry.yarnpkg.com/@oclif/core/-/core-1.6.3.tgz#3d1dd4e033f5512ac35963a73878257142390838"
integrity sha512-a3DrPNlOYemwnzxuJ3tINjqpMVIYe56Mg+XaQo0nGsqGSk69wF5Q/hD8plsWrtwdkeIxwxhgl7T699EJypAUwg==
dependencies:
"@oclif/linewrap" "^1.0.0"
"@oclif/screen" "^3.0.2"
Expand Down Expand Up @@ -1024,16 +1024,16 @@
chalk "^2.4.2"

"@salesforce/core@^2.28.1":
version "2.35.3"
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-2.35.3.tgz#acda80e6a329a40f257033c99ed353168253b0db"
integrity sha512-F/Up8QQf7H8iKxQpGa4EZpViuNUzS+MSKaifbs+nBHs3ni0XZ2NMxB5Ai+C1vsbNNEeB1NoTPcOw/cpTm7WRRA==
version "2.36.0"
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-2.36.0.tgz#eadade3d663f0a2e11d0cc9f9097c528c182997d"
integrity sha512-VsKt7SXArxrOelaJl5Ez21Pmtdp2eU6qimqZ5clxnNaZDZKOySDPYnKHu7AYCt1LUNFN9cfsX8K5yOHxS+wT+w==
dependencies:
"@salesforce/bunyan" "^2.0.0"
"@salesforce/kit" "^1.5.17"
"@salesforce/schemas" "^1.0.1"
"@salesforce/ts-types" "^1.5.20"
"@types/graceful-fs" "^4.1.5"
"@types/jsforce" "^1.9.38"
"@types/jsforce" "^1.9.41"
"@types/mkdirp" "^1.0.1"
archiver "^5.3.0"
debug "^3.1.0"
Expand All @@ -1048,9 +1048,9 @@
ts-retry-promise "^0.6.0"

"@salesforce/core@^3.7.9":
version "3.9.0"
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.9.0.tgz#30e1e3ef405a1d1fe1ef012cf18a4262d338d88e"
integrity sha512-NwCzwp/plSwU89fpvC2WxQR39uGv2dkErYr5k/U0FBePp1djQ1PAW61O8zjAa+hh8nIES0tOTUFzLiyYHp4BWg==
version "3.10.0"
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.10.0.tgz#8fa07d41e4d953ce501f52af43ee1e67f2f3ef05"
integrity sha512-LXgb/SqdPeSm7RqSGtqHDUKo9B2kXr/bckNS6VFH2502DHnDFdi+WV2sIq/D7YYSoJGrS+RpgkNH0f5gNx35sQ==
dependencies:
"@oclif/core" "^1.5.1"
"@salesforce/bunyan" "^2.0.0"
Expand Down Expand Up @@ -1220,7 +1220,7 @@
dependencies:
"@types/istanbul-lib-report" "*"

"@types/jsforce@^1.9.38":
"@types/jsforce@^1.9.41":
version "1.9.41"
resolved "https://registry.yarnpkg.com/@types/jsforce/-/jsforce-1.9.41.tgz#08b31a0d04e14fd5f8a232196e16bc742e22bbed"
integrity sha512-J0dReK6EPGR98b4fAowqqQqFXH4DGtPxY2lLrZGcuCthrHYkYNrKnfGf2xM1jwiBC5CGdSEDmWEDwRwwmX25tA==
Expand Down Expand Up @@ -1265,9 +1265,9 @@
integrity sha512-QCWHkbMv4Y5U9oW10Uxbr45qMMSzl4OzijsozynUAgx3kEHUdXB00udx2dWDQ7f2TU2a2uuiFaRZjCe3unPpeg==

"@types/node@*", "@types/node@>=12", "@types/node@^17.0.0":
version "17.0.22"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.22.tgz#38b6c4b9b2f3ed9f2e376cce42a298fb2375251e"
integrity sha512-8FwbVoG4fy+ykY86XCAclKZDORttqE5/s7dyWZKLXTdv3vRy5HozBEinG5IqhvPXXzIZEcTVbuHlQEI6iuwcmw==
version "17.0.23"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.23.tgz#3b41a6e643589ac6442bdbd7a4a3ded62f33f7da"
integrity sha512-UxDxWn7dl97rKVeVS61vErvw086aCYhDLyvRQZ5Rk65rZKepaFdm53GeqXaKBuOhED4e9uWq34IC3TdSdJJ2Gw==

"@types/node@^12.19.9":
version "12.20.47"
Expand Down Expand Up @@ -1302,9 +1302,9 @@
"@types/sinonjs__fake-timers" "*"

"@types/sinonjs__fake-timers@*":
version "8.1.1"
resolved "https://registry.yarnpkg.com/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.1.tgz#b49c2c70150141a15e0fa7e79cf1f92a72934ce3"
integrity sha512-0kSuKjAS0TrGLJ0M/+8MaFkGsQhZpB6pxOmvS3K8FYI72K//YmdfoW9X2qPsAKh1mkwxGD5zib9s1FIFed6E8g==
version "8.1.2"
resolved "https://registry.yarnpkg.com/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.2.tgz#bf2e02a3dbd4aecaf95942ecd99b7402e03fad5e"
integrity sha512-9GcLXF0/v3t80caGs5p2rRfkB+a8VBGLJZVih6CNFkx8IZ994wiKKLSRs9nuFwk1HevWs/1mnUmkApGrSGsShA==

"@types/stack-utils@^2.0.0":
version "2.0.1"
Expand Down Expand Up @@ -1535,9 +1535,9 @@ ajv@^6.10.0, ajv@^6.12.3, ajv@^6.12.4, ajv@^6.12.6:
uri-js "^4.2.2"

ajv@^8.0.1:
version "8.10.0"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.10.0.tgz#e573f719bd3af069017e3b66538ab968d040e54d"
integrity sha512-bzqAEZOjkrUMl2afH8dknrq5KEk2SrwdBROR+vH1EKVQTqaUbJVPdc/gEdggTMM0Se+s+Ja4ju4TlNcStKl2Hw==
version "8.11.0"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.11.0.tgz#977e91dd96ca669f54a11e23e378e33b884a565f"
integrity sha512-wGgprdCvMalC0BztXvitD2hC04YffAvtsUn93JbGXYLAtCUO4xd17mCCZQxUOItiBwZvJScWo8NIvQMQ71rdpg==
dependencies:
fast-deep-equal "^3.1.1"
json-schema-traverse "^1.0.0"
Expand Down Expand Up @@ -3033,9 +3033,9 @@ ejs@^3.1.6:
jake "^10.6.1"

electron-to-chromium@^1.4.84:
version "1.4.89"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.89.tgz#33c06592812a17a7131873f4596579084ce33ff8"
integrity sha512-z1Axg0Fu54fse8wN4fd+GAINdU5mJmLtcl6bqIcYyzNVGONcfHAeeJi88KYMQVKalhXlYuVPzKkFIU5VD0raUw==
version "1.4.91"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.91.tgz#842bbc97fd639abe7e46e7da530e3af5f6ca2831"
integrity sha512-Z7Jkc4+ouEg8F6RrrgLOs0kkJjI0cnyFQmnGVpln8pPifuKBNbUr37GMgJsCTSwy6Z9TK7oTwW33Oe+3aERYew==

emittery@^0.8.1:
version "0.8.1"
Expand Down Expand Up @@ -5857,10 +5857,10 @@ minimist-options@^3.0.1:
arrify "^1.0.1"
is-plain-obj "^1.1.0"

minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5, minimist@^1.2.6:
version "1.2.6"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44"
integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==

mkdirp-classic@^0.5.2:
version "0.5.3"
Expand All @@ -5873,11 +5873,11 @@ [email protected]:
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==

mkdirp@~0.5.1:
version "0.5.5"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.5.tgz#d91cefd62d1436ca0f41620e251288d420099def"
integrity sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==
version "0.5.6"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.6.tgz#7def03d2432dcae4ba1d611445c48396062255f6"
integrity sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==
dependencies:
minimist "^1.2.5"
minimist "^1.2.6"

mock-stdin@^1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -7740,13 +7740,13 @@ ts-retry-promise@^0.6.0:
integrity sha512-6L9PAWahkRtZ4mG48wz3Mxk7LfW1eZKEPsCteIa5fbDE1G2kFk4ThHXbynKlIZLg0RdenDBDw6CLME5liOrBSQ==

tsconfig-paths@^3.12.0:
version "3.14.0"
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.14.0.tgz#4fcc48f9ccea8826c41b9ca093479de7f5018976"
integrity sha512-cg/1jAZoL57R39+wiw4u/SCC6Ic9Q5NqjBOb+9xISedOYurfog9ZNmKJSxAnb2m/5Bq4lE9lhUcau33Ml8DM0g==
version "3.14.1"
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.14.1.tgz#ba0734599e8ea36c862798e920bcf163277b137a"
integrity sha512-fxDhWnFSLt3VuTwtvJt5fpwxBHg5AdKWMsgcPOOIilyjymcYVZoCQF8fvFRezCNfblEXmi+PcM1eYHeOAgXCOQ==
dependencies:
"@types/json5" "^0.0.29"
json5 "^1.0.1"
minimist "^1.2.0"
minimist "^1.2.6"
strip-bom "^3.0.0"

tslib@^1.8.1, tslib@^1.9.0:
Expand Down