Skip to content

Commit deb129b

Browse files
committed
chore(package upgrade): resolved vulnerabilities -- refactor
1 parent deb35d7 commit deb129b

7 files changed

Lines changed: 3191 additions & 2197 deletions

File tree

lib/bootstrap/__tests__/jsonToScript.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ describe('jsonToScript', () => {
161161
}
162162
]
163163

164-
it('generates description, up and down', () => {
165-
const actual = jsonToScript(contentType, editorInterface)
164+
it('generates description, up and down', async () => {
165+
const actual = await jsonToScript(contentType, editorInterface)
166166
expect(actual).to.contain('module.exports.description = \'Create content model for Horse\'')
167167
expect(actual).to.contain('module.exports.up')
168168
expect(actual).to.contain('module.exports.down')

lib/bootstrap/generateScripts.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@ const generateScripts = async (spaceId, environmentId, contentTypes, accessToken
2121
const contentTypesSet = new Set(contentTypes)
2222
requiredContentTypes = requiredContentTypes.filter(contentType => contentTypesSet.has(contentType.sys.id))
2323
}
24-
const mapper = (contentType) => {
24+
const mapper = async (contentType) => {
2525
const contentTypeId = contentType.sys.id
26-
return environment.getEditorInterfaceForContentType(contentTypeId)
27-
.then((editorInterface) => {
28-
return createFile(
29-
contentTypeId,
30-
jsonToScript(contentType, editorInterface.controls),
31-
migrationsDirectory
32-
)
33-
})
26+
const editorInterface = await environment.getEditorInterfaceForContentType(contentTypeId)
27+
const script = await jsonToScript(contentType, editorInterface.controls)
28+
return createFile(
29+
contentTypeId,
30+
script,
31+
migrationsDirectory
32+
)
3433
}
3534

3635
const files = await pMap(requiredContentTypes, mapper, { concurrency })

lib/bootstrap/jsonToScript.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,16 @@ const restructureContentTypeJson = item => ({
6363
fields: item.fields.map(restructureFields)
6464
})
6565

66-
const jsonToScript = (contentTypeJson, editorInterface) => {
66+
const jsonToScript = async (contentTypeJson, editorInterface) => {
6767
const restructuredJson = restructureContentTypeJson(contentTypeJson)
6868
const unformattedScript = createScript(restructuredJson, editorInterface)
69-
const engine = new eslint.CLIEngine({
69+
const engine = new eslint.ESLint({
7070
fix: true,
7171
baseConfig: { extends: ['eslint-config-standard'] },
7272
useEslintrc: false
7373
})
74-
return engine.executeOnText(unformattedScript).results[0].output
74+
const results = await engine.lintText(unformattedScript)
75+
return results[0].output || unformattedScript
7576
}
7677

7778
module.exports = {

lib/run.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ const run = async ({
3939
const client = createManagementClient(clientConfig)
4040

4141
const makeRequest = (requestConfig) => {
42-
const { url, ...config } = requestConfig
42+
const { url, baseType, ...config } = requestConfig
4343
const parts = [
4444
'spaces', spaceId,
4545
'environments', environmentId,
4646
url.replace(/^\//, '') // Remove leading slash if present
4747
]
48-
const fullUrl = parts.filter(x => x !== '').join('/')
48+
const fullUrl = `https://api.contentful.com/${parts.filter(x => x !== '').join('/')}`
4949
return client.raw.http(fullUrl, config)
5050
}
5151
const migrationParser = migrationParser1.default(makeRequest, clientConfig)

lib/store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class ContentfulStore {
8787
return {
8888
[this.locale]: {
8989
lastRun: set.lastRun,
90-
migrations: migrations
90+
migrations
9191
}
9292
}
9393
}

0 commit comments

Comments
 (0)