sfdx-git-delta
Advanced tools
Comparing version 1.1.0 to 2.0.0
'use strict' | ||
const fse = jest.genMockFromModule('fs-extra') | ||
// eslint-disable-next-line no-unused-vars | ||
fse.copy = (_src, _tgt) => new Promise(resolve => resolve()) | ||
fse.copy = () => new Promise(resolve => resolve()) | ||
module.exports = fse |
@@ -22,6 +22,17 @@ 'use strict' | ||
fs.readdirSync = directoryPath => mockFiles[directoryPath] || [] | ||
fs.readdirSync = directoryPath => { | ||
if (directoryPath.endsWith('metadata')) { | ||
return ['v46.json'] | ||
} | ||
return mockFiles[directoryPath] || [] | ||
} | ||
fs.existsSync = filePath => filePathList.has(filePath) | ||
fs.statSync = () => ({ | ||
isDirectory() { | ||
return true | ||
}, | ||
}) | ||
fs.writeFile = (_filePath, _content, _encoding, cb) => | ||
@@ -28,0 +39,0 @@ errorMode ? cb(new Error()) : cb(null) |
@@ -27,2 +27,7 @@ 'use strict' | ||
describe(`test if the appli`, () => { | ||
beforeAll(() => { | ||
require('fs').__setMockFiles({ | ||
output: '', | ||
}) | ||
}) | ||
test('can execute with rich parameters and big diff', async () => { | ||
@@ -32,6 +37,6 @@ mySpawn.setDefault(mySpawn.simple(0, lines.join(os.EOL))) | ||
app({ | ||
output: 'output/', | ||
output: 'output', | ||
repo: 'repo/path', | ||
to: 'test', | ||
apiVersion: '46.0', | ||
apiVersion: '46', | ||
}) | ||
@@ -38,0 +43,0 @@ ).resolves.toStrictEqual([]) |
@@ -11,6 +11,12 @@ 'use strict' | ||
describe(`test if the appli`, () => { | ||
beforeAll(() => { | ||
require('fs').__setMockFiles({ | ||
output: '', | ||
}) | ||
}) | ||
test('can execute with simple parameters and no diff', async () => { | ||
mySpawn.setDefault(mySpawn.simple(0, '')) | ||
await expect( | ||
app({ output: '', repo: '', to: 'test', apiVersion: '46.0' }) | ||
app({ output: 'output', repo: '', to: 'test', apiVersion: '46' }) | ||
).resolves.toStrictEqual([]) | ||
@@ -22,4 +28,4 @@ }) | ||
await expect( | ||
app({ output: '', repo: '', apiVersion: '46.0' }) | ||
).rejects.toStrictEqual(new Error(`Not enough parameter`)) | ||
app({ output: 'output', repo: '', apiVersion: '46' }) | ||
).rejects.toBeTruthy() | ||
}) | ||
@@ -35,3 +41,3 @@ | ||
await expect( | ||
app({ output: '', repo: '', to: 'test', apiVersion: '46.0' }) | ||
app({ output: 'output', repo: '', to: 'test', apiVersion: '46' }) | ||
).resolves.toStrictEqual([]) | ||
@@ -48,3 +54,3 @@ }) | ||
await expect( | ||
app({ output: '', repo: '', to: 'test', apiVersion: '46.0' }) | ||
app({ output: 'output', repo: '', to: 'test', apiVersion: '46' }) | ||
).resolves.toStrictEqual([]) | ||
@@ -61,5 +67,5 @@ }) | ||
await expect( | ||
app({ output: '', repo: '', to: 'test', apiVersion: '46.0' }) | ||
app({ output: 'output', repo: '', to: 'test', apiVersion: '46' }) | ||
).resolves.toStrictEqual([]) | ||
}) | ||
}) |
'use strict' | ||
const PackageConstructor = require('../../../lib/packageConstructor') | ||
const options = { apiVersion: '46.0' } | ||
const options = { apiVersion: '46' } | ||
const tests = [ | ||
@@ -15,3 +15,3 @@ [ | ||
</types> | ||
<version>${options.apiVersion}</version> | ||
<version>${options.apiVersion}.0</version> | ||
</Package>`, | ||
@@ -24,3 +24,3 @@ ], | ||
<Package xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<version>${options.apiVersion}</version> | ||
<version>${options.apiVersion}.0</version> | ||
</Package>`, | ||
@@ -59,3 +59,3 @@ ], | ||
</types> | ||
<version>${options.apiVersion}</version> | ||
<version>${options.apiVersion}.0</version> | ||
</Package>`, | ||
@@ -62,0 +62,0 @@ ], |
@@ -14,3 +14,3 @@ 'use strict' | ||
typeHandlerFactory = new TypeHandlerFactory({ | ||
config: {}, | ||
config: { apiVersion: '46' }, | ||
diffs: {}, | ||
@@ -17,0 +17,0 @@ promises: [], |
35
index.js
@@ -5,18 +5,37 @@ 'use strict' | ||
const FileUtils = require('./lib/utils/fileUtils') | ||
const git = require('git-state') | ||
const fs = require('fs') | ||
const DESTRUCTIVE_CHANGES_FILE_NAME = 'destructiveChanges.xml' | ||
const PACKAGE_FILE_NAME = 'package.xml' | ||
const ERROR_MESSAGE = `Not enough parameter` | ||
const checkConfig = config => | ||
typeof config.to !== 'string' || | ||
typeof config.apiVersion !== 'string' || | ||
typeof config.output !== 'string' || | ||
typeof config.repo !== 'string' | ||
const checkConfig = config => { | ||
const errors = [] | ||
if (typeof config.to !== 'string') { | ||
errors.push(`to ${config.to} is not a sha`) | ||
} | ||
if (isNaN(config.apiVersion)) { | ||
errors.push(`api-version ${config.apiVersion} is not a number`) | ||
} | ||
if ( | ||
!fs.existsSync(config.output) || | ||
!fs.statSync(config.output).isDirectory() | ||
) { | ||
errors.push(`${config.output} folder does not exist`) | ||
} | ||
if (!git.isGitSync(config.repo)) { | ||
errors.push(`${config.repo} is not a git repository`) | ||
} | ||
return errors | ||
} | ||
module.exports = config => { | ||
return new Promise((resolve, reject) => { | ||
if (checkConfig(config)) { | ||
return reject(new Error(ERROR_MESSAGE)) | ||
const inputError = checkConfig(config) | ||
if (inputError.length > 0) { | ||
return reject(new Error(inputError)) | ||
} | ||
config.apiVersion = parseInt(config.apiVersion) | ||
const diffHandler = new DiffHandler(config) | ||
@@ -23,0 +42,0 @@ diffHandler |
@@ -6,3 +6,3 @@ 'use strict' | ||
const TypeHandlerFactory = require('./service/typeHandlerFactory') | ||
const metadata = require('./metadata/metadata')('directoryName') | ||
const metadataManager = require('./metadata/metadataManager') | ||
@@ -64,2 +64,6 @@ const UTF8_ENCODING = 'utf8' | ||
const treatResult = (fullResult, work) => { | ||
const metadata = metadataManager.getDefinition( | ||
'directoryName', | ||
work.config.apiVersion | ||
) | ||
const typeHandlerFactory = new TypeHandlerFactory(work) | ||
@@ -66,0 +70,0 @@ fullResult |
'use strict' | ||
const xmlbuilder = require('xmlbuilder') | ||
const metadata = require('./metadata/metadata')('directoryName') | ||
const metadataManager = require('./metadata/metadataManager') | ||
const xmlConf = { indent: ' ', newline: '\n', pretty: true } | ||
@@ -15,2 +15,6 @@ | ||
} | ||
const metadata = metadataManager.getDefinition( | ||
'directoryName', | ||
this.config.apiVersion | ||
) | ||
return new Promise(resolve => { | ||
@@ -29,3 +33,3 @@ const xml = getXML() | ||
) | ||
xml.ele('version').t(this.config.apiVersion) | ||
xml.ele('version').t(`${this.config.apiVersion}.0`) | ||
resolve(xml.end(xmlConf)) | ||
@@ -32,0 +36,0 @@ }) |
'use strict' | ||
const metadata = require('../metadata/metadata')('directoryName') | ||
const StandardHandler = require('./standardHandler') | ||
@@ -15,3 +14,3 @@ const path = require('path') | ||
.replace(StandardHandler.METAFILE_SUFFIX, '') | ||
.replace(`.${metadata[this.type].suffix}`, '') | ||
.replace(`.${this.metadata[this.type].suffix}`, '') | ||
) | ||
@@ -18,0 +17,0 @@ } |
'use strict' | ||
const metadata = require('../metadata/metadata')('directoryName') | ||
const metadataManager = require('../metadata/metadataManager') | ||
const path = require('path') | ||
@@ -15,4 +15,8 @@ const fse = require('fs-extra') | ||
this.splittedLine = this.line.split(path.sep) | ||
this.metadata = metadataManager.getDefinition( | ||
'directoryName', | ||
this.config.apiVersion | ||
) | ||
if (metadata[this.type].metaFile === true) { | ||
if (this.metadata[this.type].metaFile === true) { | ||
this.line = this.line.replace(StandardHandler.METAFILE_SUFFIX, '') | ||
@@ -39,3 +43,3 @@ } | ||
this.promises.push(fse.copy(source, target)) | ||
if (metadata[this.type].metaFile === true) { | ||
if (this.metadata[this.type].metaFile === true) { | ||
this.promises.push( | ||
@@ -52,5 +56,5 @@ fse.copy( | ||
if ( | ||
(metadata[this.type].metaFile === true && | ||
(this.metadata[this.type].metaFile === true && | ||
!this.line.endsWith(StandardHandler.METAFILE_SUFFIX)) || | ||
metadata[this.type].metaFile === false | ||
this.metadata[this.type].metaFile === false | ||
) { | ||
@@ -70,3 +74,3 @@ this.diffs[this.type] = this.diffs[this.type] || new Set() | ||
.replace(StandardHandler.METAFILE_SUFFIX, '') | ||
.replace(`.${metadata[this.type].suffix}`, '') | ||
.replace(`.${this.metadata[this.type].suffix}`, '') | ||
} | ||
@@ -73,0 +77,0 @@ } |
@@ -7,3 +7,3 @@ 'use strict' | ||
const Standard = require('./standardHandler') | ||
const metadata = require('../metadata/metadata')('directoryName') | ||
const metadataManager = require('../metadata/metadataManager') | ||
const path = require('path') | ||
@@ -33,15 +33,19 @@ | ||
this.work = work | ||
this.metadata = metadataManager.getDefinition( | ||
'directoryName', | ||
this.work.config.apiVersion | ||
) | ||
} | ||
getTypeHander(line) { | ||
const type = line.split(path.sep).reduce((acc, value) => { | ||
let ret = acc | ||
const type = line | ||
.split(path.sep) | ||
.reduce( | ||
(acc, value) => | ||
Object.prototype.hasOwnProperty.call(this.metadata, value) | ||
? value | ||
: acc, | ||
'' | ||
) | ||
if (Object.prototype.hasOwnProperty.call(metadata, value)) { | ||
ret = value | ||
} | ||
return ret | ||
}, '') | ||
return classes[type] | ||
@@ -48,0 +52,0 @@ ? new classes[type](line, type, this.work) |
{ | ||
"name": "sfdx-git-delta", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "Generate the sfdx content in source format and destructive change from two git commits", | ||
@@ -42,2 +42,3 @@ "keyword": [ | ||
"fs-extra": "^8.1.0", | ||
"git-state": "^4.1.0", | ||
"xmlbuilder": "^13.0.2" | ||
@@ -44,0 +45,0 @@ }, |
@@ -53,3 +53,3 @@ [![NPM](https://nodei.co/npm/sfdx-git-delta.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/sfdx-git-delta/) [![NPM](https://nodei.co/npm-dl/sfdx-git-delta.png)](https://nodei.co/npm/sfdx-git-delta/) [![HitCount](http://hits.dwyl.com/scolladon/sfdx-git-delta.svg)](http://hits.dwyl.com/scolladon/sfdx-git-delta) | ||
'output':'', // source package specific output. Default : ./output | ||
'apiVersion':'', // salesforce API version. Default : 46.0 | ||
'apiVersion':'', // salesforce API version. Default : 46 | ||
'repo':'' // git repository location. Default : ./repo | ||
@@ -56,0 +56,0 @@ }, console.log); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12832698
42
2039
4
11
+ Addedgit-state@^4.1.0
+ Addedafter-all-results@2.0.0(transitive)
+ Addedgit-state@4.1.0(transitive)