@ds-sfdc/sfparty 1.3.7 → 1.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,133 +5,161 @@ import { existsSync } from 'fs'
5
5
  import * as fileUtils from './fileUtils.js'
6
6
 
7
7
  const defaultDefinition = {
8
- git: {
9
- lastCommit: undefined,
10
- latestCommit: undefined,
11
- },
12
- local: {
13
- lastDate: undefined,
14
- }
8
+ git: {
9
+ lastCommit: undefined,
10
+ latestCommit: undefined,
11
+ },
12
+ local: {
13
+ lastDate: undefined,
14
+ },
15
15
  }
16
16
 
17
17
  const status = {
18
- A: {
19
- type: 'add',
20
- action: 'add'
21
- },
22
- C: {
23
- type: 'copy',
24
- action: 'add',
25
- },
26
- D: {
27
- type: 'delete',
28
- action: 'delete'
29
- },
30
- M: {
31
- type: 'modify',
32
- action: 'add'
33
- },
34
- R: {
35
- type: 'rename',
36
- action: 'add'
37
- },
38
- T: {
39
- type: 'type change',
40
- action: 'add'
41
- },
42
- U: {
43
- type: 'unmerged',
44
- action: 'ignore'
45
- },
46
- X: {
47
- type: 'unknown',
48
- action: 'ignore'
49
- },
18
+ A: {
19
+ type: 'add',
20
+ action: 'add',
21
+ },
22
+ C: {
23
+ type: 'copy',
24
+ action: 'add',
25
+ },
26
+ D: {
27
+ type: 'delete',
28
+ action: 'delete',
29
+ },
30
+ M: {
31
+ type: 'modify',
32
+ action: 'add',
33
+ },
34
+ R: {
35
+ type: 'rename',
36
+ action: 'add',
37
+ },
38
+ T: {
39
+ type: 'type change',
40
+ action: 'add',
41
+ },
42
+ U: {
43
+ type: 'unmerged',
44
+ action: 'ignore',
45
+ },
46
+ X: {
47
+ type: 'unknown',
48
+ action: 'ignore',
49
+ },
50
50
  }
51
51
 
52
- export function diff(dir, gitRef = 'HEAD', existsSyncStub = existsSync, execSyncStub = execSync) {
53
- return new Promise((resolve, reject) => {
54
- if (!existsSyncStub(dir) || !existsSyncStub(path.join(dir, '.git'))) {
55
- reject(new Error(`The directory "${dir}" is not a git repository`))
56
- }
52
+ export function diff(
53
+ dir,
54
+ gitRef = 'HEAD',
55
+ existsSyncStub = existsSync,
56
+ execSyncStub = execSync,
57
+ ) {
58
+ return new Promise((resolve, reject) => {
59
+ if (!existsSyncStub(dir) || !existsSyncStub(path.join(dir, '.git'))) {
60
+ reject(new Error(`The directory "${dir}" is not a git repository`))
61
+ }
57
62
 
58
- let data = ''
59
- try {
60
- data = execSyncStub(`git diff --name-status --oneline --relative ${gitRef} -- *-party/*`, { cwd: dir, maxBuffer: 1024 * 1024 * 10 }).toString()
61
- } catch (error) {
62
- reject(error)
63
- }
63
+ let data = ''
64
+ try {
65
+ data = execSyncStub(
66
+ `git diff --name-status --oneline --relative ${gitRef} -- *-party/*`,
67
+ { cwd: dir, maxBuffer: 1024 * 1024 * 10 },
68
+ ).toString()
69
+ } catch (error) {
70
+ reject(error)
71
+ }
64
72
 
65
- const gitData = data.toString().split(os.EOL)
66
- const files = gitData.reduce((acc, gitRow) => {
67
- if (gitRow.indexOf('\t') > 0) {
68
- const file = gitRow.split('\t')
69
- if (file.slice(-1) !== '') {
70
- const statusType = status[(file[0] === file.slice(-1)) ? 'A' : Array.from(file[0])[0]];
71
- acc.push({
72
- type: statusType.type,
73
- path: file.slice(-1)[0],
74
- action: statusType.action
75
- });
76
- }
77
- }
78
- return acc;
79
- }, []);
80
- resolve(files);
81
- })
73
+ const gitData = data.toString().split(os.EOL)
74
+ const files = gitData.reduce((acc, gitRow) => {
75
+ if (gitRow.indexOf('\t') > 0) {
76
+ const file = gitRow.split('\t')
77
+ if (file.slice(-1) !== '') {
78
+ const statusType =
79
+ status[
80
+ file[0] === file.slice(-1)
81
+ ? 'A'
82
+ : Array.from(file[0])[0]
83
+ ]
84
+ acc.push({
85
+ type: statusType.type,
86
+ path: file.slice(-1)[0],
87
+ action: statusType.action,
88
+ })
89
+ }
90
+ }
91
+ return acc
92
+ }, [])
93
+ resolve(files)
94
+ })
82
95
  }
83
96
 
84
97
  export function log(dir, gitRef, execSyncStub = execSync) {
85
- try {
86
- const gitLog = execSyncStub(`git log --format=format:%H ${gitRef}`, { cwd: dir, encoding: 'utf-8' });
87
- const commits = gitLog.split(os.EOL).filter(commit => commit)
88
- return commits
89
- } catch (error) {
90
- if (error.message.indexOf('ENOENT') > -1) {
91
- error.message = 'git not installed or no entry found in path'
92
- }
93
- throw error
94
- }
98
+ try {
99
+ const gitLog = execSyncStub(`git log --format=format:%H ${gitRef}`, {
100
+ cwd: dir,
101
+ encoding: 'utf-8',
102
+ })
103
+ const commits = gitLog.split(os.EOL).filter((commit) => commit)
104
+ return commits
105
+ } catch (error) {
106
+ if (error.message.indexOf('ENOENT') > -1) {
107
+ error.message = 'git not installed or no entry found in path'
108
+ }
109
+ throw error
110
+ }
95
111
  }
96
112
 
97
- export function lastCommit(dir, fileName = 'index.yaml', existsSyncStub = existsSync, execSyncStub = execSync, fileUtilsStub = fileUtils) {
98
- try {
99
- const folder = path.resolve(dir, '.sfdx', 'sfparty')
100
- const filePath = path.resolve(folder, fileName)
101
- let lastCommit = undefined
113
+ export function lastCommit(
114
+ dir,
115
+ fileName = 'index.yaml',
116
+ existsSyncStub = existsSync,
117
+ execSyncStub = execSync,
118
+ fileUtilsStub = fileUtils,
119
+ ) {
120
+ try {
121
+ const folder = path.resolve(dir, '.sfdx', 'sfparty')
122
+ const filePath = path.resolve(folder, fileName)
123
+ let lastCommit = undefined
102
124
 
103
- fileUtilsStub.createDirectory(folder)
104
- if (existsSyncStub(filePath)) {
105
- const data = fileUtilsStub.readFile(filePath)
106
- if (data.git.lastCommit !== undefined) {
107
- lastCommit = data.git.lastCommit
108
- }
109
- }
110
- const latestCommit = execSyncStub(`git log --format=format:%H -1`, { cwd: dir, encoding: 'utf-8' })
111
- return {
112
- lastCommit: lastCommit,
113
- latestCommit: latestCommit,
114
- }
115
- } catch (error) {
116
- throw new Error(error)
117
- }
125
+ fileUtilsStub.createDirectory(folder)
126
+ if (existsSyncStub(filePath)) {
127
+ const data = fileUtilsStub.readFile(filePath)
128
+ if (data.git.lastCommit !== undefined) {
129
+ lastCommit = data.git.lastCommit
130
+ }
131
+ }
132
+ const latestCommit = execSyncStub(`git log --format=format:%H -1`, {
133
+ cwd: dir,
134
+ encoding: 'utf-8',
135
+ })
136
+ return {
137
+ lastCommit: lastCommit,
138
+ latestCommit: latestCommit,
139
+ }
140
+ } catch (error) {
141
+ throw new Error(error)
142
+ }
118
143
  }
119
144
 
120
145
  export function updateLastCommit(dir, latest, fileUtilsStub = fileUtils) {
121
- if (typeof latest !== 'string' && typeof latest !== 'undefined') throw new Error(`updateLastCommit received a ${typeof latest} instead of string`)
122
- if (latest !== undefined) {
123
- const folder = path.join(dir, '.sfdx', 'sfparty')
124
- const fileName = path.join(folder, 'index.yaml')
125
- let data = undefined
126
- if (fileUtilsStub.fileExists(fileName)) {
127
- data = fileUtilsStub.readFile(fileName)
128
- }
146
+ if (typeof latest !== 'string' && typeof latest !== 'undefined')
147
+ throw new Error(
148
+ `updateLastCommit received a ${typeof latest} instead of string`,
149
+ )
150
+ if (latest !== undefined) {
151
+ const folder = path.join(dir, '.sfdx', 'sfparty')
152
+ const fileName = path.join(folder, 'index.yaml')
153
+ let data = undefined
154
+ if (fileUtilsStub.fileExists(fileName)) {
155
+ data = fileUtilsStub.readFile(fileName)
156
+ }
129
157
 
130
- if (data === undefined) {
131
- data = defaultDefinition
132
- }
158
+ if (data === undefined) {
159
+ data = defaultDefinition
160
+ }
133
161
 
134
- data.git.lastCommit = latest
135
- fileUtilsStub.saveFile(data, fileName)
136
- }
137
- }
162
+ data.git.lastCommit = latest
163
+ fileUtilsStub.saveFile(data, fileName)
164
+ }
165
+ }