-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostbuild.js
More file actions
32 lines (26 loc) · 1.09 KB
/
postbuild.js
File metadata and controls
32 lines (26 loc) · 1.09 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
#!/usr/bin/env node
import { chmodSync, cpSync, mkdirSync, writeFileSync } from "fs";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Create bin/package.json to mark the directory as CommonJS
const binPackageJson = {
type: "commonjs",
};
const binPackageJsonPath = join(__dirname, "bin", "package.json");
writeFileSync(binPackageJsonPath, JSON.stringify(binPackageJson, null, 2));
// Create bin/plot.cjs wrapper that executes bin/index.js
const wrapperContent = `#!/usr/bin/env node
// This is a wrapper that runs the compiled CLI
require('./index.js');
`;
const binPath = join(__dirname, "bin", "plot.cjs");
writeFileSync(binPath, wrapperContent);
chmodSync(binPath, 0o755);
// Copy templates directory to bin
const templatesSource = join(__dirname, "cli", "templates");
const templatesDestination = join(__dirname, "bin", "templates");
mkdirSync(templatesDestination, { recursive: true });
cpSync(templatesSource, templatesDestination, { recursive: true });
console.log("✓ Built CLI");