This repository has been archived by the owner on Nov 24, 2022. It is now read-only.
forked from OnyxPrime/sourcebit-source-kontent
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
125 lines (112 loc) · 2.69 KB
/
index.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const pkg = require("./package.json");
const kontentItems = require("./build/src/core/sourceNodes.items");
const kontentTypes = require("./build/src/core/sourceNodes.types");
const normalize = require("./build/src/normalize");
module.exports.name = pkg.name;
module.exports.options = {
kontentProjectId: {
private: false
},
languageCodenames: {
private: false
},
includeKontentMetadata: {
private : false,
default: false,
}
};
module.exports.bootstrap = async ({
debug,
getPluginContext,
log,
options,
refresh,
setPluginContext
}) => {
const context = getPluginContext();
if (context && context.entries) {
log(`Loaded ${context.entries.length} entries from cache`);
} else {
const kontentConfig = {
projectId: options.projectId,
languageCodenames: options.languageCodenames
};
const items = await kontentItems.kontentItemsSourceNodes(kontentConfig);
const types = await kontentTypes.kontentTypesSourceNodes(kontentConfig);
setPluginContext({
items,
types
});
}
if (options.watch) {
console.error("Watch mode is not supported at this time");
}
};
module.exports.transform = ({
data,
debug,
getPluginContext,
log,
options
}) => {
const { items, types } = getPluginContext();
const normalizedModels = normalize.getNormalizedModels(types, options);
const normalizedEntries = normalize.getNormalizedEntries(
items,
normalizedModels,
options
);
const normalizedAssets = normalize.getNormalizedAssets(
items,
normalizedModels
);
const normalizedAssetsAndEntries = normalizedAssets.concat(normalizedEntries);
return {
...data,
models: data.models.concat(normalizedModels),
objects: data.objects.concat(normalizedAssetsAndEntries)
};
};
module.exports.getSetup = ({
chalk,
context,
currentOptions,
data,
debug,
getSetupContext,
inquirer,
ora,
setSetupContext
}) => {
const questions = [
{
type: "input",
name: "projectId",
message: "What is the Kontent projectId?",
validate: value =>
value.length > 0 ? true : "The project Id cannot be empty."
},
{
type: "input",
name: "languageCodenames",
message: "What are the Kontent languages codenames (separated by space)?",
validate: value =>
value.length > 0 ? true : "The language codenames cannot be empty."
}
];
return async () => {
const answers = await inquirer.prompt(questions);
return answers;
};
};
module.exports.getOptionsFromSetup = ({
answers,
debug,
getSetupContext,
setSetupContext
}) => {
return {
projectId: answers.projectId,
languageCodenames: answers.languageCodenames.split(" ")
};
};