Skip to content

Commit 6c816f7

Browse files
committed
fix(deps): support node 20 and strapi v4.13
With Strapi v4.13 support for nodejs 20 was introduced and with v4.15 support for nodejs 16 was dropped. This plugin should support the most versions possible. fix #357
1 parent c6e569f commit 6c816f7

File tree

11 files changed

+2527
-2004
lines changed

11 files changed

+2527
-2004
lines changed

.github/workflows/e2e.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ on:
22
workflow_call:
33
jobs:
44
e2e:
5+
continue-on-error: true
56
strategy:
67
matrix:
7-
node: [14, 16, 18]
8-
strapi: [4.6, 4.7, 4.8, 4.9]
8+
node: [18, 20]
9+
strapi: [4.14, 4.15]
910
runs-on: ubuntu-latest
1011
steps:
1112
- uses: actions/checkout@v3

.github/workflows/unittest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jobs:
44
unittest:
55
strategy:
66
matrix:
7-
version: [14, 16, 18]
7+
version: [18, 20]
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@v3

playground/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,4 @@ exports
113113
dist
114114
build
115115
.strapi-updater.json
116+
types

playground/package.json

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
11
{
2-
"dependencies": {
3-
"@strapi/plugin-i18n": "4.9.2",
4-
"@strapi/plugin-users-permissions": "4.7.1",
5-
"@strapi/strapi": "4.9.2",
6-
"better-sqlite3": "8.2.0",
7-
"dotenv": "^16.0.3",
8-
"lodash.set": "^4.3.2",
9-
"mime-types": "^2.1.27",
10-
"strapi-plugin-init-admin-user": "^0.2.1"
11-
},
122
"name": "playground",
13-
"private": true,
143
"version": "0.1.0",
4+
"private": true,
155
"description": "A Strapi application",
6+
"license": "MIT",
7+
"author": {
8+
"name": "A Strapi developer"
9+
},
1610
"scripts": {
11+
"build": "strapi build",
12+
"cy:run": "cypress run",
1713
"develop": "strapi develop",
14+
"e2e": "ENV_PATH='./.env.test' start-server-and-test 'yarn start' http://0.0.0.0:1337 'yarn cy:run'",
15+
"reset": "node scripts/reset.js",
1816
"start": "strapi start",
19-
"build": "strapi build",
2017
"strapi": "strapi",
21-
"reset": "node scripts/reset.js",
22-
"cy:run": "cypress run",
23-
"test": "echo no unittests",
24-
"e2e": "ENV_PATH='./.env.test' start-server-and-test 'yarn start' http://0.0.0.0:1337 'yarn cy:run'"
18+
"test": "echo no unittests"
19+
},
20+
"dependencies": {
21+
"@strapi/plugin-i18n": "4.15.0",
22+
"@strapi/plugin-users-permissions": "4.15.0",
23+
"@strapi/strapi": "4.15.0",
24+
"better-sqlite3": "8.2.0",
25+
"dotenv": "^16.0.3",
26+
"lodash.set": "^4.3.2",
27+
"mime-types": "^2.1.27"
2528
},
2629
"devDependencies": {
2730
"cypress": "^12.7.0",
2831
"start-server-and-test": "^2.0.0"
2932
},
30-
"author": {
31-
"name": "A Strapi developer"
33+
"engines": {
34+
"node": ">=14.19.1 <=20.x.x",
35+
"npm": ">=6.0.0"
3236
},
3337
"strapi": {
3438
"uuid": "e52249f8-dcf2-4e7b-8612-7713abc46c04",
3539
"template": "@strapi/template-blog@^1.0.0",
3640
"starter": "@strapi/starter-next-blog",
3741
"telemetryDisabled": true
38-
},
39-
"engines": {
40-
"node": ">=14.19.1 <=18.x.x",
41-
"npm": ">=6.0.0"
42-
},
43-
"license": "MIT"
42+
}
4443
}

playground/src/bootstrap.js

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
'categories-page': categoriesPage,
1313
global,
1414
} = require('../data/data.json')
15+
const { initAdminData, getSuperAdminRole } = require('./helpers/init-admin')
1516

1617
async function isFirstRun() {
1718
const pluginStore = strapi.store({
@@ -223,16 +224,70 @@ async function cleanData() {
223224
await cleanCollectionType('api::writer.writer')
224225
}
225226

227+
async function initAdmin() {
228+
// MIT License
229+
230+
// Copyright (c) 2022 minzig
231+
232+
// Permission is hereby granted, free of charge, to any person obtaining a copy
233+
// of this software and associated documentation files (the "Software"), to deal
234+
// in the Software without restriction, including without limitation the rights
235+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
236+
// copies of the Software, and to permit persons to whom the Software is
237+
// furnished to do so, subject to the following conditions:
238+
239+
// The above copyright notice and this permission notice shall be included in all
240+
// copies or substantial portions of the Software.
241+
242+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
243+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
244+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
245+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
246+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
247+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
248+
// SOFTWARE.
249+
if (
250+
process.env.NODE_ENV === 'development' ||
251+
process.env.INIT_ADMIN === 'true' ||
252+
(typeof process.env.INIT_ADMIN === 'string' &&
253+
process.env.INIT_ADMIN.includes('{"'))
254+
) {
255+
const users = await strapi.db.query('admin::user').findMany()
256+
if (users.length === 0) {
257+
const defaultAdmin = initAdminData(process.env)
258+
const superAdminRole = await getSuperAdminRole()
259+
defaultAdmin.roles = [superAdminRole.id]
260+
defaultAdmin.password = await strapi
261+
.service('admin::auth')
262+
.hashPassword(defaultAdmin.password)
263+
try {
264+
await strapi.db
265+
.query('admin::user')
266+
.create({ data: { ...defaultAdmin } })
267+
strapi.log.info(
268+
`Created admin (E-Mail: ${defaultAdmin.email}, Password: ${
269+
process.env.INIT_ADMIN_PASSWORD ? '[INIT_ADMIN_PASSWORD]' : 'admin'
270+
}).`
271+
)
272+
} catch (e) {
273+
strapi.log.error(`Couldn't create admin (${defaultAdmin.email}):`, e)
274+
}
275+
}
276+
}
277+
}
278+
226279
module.exports = async () => {
227280
const shouldImportSeedData = await isFirstRun()
228281

229282
if (shouldImportSeedData) {
230283
try {
231-
console.log('Cleaning database')
284+
console.log('Cleaning database...')
232285
await cleanData()
286+
console.log('Initializing admin user...')
287+
await initAdmin()
233288
console.log('Setting up the template...')
234289
await importSeedData()
235-
console.log('Ready to go')
290+
console.log('Ready to go!')
236291
} catch (error) {
237292
console.log('Could not import seed data')
238293
console.error(error)

playground/src/helpers/init-admin.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// MIT License
2+
3+
// Copyright (c) 2022 minzig
4+
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
module.exports = {
24+
async getSuperAdminRole() {
25+
try {
26+
await strapi.admin.services.role.createRolesIfNoneExist()
27+
} catch (e) {
28+
strapi.log.error(`Couldn't check for & create existing roles.`, e)
29+
}
30+
31+
let superAdminRole = await strapi.db.query('admin::role').findOne({
32+
select: [],
33+
where: { code: 'strapi-super-admin' },
34+
orderBy: {},
35+
populate: {},
36+
})
37+
38+
if (!superAdminRole) {
39+
superAdminRole = await strapi.db.query('admin::role').create({
40+
data: {
41+
name: 'Super Admin',
42+
code: 'strapi-super-admin',
43+
description:
44+
'Super Admins can access and manage all features and settings.',
45+
},
46+
})
47+
}
48+
49+
return superAdminRole
50+
},
51+
initAdminData(env) {
52+
const useJsonData = (initAdminString) => {
53+
let adminData = {}
54+
try {
55+
adminData = JSON.parse(initAdminString)
56+
} catch (e) {
57+
strapi.log.error(`Couldn't parse adminData from INIT_ADMIN.`, e)
58+
}
59+
return adminData
60+
}
61+
return {
62+
username: env.INIT_ADMIN_USERNAME || 'admin',
63+
password: env.INIT_ADMIN_PASSWORD || 'admin',
64+
firstname: env.INIT_ADMIN_FIRSTNAME || 'Admin',
65+
lastname: env.INIT_ADMIN_LASTNAME || 'Admin',
66+
email: env.INIT_ADMIN_EMAIL || '[email protected]',
67+
blocked: false,
68+
isActive: true,
69+
...(typeof env.INIT_ADMIN === 'string' &&
70+
env.INIT_ADMIN.includes('{"') && {
71+
...useJsonData(env.INIT_ADMIN),
72+
}),
73+
}
74+
},
75+
}
Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
11
{
2-
"dependencies": {
3-
"@strapi/plugin-i18n": "${VERSION}",
4-
"@strapi/plugin-users-permissions": "${VERSION}",
5-
"@strapi/strapi": "${VERSION}",
6-
"better-sqlite3": "8.2.0",
7-
"dotenv": "^16.0.3",
8-
"lodash.set": "^4.3.2",
9-
"mime-types": "^2.1.27",
10-
"strapi-plugin-init-admin-user": "^0.2.1"
11-
},
122
"name": "playground",
13-
"private": true,
143
"version": "0.1.0",
4+
"private": true,
155
"description": "A Strapi application",
6+
"license": "MIT",
7+
"author": {
8+
"name": "A Strapi developer"
9+
},
1610
"scripts": {
11+
"build": "strapi build",
12+
"cy:run": "cypress run",
1713
"develop": "strapi develop",
14+
"e2e": "ENV_PATH='./.env.test' start-server-and-test 'yarn start' http://0.0.0.0:1337 'yarn cy:run'",
15+
"reset": "node scripts/reset.js",
1816
"start": "strapi start",
19-
"build": "strapi build",
2017
"strapi": "strapi",
21-
"reset": "node scripts/reset.js",
22-
"cy:run": "cypress run",
23-
"test": "echo no unittests",
24-
"e2e": "ENV_PATH='./.env.test' start-server-and-test 'yarn start' http://0.0.0.0:1337 'yarn cy:run'"
18+
"test": "echo no unittests"
19+
},
20+
"dependencies": {
21+
"@strapi/plugin-i18n": "${VERSION}",
22+
"@strapi/plugin-users-permissions": "${VERSION}",
23+
"@strapi/strapi": "${VERSION}",
24+
"better-sqlite3": "8.2.0",
25+
"dotenv": "^16.0.3",
26+
"lodash.set": "^4.3.2",
27+
"mime-types": "^2.1.27"
2528
},
2629
"devDependencies": {
2730
"cypress": "^12.7.0",
2831
"start-server-and-test": "^2.0.0"
2932
},
30-
"author": {
31-
"name": "A Strapi developer"
33+
"engines": {
34+
"node": ">=14.19.1 <=20.x.x",
35+
"npm": ">=6.0.0"
3236
},
3337
"strapi": {
3438
"uuid": "e52249f8-dcf2-4e7b-8612-7713abc46c04",
3539
"template": "@strapi/template-blog@^1.0.0",
3640
"starter": "@strapi/starter-next-blog",
3741
"telemetryDisabled": true
38-
},
39-
"engines": {
40-
"node": ">=14.19.1 <=18.x.x",
41-
"npm": ">=6.0.0"
42-
},
43-
"license": "MIT"
42+
}
4443
}

0 commit comments

Comments
 (0)