@interopio/iocd-cli 0.0.20 โ†’ 0.0.21

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": "@interopio/iocd-cli",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "CLI tool for setting up, building and packaging io.Connect Desktop platforms",
5
5
  "engines": {
6
6
  "node": ">=18.0.0",
@@ -40,7 +40,8 @@
40
40
  "author": "Interop.io",
41
41
  "license": "MIT",
42
42
  "files": [
43
- "dist/**/*",
43
+ "dist",
44
+ "scripts",
44
45
  "tools",
45
46
  "README.md"
46
47
  ],
@@ -0,0 +1,16 @@
1
+ const { cp } = require("fs/promises");
2
+
3
+ async function main() {
4
+ console.log("Copying template files...");
5
+ await cp("src/templates", "dist/templates", { recursive: true });
6
+ console.log("Template files copied successfully");
7
+
8
+ console.log("Copying tools files...");
9
+ await cp("tools", "dist/tools", { recursive: true });
10
+ console.log("Tools copied successfully");
11
+ }
12
+
13
+ main().catch(err => {
14
+ console.error(err);
15
+ process.exit(1);
16
+ });
@@ -0,0 +1,13 @@
1
+ // delete the dist folder before a new build
2
+ const { rm } = require("fs/promises");
3
+
4
+ async function main() {
5
+ console.log("Deleting dist folder...");
6
+ await rm("dist", { recursive: true, force: true });
7
+ console.log("Dist folder deleted successfully");
8
+ }
9
+
10
+ main().catch(err => {
11
+ console.error(err);
12
+ process.exit(1);
13
+ });
@@ -0,0 +1,158 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ /**
7
+ * Script to handle .gitignore template files for npm packaging
8
+ *
9
+ * Usage:
10
+ * - npm run pre-package: Copies .gitignore files to .gitignore.template
11
+ * - npm run post-publish: Removes .gitignore.template files
12
+ * - npm run post-install: Renames .gitignore.template back to .gitignore
13
+ */
14
+
15
+ const templatesDir = path.join(__dirname, '..', 'src', 'templates');
16
+ const distTemplatesDir = path.join(__dirname, '..', 'dist', 'templates');
17
+
18
+ function findGitignoreFiles(dir) {
19
+ const gitignoreFiles = [];
20
+
21
+ function walk(currentDir) {
22
+ if (!fs.existsSync(currentDir)) return;
23
+
24
+ const files = fs.readdirSync(currentDir);
25
+
26
+ for (const file of files) {
27
+ const filePath = path.join(currentDir, file);
28
+ const stat = fs.statSync(filePath);
29
+
30
+ if (stat.isDirectory()) {
31
+ walk(filePath);
32
+ } else if (file === '.gitignore') {
33
+ gitignoreFiles.push(filePath);
34
+ }
35
+ }
36
+ }
37
+
38
+ walk(dir);
39
+ return gitignoreFiles;
40
+ }
41
+
42
+ function findGitignoreTemplateFiles(dir) {
43
+ const templateFiles = [];
44
+
45
+ function walk(currentDir) {
46
+ if (!fs.existsSync(currentDir)) return;
47
+
48
+ const files = fs.readdirSync(currentDir);
49
+
50
+ for (const file of files) {
51
+ const filePath = path.join(currentDir, file);
52
+ const stat = fs.statSync(filePath);
53
+
54
+ if (stat.isDirectory()) {
55
+ walk(filePath);
56
+ } else if (file === '.gitignore.template') {
57
+ templateFiles.push(filePath);
58
+ }
59
+ }
60
+ }
61
+
62
+ walk(dir);
63
+ return templateFiles;
64
+ }
65
+
66
+ function copyGitignoreToTemplate() {
67
+ console.log('๐Ÿ“ฆ Pre-package: Converting .gitignore files to .gitignore.template files...');
68
+
69
+ // Handle both src and dist directories
70
+ const directories = [templatesDir, distTemplatesDir];
71
+ let totalFiles = 0;
72
+
73
+ for (const dir of directories) {
74
+ if (!fs.existsSync(dir)) continue;
75
+
76
+ const gitignoreFiles = findGitignoreFiles(dir);
77
+
78
+ for (const gitignoreFile of gitignoreFiles) {
79
+ const templateFile = gitignoreFile + '.template';
80
+
81
+ try {
82
+ fs.copyFileSync(gitignoreFile, templateFile);
83
+ console.log(`โœ… Copied: ${path.relative(process.cwd(), gitignoreFile)} โ†’ ${path.relative(process.cwd(), templateFile)}`);
84
+ totalFiles++;
85
+ } catch (error) {
86
+ console.error(`โŒ Failed to copy ${gitignoreFile}:`, error.message);
87
+ }
88
+ }
89
+ }
90
+
91
+ console.log(`๐Ÿ“ฆ Pre-package complete: ${totalFiles} .gitignore files converted to .template files`);
92
+ }
93
+
94
+ function removeTemplateFiles() {
95
+ console.log('๐Ÿงน Post-publish: Removing .gitignore.template files...');
96
+
97
+ // Handle both src and dist directories
98
+ const directories = [templatesDir, distTemplatesDir];
99
+ let totalFiles = 0;
100
+
101
+ for (const dir of directories) {
102
+ if (!fs.existsSync(dir)) continue;
103
+
104
+ const templateFiles = findGitignoreTemplateFiles(dir);
105
+
106
+ for (const templateFile of templateFiles) {
107
+ try {
108
+ fs.unlinkSync(templateFile);
109
+ console.log(`๐Ÿ—‘๏ธ Removed: ${path.relative(process.cwd(), templateFile)}`);
110
+ totalFiles++;
111
+ } catch (error) {
112
+ console.error(`โŒ Failed to remove ${templateFile}:`, error.message);
113
+ }
114
+ }
115
+ }
116
+
117
+ console.log(`๐Ÿงน Post-publish complete: ${totalFiles} .gitignore.template files removed`);
118
+ }
119
+
120
+ function convertTemplateToGitignore() {
121
+ console.log('๐Ÿ”„ Post-install: Converting .gitignore.template files back to .gitignore...');
122
+
123
+ // Only handle dist directory for post-install
124
+ const templateFiles = findGitignoreTemplateFiles(distTemplatesDir);
125
+ let totalFiles = 0;
126
+
127
+ for (const templateFile of templateFiles) {
128
+ const gitignoreFile = templateFile.replace('.template', '');
129
+
130
+ try {
131
+ fs.renameSync(templateFile, gitignoreFile);
132
+ console.log(`โœ… Converted: ${path.relative(process.cwd(), templateFile)} โ†’ ${path.relative(process.cwd(), gitignoreFile)}`);
133
+ totalFiles++;
134
+ } catch (error) {
135
+ console.error(`โŒ Failed to convert ${templateFile}:`, error.message);
136
+ }
137
+ }
138
+
139
+ console.log(`๐Ÿ”„ Post-install complete: ${totalFiles} .gitignore.template files converted back to .gitignore`);
140
+ }
141
+
142
+ // Parse command line arguments
143
+ const command = process.argv[2];
144
+
145
+ switch (command) {
146
+ case 'pre-package':
147
+ copyGitignoreToTemplate();
148
+ break;
149
+ case 'post-publish':
150
+ removeTemplateFiles();
151
+ break;
152
+ case 'post-install':
153
+ convertTemplateToGitignore();
154
+ break;
155
+ default:
156
+ console.error('Usage: node handle-gitignore-templates.js <pre-package|post-publish|post-install>');
157
+ process.exit(1);
158
+ }