Skip to content

Commit

Permalink
fix(deps): support node 20 and strapi v4.13
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sargreal committed Oct 28, 2023
1 parent c6e569f commit 6c816f7
Show file tree
Hide file tree
Showing 11 changed files with 2,527 additions and 2,004 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ on:
workflow_call:
jobs:
e2e:
continue-on-error: true
strategy:
matrix:
node: [14, 16, 18]
strapi: [4.6, 4.7, 4.8, 4.9]
node: [18, 20]
strapi: [4.14, 4.15]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
unittest:
strategy:
matrix:
version: [14, 16, 18]
version: [18, 20]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions playground/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,4 @@ exports
dist
build
.strapi-updater.json
types
47 changes: 23 additions & 24 deletions playground/package.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
{
"dependencies": {
"@strapi/plugin-i18n": "4.9.2",
"@strapi/plugin-users-permissions": "4.7.1",
"@strapi/strapi": "4.9.2",
"better-sqlite3": "8.2.0",
"dotenv": "^16.0.3",
"lodash.set": "^4.3.2",
"mime-types": "^2.1.27",
"strapi-plugin-init-admin-user": "^0.2.1"
},
"name": "playground",
"private": true,
"version": "0.1.0",
"private": true,
"description": "A Strapi application",
"license": "MIT",
"author": {
"name": "A Strapi developer"
},
"scripts": {
"build": "strapi build",
"cy:run": "cypress run",
"develop": "strapi develop",
"e2e": "ENV_PATH='./.env.test' start-server-and-test 'yarn start' http://0.0.0.0:1337 'yarn cy:run'",
"reset": "node scripts/reset.js",
"start": "strapi start",
"build": "strapi build",
"strapi": "strapi",
"reset": "node scripts/reset.js",
"cy:run": "cypress run",
"test": "echo no unittests",
"e2e": "ENV_PATH='./.env.test' start-server-and-test 'yarn start' http://0.0.0.0:1337 'yarn cy:run'"
"test": "echo no unittests"
},
"dependencies": {
"@strapi/plugin-i18n": "4.15.0",
"@strapi/plugin-users-permissions": "4.15.0",
"@strapi/strapi": "4.15.0",
"better-sqlite3": "8.2.0",
"dotenv": "^16.0.3",
"lodash.set": "^4.3.2",
"mime-types": "^2.1.27"
},
"devDependencies": {
"cypress": "^12.7.0",
"start-server-and-test": "^2.0.0"
},
"author": {
"name": "A Strapi developer"
"engines": {
"node": ">=14.19.1 <=20.x.x",
"npm": ">=6.0.0"
},
"strapi": {
"uuid": "e52249f8-dcf2-4e7b-8612-7713abc46c04",
"template": "@strapi/template-blog@^1.0.0",
"starter": "@strapi/starter-next-blog",
"telemetryDisabled": true
},
"engines": {
"node": ">=14.19.1 <=18.x.x",
"npm": ">=6.0.0"
},
"license": "MIT"
}
}
59 changes: 57 additions & 2 deletions playground/src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
'categories-page': categoriesPage,
global,
} = require('../data/data.json')
const { initAdminData, getSuperAdminRole } = require('./helpers/init-admin')

async function isFirstRun() {
const pluginStore = strapi.store({
Expand Down Expand Up @@ -223,16 +224,70 @@ async function cleanData() {
await cleanCollectionType('api::writer.writer')
}

async function initAdmin() {
// MIT License

// Copyright (c) 2022 minzig

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
if (
process.env.NODE_ENV === 'development' ||
process.env.INIT_ADMIN === 'true' ||
(typeof process.env.INIT_ADMIN === 'string' &&
process.env.INIT_ADMIN.includes('{"'))
) {
const users = await strapi.db.query('admin::user').findMany()
if (users.length === 0) {
const defaultAdmin = initAdminData(process.env)
const superAdminRole = await getSuperAdminRole()
defaultAdmin.roles = [superAdminRole.id]
defaultAdmin.password = await strapi
.service('admin::auth')
.hashPassword(defaultAdmin.password)
try {
await strapi.db
.query('admin::user')
.create({ data: { ...defaultAdmin } })
strapi.log.info(
`Created admin (E-Mail: ${defaultAdmin.email}, Password: ${
process.env.INIT_ADMIN_PASSWORD ? '[INIT_ADMIN_PASSWORD]' : 'admin'
}).`
)
} catch (e) {
strapi.log.error(`Couldn't create admin (${defaultAdmin.email}):`, e)
}
}
}
}

module.exports = async () => {
const shouldImportSeedData = await isFirstRun()

if (shouldImportSeedData) {
try {
console.log('Cleaning database')
console.log('Cleaning database...')
await cleanData()
console.log('Initializing admin user...')
await initAdmin()
console.log('Setting up the template...')
await importSeedData()
console.log('Ready to go')
console.log('Ready to go!')
} catch (error) {
console.log('Could not import seed data')
console.error(error)
Expand Down
75 changes: 75 additions & 0 deletions playground/src/helpers/init-admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// MIT License

// Copyright (c) 2022 minzig

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

module.exports = {
async getSuperAdminRole() {
try {
await strapi.admin.services.role.createRolesIfNoneExist()
} catch (e) {
strapi.log.error(`Couldn't check for & create existing roles.`, e)
}

let superAdminRole = await strapi.db.query('admin::role').findOne({
select: [],
where: { code: 'strapi-super-admin' },
orderBy: {},
populate: {},
})

if (!superAdminRole) {
superAdminRole = await strapi.db.query('admin::role').create({
data: {
name: 'Super Admin',
code: 'strapi-super-admin',
description:
'Super Admins can access and manage all features and settings.',
},
})
}

return superAdminRole
},
initAdminData(env) {
const useJsonData = (initAdminString) => {
let adminData = {}
try {
adminData = JSON.parse(initAdminString)
} catch (e) {
strapi.log.error(`Couldn't parse adminData from INIT_ADMIN.`, e)
}
return adminData
}
return {
username: env.INIT_ADMIN_USERNAME || 'admin',
password: env.INIT_ADMIN_PASSWORD || 'admin',
firstname: env.INIT_ADMIN_FIRSTNAME || 'Admin',
lastname: env.INIT_ADMIN_LASTNAME || 'Admin',
email: env.INIT_ADMIN_EMAIL || '[email protected]',
blocked: false,
isActive: true,
...(typeof env.INIT_ADMIN === 'string' &&
env.INIT_ADMIN.includes('{"') && {
...useJsonData(env.INIT_ADMIN),
}),
}
},
}
47 changes: 23 additions & 24 deletions playground/templates/template.package.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
{
"dependencies": {
"@strapi/plugin-i18n": "${VERSION}",
"@strapi/plugin-users-permissions": "${VERSION}",
"@strapi/strapi": "${VERSION}",
"better-sqlite3": "8.2.0",
"dotenv": "^16.0.3",
"lodash.set": "^4.3.2",
"mime-types": "^2.1.27",
"strapi-plugin-init-admin-user": "^0.2.1"
},
"name": "playground",
"private": true,
"version": "0.1.0",
"private": true,
"description": "A Strapi application",
"license": "MIT",
"author": {
"name": "A Strapi developer"
},
"scripts": {
"build": "strapi build",
"cy:run": "cypress run",
"develop": "strapi develop",
"e2e": "ENV_PATH='./.env.test' start-server-and-test 'yarn start' http://0.0.0.0:1337 'yarn cy:run'",
"reset": "node scripts/reset.js",
"start": "strapi start",
"build": "strapi build",
"strapi": "strapi",
"reset": "node scripts/reset.js",
"cy:run": "cypress run",
"test": "echo no unittests",
"e2e": "ENV_PATH='./.env.test' start-server-and-test 'yarn start' http://0.0.0.0:1337 'yarn cy:run'"
"test": "echo no unittests"
},
"dependencies": {
"@strapi/plugin-i18n": "${VERSION}",
"@strapi/plugin-users-permissions": "${VERSION}",
"@strapi/strapi": "${VERSION}",
"better-sqlite3": "8.2.0",
"dotenv": "^16.0.3",
"lodash.set": "^4.3.2",
"mime-types": "^2.1.27"
},
"devDependencies": {
"cypress": "^12.7.0",
"start-server-and-test": "^2.0.0"
},
"author": {
"name": "A Strapi developer"
"engines": {
"node": ">=14.19.1 <=20.x.x",
"npm": ">=6.0.0"
},
"strapi": {
"uuid": "e52249f8-dcf2-4e7b-8612-7713abc46c04",
"template": "@strapi/template-blog@^1.0.0",
"starter": "@strapi/starter-next-blog",
"telemetryDisabled": true
},
"engines": {
"node": ">=14.19.1 <=18.x.x",
"npm": ">=6.0.0"
},
"license": "MIT"
}
}
Loading

0 comments on commit 6c816f7

Please sign in to comment.