-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathrelease.js
More file actions
149 lines (126 loc) · 4.31 KB
/
release.js
File metadata and controls
149 lines (126 loc) · 4.31 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
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
const fs = require('node:fs');
const path = require('node:path');
const archiver = require('archiver');
const argv = require('minimist')(process.argv.slice(2));
const deleteFilesByExtension = (dir, ext) => {
if (!fs.existsSync(dir)) {
return;
}
const files = fs.readdirSync(dir);
for (const file of files) {
const filePath = path.join(dir, file);
const stat = fs.lstatSync(filePath);
if (stat.isDirectory()) {
deleteFilesByExtension(filePath, ext);
} else if (filePath.endsWith(ext)) {
fs.unlinkSync(filePath);
}
}
};
const main = async () => {
const platform = argv.platform;
if (platform && typeof platform !== 'string') {
console.error(
'Error: The --platform argument must be a string (e.g., --platform=linux).'
);
process.exit(1);
}
const baseName = 'google-workspace-extension';
const name = platform ? `${platform}.${baseName}` : baseName;
const extension = 'tar.gz';
const rootDir = path.join(__dirname, '..');
const releaseDir = path.join(rootDir, 'release');
fs.rmSync(releaseDir, { recursive: true, force: true });
const archiveName = `${name}.${extension}`;
const archiveDir = path.join(releaseDir, name);
const workspaceMcpServerDir = path.join(rootDir, 'workspace-server');
// Create the release directory
fs.mkdirSync(releaseDir, { recursive: true });
// Create the platform-specific directory
fs.mkdirSync(archiveDir, { recursive: true });
// Copy the dist directory
fs.cpSync(
path.join(workspaceMcpServerDir, 'dist'),
path.join(archiveDir, 'dist'),
{ recursive: true }
);
// Clean up the dist directory
const distDir = path.join(archiveDir, 'dist');
deleteFilesByExtension(distDir, '.d.ts');
deleteFilesByExtension(distDir, '.map');
fs.rmSync(path.join(distDir, '__tests__'), { recursive: true, force: true });
fs.rmSync(path.join(distDir, 'auth'), { recursive: true, force: true });
fs.rmSync(path.join(distDir, 'services'), { recursive: true, force: true });
fs.rmSync(path.join(distDir, 'utils'), { recursive: true, force: true });
// Copy native modules and dependencies (keytar, jsdom)
const nodeModulesDir = path.join(archiveDir, 'node_modules');
fs.mkdirSync(nodeModulesDir, { recursive: true });
const { getTransitiveDependencies } = require('./utils/dependencies');
const visited = getTransitiveDependencies(rootDir, ['keytar', 'jsdom']);
visited.forEach(pkg => {
const source = path.join(rootDir, 'node_modules', pkg);
const dest = path.join(nodeModulesDir, pkg);
if (fs.existsSync(source)) {
fs.cpSync(source, dest, { recursive: true });
}
});
const packageJson = require('../package.json');
const version = process.env.GITHUB_REF_NAME || packageJson.version;
// Generate the gemini-extension.json file
const geminiExtensionJson = {
name: 'google-workspace',
version,
contextFileName: 'WORKSPACE-Context.md',
mcpServers: {
'google-workspace': {
command: 'node',
args: ['dist/index.js'],
cwd: '${extensionPath}',
},
},
};
fs.writeFileSync(
path.join(archiveDir, 'gemini-extension.json'),
JSON.stringify(geminiExtensionJson, null, 2)
);
// Copy the WORKSPACE-Context.md file
fs.copyFileSync(
path.join(workspaceMcpServerDir, 'WORKSPACE-Context.md'),
path.join(archiveDir, 'WORKSPACE-Context.md')
);
// Copy the commands directory
const commandsDir = path.join(rootDir, 'commands');
if (fs.existsSync(commandsDir)) {
fs.cpSync(commandsDir, path.join(archiveDir, 'commands'), { recursive: true });
}
// Create the archive
const output = fs.createWriteStream(path.join(releaseDir, archiveName));
const archive = archiver('tar', {
gzip: true,
});
const archivePromise = new Promise((resolve, reject) => {
output.on('close', function () {
console.log(archive.pointer() + ' total bytes');
console.log(
'archiver has been finalized and the output file descriptor has closed.'
);
resolve();
});
archive.on('error', function (err) {
reject(err);
});
});
archive.pipe(output);
archive.directory(archiveDir, false);
archive.finalize();
await archivePromise;
};
main().catch(err => {
console.error(err);
process.exit(1);
});