-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathconnectionProfiles.ts
More file actions
65 lines (52 loc) · 1.76 KB
/
Copy pathconnectionProfiles.ts
File metadata and controls
65 lines (52 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import path from 'path';
import fs from 'fs-extra';
import { ConnectionProfile } from 'auth0';
import { constants } from '../../../tools';
import log from '../../../logger';
import { dumpJSON, existsMustBeDir, getFiles, loadJSON, sanitize } from '../../../utils';
import DirectoryContext from '..';
import { ParsedAsset } from '../../../types';
type ParsedConnectionProfiles = ParsedAsset<'connectionProfiles', Partial<ConnectionProfile>[]>;
function parse(context: DirectoryContext): ParsedConnectionProfiles {
const connectionProfilesFolder = path.join(
context.filePath,
constants.CONNECTION_PROFILES_DIRECTORY
);
if (!existsMustBeDir(connectionProfilesFolder)) return { connectionProfiles: null }; // Skip
const files = getFiles(connectionProfilesFolder, ['.json']);
const connectionProfiles = files.map((f) => {
const profile = {
...loadJSON(f, {
mappings: context.mappings,
disableKeywordReplacement: context.disableKeywordReplacement,
}),
};
return profile;
});
return {
connectionProfiles,
};
}
async function dump(context: DirectoryContext): Promise<void> {
const { connectionProfiles } = context.assets;
if (!connectionProfiles) return;
const connectionProfilesFolder = path.join(
context.filePath,
constants.CONNECTION_PROFILES_DIRECTORY
);
fs.ensureDirSync(connectionProfilesFolder);
connectionProfiles.forEach((profile) => {
const profileFile = path.join(connectionProfilesFolder, sanitize(`${profile.name}.json`));
log.info(`Writing ${profileFile}`);
// Remove read-only fields
if ('id' in profile) {
delete profile.id;
}
dumpJSON(profileFile, profile);
});
}
const connectionProfilesHandler = {
parse,
dump,
};
export default connectionProfilesHandler;