clovie 0.1.42 → 0.1.43

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clovie",
3
- "version": "0.1.42",
3
+ "version": "0.1.43",
4
4
  "description": "Vintage web dev tooling with modern quality of life",
5
5
  "keywords": [
6
6
  "static-site-generator",
@@ -47,6 +47,7 @@
47
47
  "files": [
48
48
  "lib/**/*",
49
49
  "bin/**/*",
50
+ "scripts/**/*",
50
51
  "config/**/*",
51
52
  "templates/**/*",
52
53
  "README.md",
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Kill processes running on specific ports
3
+ * Cross-platform utility for terminating processes by port number
4
+ */
5
+
6
+ import { exec } from 'node:child_process';
7
+ import { promisify } from 'node:util';
8
+
9
+ const execAsync = promisify(exec);
10
+
11
+ /**
12
+ * Get the process ID running on a specific port
13
+ * @param {number} port - Port number to check
14
+ * @returns {Promise<number|null>} Process ID or null if not found
15
+ */
16
+ async function getProcessIdOnPort(port) {
17
+ try {
18
+ if (process.platform === 'win32') {
19
+ // Windows
20
+ const { stdout } = await execAsync(`netstat -ano | findstr :${port}`);
21
+ const lines = stdout.trim().split('\n');
22
+
23
+ for (const line of lines) {
24
+ if (line.includes(`:${port} `) && line.includes('LISTENING')) {
25
+ const parts = line.trim().split(/\s+/);
26
+ const pid = parts[parts.length - 1];
27
+ return parseInt(pid, 10);
28
+ }
29
+ }
30
+ } else {
31
+ // Unix-like systems (macOS, Linux)
32
+ const { stdout } = await execAsync(`lsof -ti:${port}`);
33
+ const pid = stdout.trim();
34
+ return pid ? parseInt(pid, 10) : null;
35
+ }
36
+ } catch (error) {
37
+ // Port not in use or command failed
38
+ return null;
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Kill a process by its ID
44
+ * @param {number} pid - Process ID to kill
45
+ * @returns {Promise<boolean>} True if killed successfully
46
+ */
47
+ async function killProcess(pid) {
48
+ try {
49
+ if (process.platform === 'win32') {
50
+ // Windows
51
+ await execAsync(`taskkill /PID ${pid} /F`);
52
+ } else {
53
+ // Unix-like systems
54
+ await execAsync(`kill -9 ${pid}`);
55
+ }
56
+ return true;
57
+ } catch (error) {
58
+ return false;
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Kill all processes running on the specified ports
64
+ * @param {number|number[]} ports - Port number(s) to kill processes on
65
+ * @param {Object} options - Options for killing
66
+ * @param {boolean} options.verbose - Show verbose output
67
+ * @returns {Promise<Object>} Result object with killed processes
68
+ */
69
+ export async function killPort(ports, options = {}) {
70
+ const { verbose = false } = options;
71
+ const portArray = Array.isArray(ports) ? ports : [ports];
72
+ const results = {
73
+ killed: [],
74
+ notFound: [],
75
+ errors: []
76
+ };
77
+
78
+ for (const port of portArray) {
79
+ try {
80
+ if (verbose) console.log(`Checking port ${port}...`);
81
+
82
+ const pid = await getProcessIdOnPort(port);
83
+
84
+ if (!pid) {
85
+ if (verbose) console.log(`No process found on port ${port}`);
86
+ results.notFound.push(port);
87
+ continue;
88
+ }
89
+
90
+ if (verbose) console.log(`Killing process ${pid} on port ${port}...`);
91
+
92
+ const killed = await killProcess(pid);
93
+
94
+ if (killed) {
95
+ if (verbose) console.log(`✅ Successfully killed process ${pid} on port ${port}`);
96
+ results.killed.push({ port, pid });
97
+ } else {
98
+ if (verbose) console.log(`❌ Failed to kill process ${pid} on port ${port}`);
99
+ results.errors.push({ port, pid, error: 'Kill command failed' });
100
+ }
101
+ } catch (error) {
102
+ if (verbose) console.log(`❌ Error checking port ${port}: ${error.message}`);
103
+ results.errors.push({ port, error: error.message });
104
+ }
105
+ }
106
+
107
+ return results;
108
+ }
109
+
110
+ /**
111
+ * Check what processes are running on specified ports
112
+ * @param {number|number[]} ports - Port number(s) to check
113
+ * @returns {Promise<Object>} Object with port information
114
+ */
115
+ export async function checkPorts(ports) {
116
+ const portArray = Array.isArray(ports) ? ports : [ports];
117
+ const results = {};
118
+
119
+ for (const port of portArray) {
120
+ const pid = await getProcessIdOnPort(port);
121
+ results[port] = {
122
+ inUse: !!pid,
123
+ pid: pid || null
124
+ };
125
+ }
126
+
127
+ return results;
128
+ }
129
+
130
+ /**
131
+ * Kill all common development ports (3000, 3001, 5000, 8000, 8080)
132
+ * @param {Object} options - Options for killing
133
+ * @returns {Promise<Object>} Result object
134
+ */
135
+ export async function killCommonPorts(options = {}) {
136
+ const commonPorts = [3000, 3001, 5000, 8000, 8080];
137
+ return killPort(commonPorts, options);
138
+ }
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { execSync } from 'child_process';
4
+ import { readFileSync, writeFileSync } from 'fs';
5
+ import { fileURLToPath } from 'url';
6
+ import { dirname, join } from 'path';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
10
+ const rootDir = join(__dirname, '..');
11
+
12
+ function run(command, options = {}) {
13
+ console.log(`\n> ${command}`);
14
+ try {
15
+ return execSync(command, {
16
+ stdio: 'inherit',
17
+ cwd: rootDir,
18
+ encoding: 'utf8',
19
+ ...options
20
+ });
21
+ } catch (error) {
22
+ console.error(`Failed to run: ${command}`);
23
+ process.exit(1);
24
+ }
25
+ }
26
+
27
+ function getPackageInfo() {
28
+ const packagePath = join(rootDir, 'package.json');
29
+ return JSON.parse(readFileSync(packagePath, 'utf8'));
30
+ }
31
+
32
+ function updateVersion(type = 'patch') {
33
+ console.log(`\n📦 Updating version (${type})...`);
34
+ run(`npm version ${type} --no-git-tag-version`);
35
+ return getPackageInfo().version;
36
+ }
37
+
38
+ function runTests() {
39
+ console.log('\n🧪 Running tests...');
40
+ run('npm test');
41
+ }
42
+
43
+ function dryRun() {
44
+ console.log('\n🔍 Running publish dry run...');
45
+ run('npm publish --dry-run');
46
+ }
47
+
48
+ function publish(tag = 'latest') {
49
+ console.log(`\n🚀 Publishing to NPM (tag: ${tag})...`);
50
+ const publishCmd = tag === 'latest'
51
+ ? 'npm publish'
52
+ : `npm publish --tag ${tag}`;
53
+ run(publishCmd);
54
+ }
55
+
56
+ function showPublishInfo() {
57
+ const pkg = getPackageInfo();
58
+ console.log('\n📋 Publish Information:');
59
+ console.log(` Package: ${pkg.name}@${pkg.version}`);
60
+ console.log(` License: ${pkg.license}`);
61
+ console.log(' Files to be published:');
62
+
63
+ try {
64
+ const result = execSync('npm pack --dry-run', {
65
+ cwd: rootDir,
66
+ encoding: 'utf8'
67
+ });
68
+ console.log(result);
69
+ } catch (error) {
70
+ console.log(' (Run "npm pack --dry-run" to see files)');
71
+ }
72
+ }
73
+
74
+ function buildDocs() {
75
+ console.log('\n📚 Building documentation...');
76
+ run('npm run docs:build');
77
+ }
78
+
79
+ function main() {
80
+ const args = process.argv.slice(2);
81
+ const command = args[0] || 'help';
82
+ const versionType = args[1] || 'patch';
83
+ const tag = args[1] || 'latest';
84
+
85
+ console.log('🍀 Clovie Publisher');
86
+ console.log('===================');
87
+
88
+ switch (command) {
89
+ case 'build':
90
+ console.log('No build step needed — shipping raw source.');
91
+ break;
92
+
93
+ case 'test':
94
+ runTests();
95
+ break;
96
+
97
+ case 'docs':
98
+ buildDocs();
99
+ break;
100
+
101
+ case 'dry-run':
102
+ runTests();
103
+ buildDocs();
104
+ dryRun();
105
+ showPublishInfo();
106
+ break;
107
+
108
+ case 'patch':
109
+ case 'minor':
110
+ case 'major':
111
+ const newVersion = updateVersion(command);
112
+ runTests();
113
+ buildDocs();
114
+ dryRun();
115
+ showPublishInfo();
116
+ console.log(`\n✅ Ready to publish version ${newVersion}`);
117
+ console.log('Run "npm run publish:do" to publish to NPM');
118
+ break;
119
+
120
+ case 'beta':
121
+ runTests();
122
+ buildDocs();
123
+ publish('beta');
124
+ break;
125
+
126
+ case 'do':
127
+ publish('latest');
128
+ break;
129
+
130
+ case 'info':
131
+ showPublishInfo();
132
+ break;
133
+
134
+ case 'help':
135
+ default:
136
+ console.log(`
137
+ 📚 Usage:
138
+ node scripts/publish.js [command] [options]
139
+
140
+ 🔧 Commands:
141
+ build - Build the project and check size
142
+ test - Run tests
143
+ docs - Build documentation
144
+ dry-run - Full dry run (build, test, docs, size check, npm dry-run)
145
+ patch|minor|major - Update version and prepare for publish
146
+ beta - Publish beta version
147
+ do - Publish to NPM (latest tag)
148
+ info - Show publish information
149
+ help - Show this help
150
+
151
+ 📝 Examples:
152
+ node scripts/publish.js dry-run # Test everything without publishing
153
+ node scripts/publish.js patch # Bump patch version and prepare
154
+ node scripts/publish.js beta # Publish beta version
155
+ node scripts/publish.js do # Publish to NPM
156
+
157
+ ⚠️ Note: Always run "dry-run" first to verify everything looks correct!
158
+ `);
159
+ break;
160
+ }
161
+ }
162
+
163
+ main();