sg-frontend-starter 1.0.8 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/postinstall.js +50 -32
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sg-frontend-starter",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",
package/postinstall.js CHANGED
@@ -13,48 +13,66 @@ const projectRoot = path.join(__dirname, '..', '..');
13
13
  const targetPackageJson = path.join(projectRoot, 'package.json');
14
14
  const sourcePackageJson = path.join(source, 'package.json');
15
15
 
16
+ // Az eredeti package.json tartalmát olvassuk be, mielőtt másolnánk
17
+ let templatePkg = null;
18
+ if (fs.existsSync(sourcePackageJson)) {
19
+ try {
20
+ const raw = fs.readFileSync(sourcePackageJson, 'utf8');
21
+ templatePkg = JSON.parse(raw);
22
+ } catch (error) {
23
+ console.error('Hiba az eredeti package.json beolvasása során:', error);
24
+ }
25
+ }
26
+
16
27
  if (fs.existsSync(source)) {
17
- // Az sg-frontend-starter mappájában lévő összes fájlt és mappát másolja ki
18
- const files = fs.readdirSync(source);
19
-
20
- files.forEach(file => {
21
- // Kihagyja a node_modules-t, package.json-t és magát a postinstall.js-t
22
- if (file !== 'node_modules' && file !== 'package.json' && file !== 'postinstall.js') {
23
- const srcPath = path.join(source, file);
24
- const destPath = path.join(projectRoot, file);
25
-
26
- if (fs.existsSync(destPath)) {
27
- fs.rmSync(destPath, { recursive: true, force: true });
28
- }
29
-
30
- // Másolja a fájlt/mappát
31
- const stat = fs.statSync(srcPath);
32
- if (stat.isDirectory()) {
33
- copyDir(srcPath, destPath);
34
- } else {
35
- fs.copyFileSync(srcPath, destPath);
28
+ // Az sg-frontend-starter mappájában lévő összes fájlt és mappát másolja ki
29
+ const files = fs.readdirSync(source);
30
+
31
+ files.forEach(file => {
32
+ // Kihagyja a node_modules-t, package.json-t és magát a postinstall.js-t
33
+ if (file !== 'node_modules' && file !== 'package.json' && file !== 'postinstall.js') {
34
+ const srcPath = path.join(source, file);
35
+ const destPath = path.join(projectRoot, file);
36
+
37
+ if (fs.existsSync(destPath)) {
38
+ fs.rmSync(destPath, { recursive: true, force: true });
39
+ }
40
+
41
+ // Másolja a fájlt/mappát
42
+ const stat = fs.statSync(srcPath);
43
+ if (stat.isDirectory()) {
44
+ copyDir(srcPath, destPath);
45
+ } else {
46
+ fs.copyFileSync(srcPath, destPath);
47
+ }
36
48
  }
37
- }
38
- });
39
-
40
- console.log('✓ sg-frontend-starter tartalma sikeresen áthelyezve');
49
+ });
50
+
51
+ console.log('✓ sg-frontend-starter tartalma sikeresen áthelyezve');
41
52
  }
42
53
 
43
- // Biztosítja, hogy a cél package.json megegyezzen a sablonnal
44
- syncPackageJson(targetPackageJson, sourcePackageJson);
54
+ // Biztosítja, hogy a cél package.json dependencies, devDependencies és scripts kulcsai a sablonnal egyezzenek
55
+ syncPackageJsonDependencies(targetPackageJson, templatePkg);
45
56
 
46
- function syncPackageJson(targetPath, templatePath) {
47
- if (!fs.existsSync(templatePath)) {
48
- console.error('Nem található a sablon package.json:', templatePath);
57
+ function syncPackageJsonDependencies(targetPath, templatePkg) {
58
+ if (!templatePkg) {
59
+ console.error('Nincs sablon package.json adat');
49
60
  return;
50
61
  }
51
62
 
52
63
  try {
53
- const templateRaw = fs.readFileSync(templatePath, 'utf8');
54
- const templatePkg = JSON.parse(templateRaw);
64
+ let targetPkg = {};
65
+ if (fs.existsSync(targetPath)) {
66
+ const targetRaw = fs.readFileSync(targetPath, 'utf8');
67
+ targetPkg = JSON.parse(targetRaw);
68
+ }
69
+
70
+ targetPkg.dependencies = templatePkg.dependencies || {};
71
+ targetPkg.devDependencies = templatePkg.devDependencies || {};
72
+ targetPkg.scripts = templatePkg.scripts || {};
55
73
 
56
- fs.writeFileSync(targetPath, JSON.stringify(templatePkg, null, 2) + '\n');
57
- console.log('✓ package.json szinkronizálva a sablonnal');
74
+ fs.writeFileSync(targetPath, JSON.stringify(targetPkg, null, 2) + '\n');
75
+ console.log('✓ package.json scripts/dependencies szinkronizálva a sablonnal');
58
76
  } catch (error) {
59
77
  console.error('Hiba a package.json szinkronizálása során:', error);
60
78
  }