vue-cli-plugin-electron-haunv 1.0.10 → 1.0.12

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/generator/index.js +26 -38
  2. package/package.json +1 -1
@@ -55,48 +55,36 @@ module.exports = (api) => {
55
55
  const fs = require("fs")
56
56
  const configPath = api.resolve("vue.config.js")
57
57
 
58
- // 🟢 chưa có file → tạo mới
59
- if (!fs.existsSync(configPath)) {
60
- fs.writeFileSync(
61
- configPath,
62
- `module.exports = {
63
- publicPath: "./"
64
- }
65
- `
66
- )
67
- console.log("🆕 Created vue.config.js with publicPath")
68
- return
69
- }
58
+ setTimeout(() => {
59
+ if (!fs.existsSync(configPath)) {
60
+ console.log("⚠️ vue.config.js not found")
61
+ return
62
+ }
70
63
 
71
- let content = fs.readFileSync(configPath, "utf-8")
64
+ let content = fs.readFileSync(configPath, "utf-8")
72
65
 
73
- // 🟢 đã có publicPath → bỏ qua
74
- if (content.includes("publicPath")) {
75
- console.log("ℹ️ publicPath already exists")
76
- return
77
- }
66
+ if (content.includes("publicPath")) {
67
+ console.log("ℹ️ already has publicPath")
68
+ return
69
+ }
78
70
 
79
- // 🟢 inject vào module.exports
80
- if (content.includes("module.exports")) {
81
- content = content.replace(
82
- /module\.exports\s*=\s*{/,
83
- `module.exports = {\n publicPath: "./",`
84
- )
85
- }
86
- // 🟡 fallback nếu là export default
87
- else if (content.includes("export default")) {
88
- content = content.replace(
89
- /export\s+default\s*{/,
90
- `export default {\n publicPath: "./",`
91
- )
92
- }
93
- // 🔴 fallback cuối: append luôn
94
- else {
95
- content += `\n\nmodule.exports = {\n publicPath: "./"\n}\n`
96
- }
71
+ // 👉 tìm dấu } cuối cùng
72
+ const lastIndex = content.lastIndexOf("}")
73
+
74
+ if (lastIndex === -1) {
75
+ console.log("❌ cannot find end of config")
76
+ return
77
+ }
78
+
79
+ // 👉 chèn trước dấu }
80
+ content =
81
+ content.slice(0, lastIndex) +
82
+ `,\n publicPath: "./"\n` +
83
+ content.slice(lastIndex)
97
84
 
98
- fs.writeFileSync(configPath, content)
85
+ fs.writeFileSync(configPath, content, "utf-8")
99
86
 
100
- console.log(" Injected publicPath into vue.config.js")
87
+ console.log(" Inject success REAL")
88
+ }, 500)
101
89
  })
102
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-cli-plugin-electron-haunv",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "keywords": [