-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
104 lines (88 loc) · 3.59 KB
/
Copy pathbuild.js
File metadata and controls
104 lines (88 loc) · 3.59 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
#!/usr/bin/env node
/**
* build.js
* Reads config.json and injects values into manifest.json,
* then zips the extension into dist/gcal-clickup-importer.zip
*
* Usage:
* node build.js
*
* Requirements:
* npm install archiver (only needed for zip output)
*/
const fs = require('fs');
const path = require('path');
const ROOT = __dirname;
const MANIFEST = path.join(ROOT, 'manifest.json');
const CONFIG = path.join(ROOT, 'config.json');
const DIST = path.join(ROOT, 'dist');
const OUT_MANIFEST = path.join(DIST, 'manifest.json');
// ── 1. Load config ────────────────────────────────────────────────────────────
if (!fs.existsSync(CONFIG)) {
console.error('ERROR: config.json not found. Copy config.json.example to config.json and fill in your values.');
process.exit(1);
}
const config = JSON.parse(fs.readFileSync(CONFIG, 'utf8'));
if (!config.google_client_id || config.google_client_id.includes('YOUR_CLIENT_ID')) {
console.error('ERROR: config.json still has a placeholder. Set google_client_id to your real OAuth client ID.');
process.exit(1);
}
// ── 2. Inject into manifest ───────────────────────────────────────────────────
let manifest = fs.readFileSync(MANIFEST, 'utf8');
manifest = manifest.replace('{{GOOGLE_CLIENT_ID}}', config.google_client_id);
const parsed = JSON.parse(manifest); // validate JSON
if (parsed.oauth2.client_id.includes('{{')) {
console.error('ERROR: Placeholder not replaced. Check config.json.');
process.exit(1);
}
// ── 3. Write to dist/ ─────────────────────────────────────────────────────────
if (!fs.existsSync(DIST)) fs.mkdirSync(DIST);
// Copy all extension files to dist/
const FILES = [
'background.js',
'content.js',
'options.html',
'options.js',
'options.css',
'popup.html',
'popup.js',
'popup.css',
'README.md'
];
// Copy icons folder
const ICONS_SRC = path.join(ROOT, 'icons');
const ICONS_DST = path.join(DIST, 'icons');
if (fs.existsSync(ICONS_SRC)) {
if (!fs.existsSync(ICONS_DST)) fs.mkdirSync(ICONS_DST);
fs.readdirSync(ICONS_SRC).forEach(f => {
fs.copyFileSync(path.join(ICONS_SRC, f), path.join(ICONS_DST, f));
});
}
FILES.forEach(f => {
const src = path.join(ROOT, f);
if (fs.existsSync(src)) {
fs.copyFileSync(src, path.join(DIST, f));
}
});
// Write the injected manifest into dist/
fs.writeFileSync(OUT_MANIFEST, JSON.stringify(parsed, null, 2));
console.log('✓ Built to dist/');
console.log(' client_id:', config.google_client_id);
// ── 4. Optionally zip dist/ ───────────────────────────────────────────────────
try {
const archiver = require('archiver');
const output = fs.createWriteStream(path.join(ROOT, 'dist', 'gcal-clickup-importer.zip'));
const archive = archiver('zip', { zlib: { level: 9 } });
output.on('close', () => {
console.log('✓ Zipped:', archive.pointer(), 'bytes →', 'dist/gcal-clickup-importer.zip');
});
archive.pipe(output);
FILES.forEach(f => {
const p = path.join(DIST, f);
if (fs.existsSync(p)) archive.file(p, { name: f });
});
archive.file(OUT_MANIFEST, { name: 'manifest.json' });
archive.finalize();
} catch (e) {
console.log(' (Skipping zip — run "npm install archiver" to enable auto-zip)');
}