-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-production.js
More file actions
149 lines (120 loc) · 4.03 KB
/
build-production.js
File metadata and controls
149 lines (120 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import fs from 'node:fs';
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import archiver from 'archiver';
const DEFAULT_BUILD_CONFIG = {
BUILD_DIR: './build',
ZIP_NAME: 'volume-for-b-production.zip'
};
async function loadBuildConfig() {
const configPath = path.resolve('./build.config.js');
if (!fs.existsSync(configPath)) {
console.log('ℹ️ build.config.js não encontrado. Usando configuração padrão.');
console.log('ℹ️ Se quiser personalizar o build, copie build.config.example.js para build.config.js');
return DEFAULT_BUILD_CONFIG;
}
const configModule = await import(pathToFileURL(configPath).href);
return {
...DEFAULT_BUILD_CONFIG,
...(configModule.default ?? configModule)
};
}
const { BUILD_DIR, ZIP_NAME } = await loadBuildConfig();
console.log('🚀 Iniciando build de produção da extensão Volume for B...');
function setupBuildDir() {
if (fs.existsSync(BUILD_DIR)) {
console.log('🧹 Limpando build anterior...');
fs.rmSync(BUILD_DIR, { recursive: true, force: true });
}
fs.mkdirSync(BUILD_DIR, { recursive: true });
}
function copyFiles() {
console.log('📦 Copiando arquivos necessários...');
const filesToCopy = [
'manifest.json',
'popup.html',
'popup.css',
'popup.js',
'sw.js',
'offscreen.html',
'offscreen.js',
'README.md',
'LICENSE',
'PRIVACY.md',
'SUPPORT.md',
'SECURITY.md'
];
filesToCopy.forEach(file => {
if (fs.existsSync(file)) {
fs.copyFileSync(file, path.join(BUILD_DIR, file));
}
});
if (fs.existsSync('icons')) {
fs.cpSync('icons', path.join(BUILD_DIR, 'icons'), { recursive: true });
}
if (fs.existsSync('_locales')) {
fs.cpSync('_locales', path.join(BUILD_DIR, '_locales'), { recursive: true });
}
}
function updateManifest() {
console.log('🆔 Atualizando manifest...');
const manifestPath = path.join(BUILD_DIR, 'manifest.json');
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
console.log(`✅ Versão preparada para publicação: ${manifest.version}`);
}
function createZip() {
return new Promise((resolve, reject) => {
console.log('🗜️ Criando arquivo ZIP...');
if (fs.existsSync(ZIP_NAME)) {
fs.unlinkSync(ZIP_NAME);
}
const output = fs.createWriteStream(ZIP_NAME);
const archive = archiver('zip', { zlib: { level: 9 } });
output.on('close', () => {
const sizeInMB = (archive.pointer() / 1024 / 1024).toFixed(2);
console.log(`📊 Arquivo ZIP criado: ${sizeInMB} MB`);
resolve();
});
output.on('error', reject);
archive.on('error', reject);
archive.pipe(output);
archive.directory(BUILD_DIR, false);
archive.finalize();
});
}
function validateBuild() {
console.log('📋 Validando build...');
const requiredFiles = [
'manifest.json', 'popup.html', 'popup.css', 'popup.js',
'sw.js', 'offscreen.html', 'offscreen.js', 'icons', '_locales'
];
for (const file of requiredFiles) {
const filePath = path.join(BUILD_DIR, file);
if (!fs.existsSync(filePath)) {
throw new Error(`❌ Arquivo obrigatório não encontrado: ${file}`);
}
}
console.log('✅ Todos os arquivos necessários estão presentes');
}
async function build() {
try {
setupBuildDir();
copyFiles();
updateManifest();
validateBuild();
await createZip();
console.log('\n🎉 Build de produção concluído com sucesso!');
console.log(`📦 Arquivo gerado: ${ZIP_NAME}`);
console.log('\n📝 Próximos passos:');
console.log(` 1. Faça upload do arquivo '${ZIP_NAME}' na Chrome Web Store`);
console.log(' 2. Configure as informações da listagem');
console.log(' 3. Submeta para revisão');
console.log('\n🔗 Chrome Web Store Developer Dashboard:');
console.log(' https://chrome.google.com/webstore/devconsole');
} catch (error) {
console.error('❌ Erro durante o build:', error.message);
globalThis.process.exit(1);
}
}
await build();