deploy-webapp 1.0.6 → 1.0.7
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.
- package/install.js +61 -13
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -130,35 +130,83 @@ if (!fs.existsSync(migrateJsPath)) {
|
|
|
130
130
|
const packageJsonPath = path.join(projectRoot, 'package.json');
|
|
131
131
|
if (fs.existsSync(packageJsonPath)) {
|
|
132
132
|
try {
|
|
133
|
-
|
|
133
|
+
let packageJson = {};
|
|
134
|
+
const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8');
|
|
135
|
+
|
|
136
|
+
// Tentar parsear o JSON, se falhar criar um novo objeto
|
|
137
|
+
try {
|
|
138
|
+
packageJson = JSON.parse(packageJsonContent);
|
|
139
|
+
} catch (parseError) {
|
|
140
|
+
console.log('⚠️ deploy-webapp: package.json inválido, criando novo...');
|
|
141
|
+
packageJson = {};
|
|
142
|
+
}
|
|
143
|
+
|
|
134
144
|
let updated = false;
|
|
135
|
-
|
|
145
|
+
|
|
146
|
+
// Garantir que name e version existam
|
|
147
|
+
if (!packageJson.name) {
|
|
148
|
+
packageJson.name = path.basename(projectRoot);
|
|
149
|
+
updated = true;
|
|
150
|
+
}
|
|
151
|
+
if (!packageJson.version) {
|
|
152
|
+
packageJson.version = '1.0.0';
|
|
153
|
+
updated = true;
|
|
154
|
+
}
|
|
155
|
+
|
|
136
156
|
// Criar scripts se não existir
|
|
137
157
|
if (!packageJson.scripts) {
|
|
138
158
|
packageJson.scripts = {};
|
|
159
|
+
updated = true;
|
|
139
160
|
}
|
|
140
|
-
|
|
141
|
-
// Adicionar script start se não existir
|
|
142
|
-
if (!packageJson.scripts.start) {
|
|
161
|
+
|
|
162
|
+
// Adicionar script start se não existir ou se for diferente
|
|
163
|
+
if (!packageJson.scripts.start || packageJson.scripts.start !== 'node migrate.js') {
|
|
143
164
|
packageJson.scripts.start = 'node migrate.js';
|
|
144
165
|
updated = true;
|
|
145
166
|
}
|
|
146
|
-
|
|
147
|
-
// Adicionar script migrate se não existir
|
|
148
|
-
if (!packageJson.scripts.migrate) {
|
|
167
|
+
|
|
168
|
+
// Adicionar script migrate se não existir ou se for diferente
|
|
169
|
+
if (!packageJson.scripts.migrate || packageJson.scripts.migrate !== 'node migrate.js') {
|
|
149
170
|
packageJson.scripts.migrate = 'node migrate.js';
|
|
150
171
|
updated = true;
|
|
151
172
|
}
|
|
152
|
-
|
|
153
|
-
//
|
|
173
|
+
|
|
174
|
+
// Garantir que dependencies existe
|
|
175
|
+
if (!packageJson.dependencies) {
|
|
176
|
+
packageJson.dependencies = {};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Salvar sempre (mesmo que não tenha atualizado, garante formatação correta)
|
|
180
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n', 'utf8');
|
|
154
181
|
if (updated) {
|
|
155
|
-
|
|
156
|
-
|
|
182
|
+
console.log('✅ deploy-webapp: Scripts adicionados/atualizados no package.json!');
|
|
183
|
+
copiedCount++;
|
|
157
184
|
} else {
|
|
158
185
|
console.log('ℹ️ deploy-webapp: Scripts já existem no package.json.');
|
|
159
186
|
}
|
|
160
187
|
} catch (error) {
|
|
161
|
-
console.error('
|
|
188
|
+
console.error('❌ deploy-webapp: Erro ao atualizar package.json:', error.message);
|
|
189
|
+
console.error(' Stack:', error.stack);
|
|
190
|
+
}
|
|
191
|
+
} else {
|
|
192
|
+
// Se não existe package.json, criar um novo
|
|
193
|
+
try {
|
|
194
|
+
const newPackageJson = {
|
|
195
|
+
name: path.basename(projectRoot),
|
|
196
|
+
version: '1.0.0',
|
|
197
|
+
scripts: {
|
|
198
|
+
start: 'node migrate.js',
|
|
199
|
+
migrate: 'node migrate.js'
|
|
200
|
+
},
|
|
201
|
+
dependencies: {
|
|
202
|
+
'deploy-webapp': require(path.join(packagePath, 'package.json')).version || 'latest'
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(newPackageJson, null, 2) + '\n', 'utf8');
|
|
206
|
+
console.log('✅ deploy-webapp: package.json criado com scripts!');
|
|
207
|
+
copiedCount++;
|
|
208
|
+
} catch (error) {
|
|
209
|
+
console.error('❌ deploy-webapp: Erro ao criar package.json:', error.message);
|
|
162
210
|
}
|
|
163
211
|
}
|
|
164
212
|
|