Skip to content

Commit 4db69d7

Browse files
authored
Merge pull request #815 from evershopcommerce/theming
Theming
2 parents 18f76d0 + f2eae08 commit 4db69d7

10 files changed

Lines changed: 62 additions & 26 deletions

File tree

packages/evershop/src/bin/install/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { Pool } from 'pg';
1515
import { CONSTANTS } from '../../lib/helpers.js';
1616
import { error, success } from '../../lib/log/logger.js';
1717
import { hashPassword } from '../../lib/util/passwordHelper.js';
18+
import { getCoreModules } from '../lib/loadModules.js';
19+
import { migrate } from '../lib/bootstrap/migrate.js';
1820

1921
// The installation command will create a .env file in the root directory of the project.
2022
// If you are using docker, do not run this command. Instead, you should set the environment variables in the docker-compose.yml file and run `npm run start`
@@ -252,6 +254,10 @@ DB_SSLMODE="${sslMode}"
252254
full_name: adminUser?.fullName || 'Admin'
253255
})
254256
.execute(connection);
257+
258+
// Run module migrations
259+
const coreModules = getCoreModules();
260+
await migrate(coreModules, connection);
255261
await commit(connection);
256262
} catch (e) {
257263
await rollback(connection);

packages/evershop/src/bin/lib/bootstrap/migrate.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ import { error } from '../../../lib/log/logger.js';
1313
import { getConnection, pool } from '../../../lib/postgres/connection.js';
1414
import { createMigrationTable } from '../../install/createMigrationTable.js';
1515

16-
async function getCurrentInstalledVersion(module) {
16+
async function getCurrentInstalledVersion(module, connection = null) {
1717
/** Check for current installed version */
1818
const check = await select()
1919
.from('migration')
2020
.where('module', '=', module)
21-
.load(pool);
21+
.load(connection || pool);
2222
if (!check) {
2323
return '0.0.1';
2424
} else {
2525
return check.version;
2626
}
2727
}
2828

29-
async function migrateModule(module) {
29+
async function migrateModule(module, connection = null) {
3030
/** Check if the module has migration folder, if not ignore it */
3131
if (!existsSync(path.resolve(module.path, 'migration'))) {
3232
return;
@@ -42,15 +42,20 @@ async function migrateModule(module) {
4242
.map((dirent) => dirent.name.replace('Version-', '').replace('.js', ''))
4343
.sort((first, second) => semver.lt(first, second));
4444

45-
const currentInstalledVersion = await getCurrentInstalledVersion(module.name);
45+
const currentInstalledVersion = await getCurrentInstalledVersion(
46+
module.name,
47+
connection
48+
);
4649

4750
for (const version of migrations) {
4851
/** If the version is lower or equal the installed version, ignore it */
4952
if (semver.lte(version, currentInstalledVersion)) {
5053
continue;
5154
}
52-
const connection = await getConnection();
53-
await startTransaction(connection);
55+
const migrationConnection = connection || (await getConnection());
56+
if (!connection) {
57+
await startTransaction(migrationConnection);
58+
}
5459

5560
/** We expect the migration script to provide a function as a default export */
5661
try {
@@ -59,32 +64,36 @@ async function migrateModule(module) {
5964
path.resolve(module.path, 'migration', `Version-${version}.js`)
6065
)
6166
);
62-
await versionModule.default(connection);
67+
await versionModule.default(migrationConnection);
6368

6469
await insertOnUpdate('migration', ['module'])
6570
.given({
6671
module: module.name,
6772
version
6873
})
69-
.execute(connection, false);
70-
await commit(connection);
74+
.execute(migrationConnection, false);
75+
if (!connection) {
76+
await commit(migrationConnection);
77+
}
7178
} catch (e) {
72-
await rollback(connection);
79+
if (!connection) {
80+
await rollback(migrationConnection);
81+
}
7382
throw new Error(
7483
`Migration failed for module ${module.name}, version ${version}\n${e}`
7584
);
7685
}
7786
}
7887
}
7988

80-
export async function migrate(modules) {
89+
export async function migrate(modules, connection = null) {
8190
try {
82-
const connection = await getConnection();
91+
const psqlConnection = connection || (await getConnection());
8392
// Create a migration table if not exists. This is for the first time installation
84-
await createMigrationTable(connection);
93+
await createMigrationTable(psqlConnection);
8594

8695
for (const module of modules) {
87-
await migrateModule(module);
96+
await migrateModule(module, connection);
8897
}
8998
} catch (e) {
9099
error(e);

packages/evershop/src/bin/seed/data/pages.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
"time": 1729900000000,
1515
"blocks": [
1616
{
17-
"id": "about_us_h1",
17+
"id": "about_us_h2",
1818
"type": "header",
1919
"data": {
2020
"text": "Welcome to Our Store",
21-
"level": 1
21+
"level": 2
2222
}
2323
},
2424
{
@@ -41,7 +41,7 @@
4141
"type": "image",
4242
"data": {
4343
"file": {
44-
"url": "https://raw.githubusercontent.com/vercel/next.js/refs/heads/canary/examples/blog/public/images/photo.jpg"
44+
"url": "https://raw.githubusercontent.com/evershopcommerce/evershop/refs/heads/dev/seed/images/banner-one.jpg"
4545
},
4646
"caption": "Our carefully curated collection",
4747
"withBorder": false,

packages/evershop/src/bin/seed/data/widgets.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"slides": [
5050
{
5151
"id": "slide-1",
52-
"image": "https://raw.githubusercontent.com/vercel/next.js/refs/heads/canary/examples/blog/public/images/photo.jpg",
52+
"image": "https://raw.githubusercontent.com/evershopcommerce/evershop/refs/heads/dev/seed/images/banner-one.jpg",
5353
"width": 2400,
5454
"height": 800,
5555
"subText": "Discover our exquisite collection of ceramic and stainless steel products",
@@ -60,7 +60,7 @@
6060
},
6161
{
6262
"id": "slide-2",
63-
"image": "https://raw.githubusercontent.com/vercel/next.js/refs/heads/canary/examples/blog/public/images/photo2.jpg",
63+
"image": "https://raw.githubusercontent.com/evershopcommerce/evershop/refs/heads/dev/seed/images/banner-two.jpg",
6464
"width": 2400,
6565
"height": 800,
6666
"subText": "Elegant designs that enhance your daily life, from morning coffee to home organization",
@@ -76,5 +76,17 @@
7676
"autoplaySpeed": 3000
7777
},
7878
"status": true
79+
},
80+
{
81+
"name": "Featured Products",
82+
"type": "collection_products",
83+
"route": ["homepage"],
84+
"area": ["content"],
85+
"sort_order": 20,
86+
"settings": {
87+
"count": 4,
88+
"collection": "homepage"
89+
},
90+
"status": true
7991
}
8092
]

packages/evershop/src/bin/seed/imageDownloader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function convertToMediaPath(localPath: string): string {
102102
// e.g., /path/to/media/widgets/slide-1.jpg -> /media/widgets/slide-1.jpg
103103
const mediaMatch = localPath.match(/media\/(.+)$/);
104104
if (mediaMatch) {
105-
return `/media/${mediaMatch[1]}`;
105+
return `/assets/${mediaMatch[1]}`;
106106
}
107107
return localPath;
108108
}

packages/evershop/src/bin/seed/seedWidgets.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
getFilenameFromUrl,
1010
convertToMediaPath
1111
} from './imageDownloader.js';
12+
import { CONSTANTS } from '../../lib/helpers.js';
1213

1314
const __filename = fileURLToPath(import.meta.url);
1415
const __dirname = dirname(__filename);
@@ -53,8 +54,12 @@ async function downloadSlideshowImages(
5354
const slideId = slide.id || `slide-${Date.now()}`;
5455

5556
// Create local path
56-
const projectRoot = resolve(__dirname, '../../../../..');
57-
const mediaDir = join(projectRoot, 'media', 'widgets', slideId);
57+
const mediaDir = join(
58+
CONSTANTS.ROOTPATH,
59+
'media',
60+
'widgets',
61+
slideId
62+
);
5863

5964
// Ensure directory exists
6065
if (!existsSync(mediaDir)) {
@@ -126,7 +131,7 @@ export async function seedWidgets(): Promise<void> {
126131

127132
// Process settings - download slideshow images if needed
128133
let processedSettings = widgetData.settings;
129-
if (widgetData.type === 'slideshow') {
134+
if (widgetData.type === 'simple_slider') {
130135
info(` → Processing slideshow images for: ${widgetData.name}`);
131136
processedSettings = await downloadSlideshowImages(widgetData.settings);
132137
}

packages/evershop/src/modules/base/pages/frontStore/all/global.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ html {
6464
body {
6565
color: #3a3a3a;
6666
}
67-
p {
68-
margin-bottom: 0.625rem;
67+
.header {
68+
padding-top: 1rem;
69+
padding-bottom: 1rem;
6970
}
7071
@media screen and (max-width: 767px) {
7172
$font-size-base: $font-size-sm;

packages/evershop/src/modules/cms/services/tailwind.frontStore.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import plugin from '@tailwindcss/typography';
2+
13
export default {
24
theme: {
35
extend: {
@@ -30,5 +32,6 @@ export default {
3032
margin: ['first', 'last'],
3133
padding: ['first', 'last']
3234
}
33-
}
35+
},
36+
plugins: [plugin]
3437
};

seed/images/banner-one.jpg

971 KB
Loading

seed/images/banner-two.jpg

919 KB
Loading

0 commit comments

Comments
 (0)