Skip to content

Commit

Permalink
Merge pull request #359 from Fekide/357-feature-support-nodejs-20
Browse files Browse the repository at this point in the history
fix(deps): support node 20 and strapi v4.13
  • Loading branch information
sargreal authored Nov 2, 2023
2 parents 5c9a70d + f458956 commit e457cef
Show file tree
Hide file tree
Showing 13 changed files with 2,543 additions and 2,019 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
11 changes: 6 additions & 5 deletions playground/cypress/e2e/batch-translation.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ describe('batch translation', () => {
.contains('label', 'Locales')
.invoke('attr', 'for')
.then((id) => {
cy.get('#' + id)
cy.get(`[id='${id}']`)
})
.click()
cy.get('li[data-strapi-value=en]').click()

cy.get('div[role=option]').filter(':contains("English (en)")').click()
cy.get('div[role=dialog] button').filter(':contains("Translate")').click()

// Verify translation finished
Expand Down Expand Up @@ -65,15 +66,15 @@ describe('batch translation', () => {
.contains('label', 'Locales')
.invoke('attr', 'for')
.then((id) => {
cy.get('#' + id)
cy.get(`[id='${id}']`)
})
.click()
cy.get('li[data-strapi-value=en]').click()
cy.get('div[role=option]').filter(':contains("English (en)")').click()
cy.get('div[role=dialog]')
.contains('label', 'Auto-Publish')
.invoke('attr', 'for')
.then((id) => {
cy.get('#' + id)
cy.get(`[id='${id}']`)
})
.parent()
.click()
Expand Down
20 changes: 10 additions & 10 deletions playground/cypress/e2e/direct-translation.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('direct translation', () => {
cy.contains('label', 'Locales')
.invoke('attr', 'for')
.then((id) => {
cy.get('#' + id)
cy.get(`[id='${id}']`)
})
.click()
cy.contains('German (de)').click()
Expand All @@ -29,7 +29,7 @@ describe('direct translation', () => {
cy.contains('label', 'slug')
.invoke('attr', 'for')
.then((id) => {
cy.get('#' + id)
cy.get(`[id='${id}']`)
})
.clear()
.type('a-bug-is-becoming-a-meme-on-the-internet-1')
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('direct translation', () => {
cy.contains('label', 'Locales')
.invoke('attr', 'for')
.then((id) => {
cy.get('#' + id)
cy.get(`[id='${id}']`)
})
.click()
cy.contains('German (de)').click()
Expand All @@ -73,7 +73,7 @@ describe('direct translation', () => {
cy.contains('label', 'slug')
.invoke('attr', 'for')
.then((id) => {
cy.get('#' + id)
cy.get(`[id='${id}']`)
})
.clear()
.type('tech-1')
Expand All @@ -89,7 +89,7 @@ describe('direct translation', () => {
cy.contains('label', 'Locales')
.invoke('attr', 'for')
.then((id) => {
cy.get('#' + id)
cy.get(`[id='${id}']`)
})
.click()
cy.contains('German (de)').click()
Expand All @@ -103,7 +103,7 @@ describe('direct translation', () => {
cy.contains('label', 'slug')
.invoke('attr', 'for')
.then((id) => {
cy.get('#' + id)
cy.get(`[id='${id}']`)
})
.clear()
.type('a-bug-is-becoming-a-meme-on-the-internet-1')
Expand Down Expand Up @@ -132,7 +132,7 @@ describe('direct translation', () => {
cy.contains('label', 'Locales')
.invoke('attr', 'for')
.then((id) => {
cy.get('#' + id)
cy.get(`[id='${id}']`)
})
.click()
cy.contains('German (de)').click()
Expand All @@ -149,13 +149,13 @@ describe('direct translation', () => {
cy.contains('label', 'metaTitle')
.invoke('attr', 'for')
.then((id) => {
cy.get('#' + id.replace('.', '\\.'))
cy.get(`[id='${id.replace('.', '\\.')}']`)
})
.should('have.value', 'My personal Strapi blog')
cy.contains('label', 'shareImage')
.invoke('attr', 'for')
.then((id) => {
cy.get('#' + id)
cy.get(`[id='${id}']`)
})
.get('img')
.should('be.visible')
Expand Down Expand Up @@ -194,7 +194,7 @@ describe('direct translation', () => {
cy.contains('label', 'Locales')
.invoke('attr', 'for')
.then((id) => {
cy.get('#' + id)
cy.get(`[id='${id}']`)
})
.click()
cy.contains('German (de)').click()
Expand Down
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),
}),
}
},
}
Loading

0 comments on commit e457cef

Please sign in to comment.