kishare 1.0.0 → 1.0.2

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": "kishare",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "description": "CLI tool for generating static KiCad project viewer sites",
6
6
  "homepage": "https://github.com/hmcty/kishare",
@@ -13,12 +13,9 @@
13
13
  "vite"
14
14
  ],
15
15
  "files": [
16
- "bin",
17
- "src",
18
- "vendor/kicanvas/build",
19
- "index.html",
20
- "vite.config.ts",
21
- "tsconfig.json"
16
+ "bin/",
17
+ "src/",
18
+ "vendor/kicanvas/build/kicanvas.js"
22
19
  ],
23
20
  "scripts": {
24
21
  "setup": "cd ./vendor/kicanvas && npm install && npm run build",
@@ -48,6 +45,10 @@
48
45
  "marked": "^17.0.6",
49
46
  "marked-base-url": "^1.1.8",
50
47
  "tsx": "^4.7.2",
51
- "vite": "^5.2.8"
52
- }
48
+ "vite": "^5.2.8",
49
+ "kicanvas": "file:vendor/kicanvas"
50
+ },
51
+ "bundledDependencies": [
52
+ "kicanvas"
53
+ ]
53
54
  }
@@ -89,19 +89,57 @@ export function getKishareRootDir(): string {
89
89
  return KISHARE_ROOT;
90
90
  }
91
91
 
92
+ // Find the git repository root directory
93
+ function findGitRoot(startDir: string): string | null {
94
+ try {
95
+ const gitRoot = execSync('git rev-parse --show-toplevel', {
96
+ cwd: startDir,
97
+ encoding: 'utf-8',
98
+ stdio: ['pipe', 'pipe', 'pipe'],
99
+ }).trim();
100
+ return gitRoot;
101
+ } catch {
102
+ return null;
103
+ }
104
+ }
105
+
92
106
  // Get list of git-tracked files in the specified project directories
93
107
  export function getTrackedFiles(projectDirs: string[]): Set<string> {
94
108
  const allFiles = new Set<string>();
109
+
110
+ // Find the git root - it might be above ROOT_DIR (e.g., when ROOT_DIR is a subdirectory)
111
+ const gitRoot = findGitRoot(getRootDir());
112
+ if (!gitRoot) {
113
+ console.warn('Not in a git repository, cannot get tracked files');
114
+ return allFiles;
115
+ }
116
+
95
117
  for (const projectDir of projectDirs) {
96
118
  try {
97
- const relativeDir = path.relative(getRootDir(), projectDir);
98
- console.log(`Getting git tracked files for ${relativeDir}...`);
99
- const output = execSync(`git ls-files --recurse-submodules "${relativeDir}/"`, {
100
- cwd: getRootDir(),
119
+ // Get path relative to git root for the git command
120
+ const relativeToGit = path.relative(gitRoot, projectDir);
121
+ // Get path relative to ROOT_DIR for the output
122
+ const relativeToRoot = path.relative(getRootDir(), projectDir);
123
+
124
+ console.log(`Getting git tracked files for ${relativeToRoot}...`);
125
+ const output = execSync(`git ls-files --recurse-submodules "${relativeToGit}/"`, {
126
+ cwd: gitRoot,
101
127
  encoding: 'utf-8',
102
128
  });
103
129
 
104
- output.trim().split('\n').filter(f => f).forEach(f => allFiles.add(f));
130
+ // Convert paths from git-root-relative to ROOT_DIR-relative
131
+ const gitRootToRootDir = path.relative(gitRoot, getRootDir());
132
+
133
+ output.trim().split('\n').filter(f => f).forEach(gitRelativePath => {
134
+ // Convert: path relative to git root -> path relative to ROOT_DIR
135
+ const absolutePath = path.join(gitRoot, gitRelativePath);
136
+ const rootRelativePath = path.relative(getRootDir(), absolutePath);
137
+
138
+ // Only include if the file is within ROOT_DIR (not above it)
139
+ if (!rootRelativePath.startsWith('..')) {
140
+ allFiles.add(rootRelativePath);
141
+ }
142
+ });
105
143
  } catch (error) {
106
144
  console.warn(`Could not get git tracked files for ${projectDir}`);
107
145
  }
package/index.html DELETED
@@ -1,15 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data: blob:; connect-src 'self'; font-src 'self' https://fonts.gstatic.com; worker-src 'self' blob:; object-src 'none'; base-uri 'self'; form-action 'self';">
7
- <title>KiShare Workspace</title>
8
- </head>
9
- <body>
10
- <workspace-app></workspace-app>
11
-
12
- <script type="module" src="/kicanvas/kicanvas.js"></script>
13
- <script type="module" src="/src/main.ts"></script>
14
- </body>
15
- </html>
package/tsconfig.json DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "useDefineForClassFields": true,
5
- "module": "ESNext",
6
- "lib": ["ES2020", "DOM", "DOM.Iterable"],
7
- "skipLibCheck": true,
8
-
9
- /* Bundler mode */
10
- "moduleResolution": "bundler",
11
- "allowImportingTsExtensions": true,
12
- "resolveJsonModule": true,
13
- "isolatedModules": true,
14
- "noEmit": true,
15
-
16
- /* Linting */
17
- "strict": true,
18
- "noUnusedLocals": true,
19
- "noUnusedParameters": true,
20
- "noFallthroughCasesInSwitch": true,
21
- "esModuleInterop": true,
22
- "allowSyntheticDefaultImports": true,
23
- "forceConsistentCasingInFileNames": true
24
- },
25
- "include": ["src"]
26
- }
@@ -1,48 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- /* Visit https://aka.ms/tsconfig to read more about this file */
4
- /* Language and Environment */
5
- "target": "es2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
6
- "moduleResolution": "bundler",
7
- // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
8
- "experimentalDecorators": true,
9
- "useDefineForClassFields": false, // Required to use experimental decorators
10
- /* Modules */
11
- "module": "es2022" /* Specify what module code is generated. */,
12
- "allowImportingTsExtensions": true,
13
- "verbatimModuleSyntax": true,
14
- "allowArbitraryExtensions": true,
15
- /* JavaScript Support */
16
- "allowJs": true /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */,
17
- "checkJs": true /* Enable error reporting in type-checked JavaScript files. */,
18
- /* Emit */
19
- // "outDir": "./build", /* Specify an output folder for all emitted files. */
20
- // "sourceMap": true,
21
- "noEmit": true /* Disable emitting files from a compilation. */,
22
- /* Interop Constraints */
23
- // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
24
- "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
25
- /* Type Checking */
26
- // "strict": true, /* Enable all strict type-checking options. */
27
- "noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied 'any' type. */,
28
- "strictNullChecks": true /* When type checking, take into account 'null' and 'undefined'. */,
29
- "strictFunctionTypes": true /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */,
30
- "strictBindCallApply": true /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */,
31
- // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
32
- "noImplicitThis": true /* Enable error reporting when 'this' is given the type 'any'. */,
33
- "useUnknownInCatchVariables": true /* Default catch clause variables as 'unknown' instead of 'any'. */,
34
- "alwaysStrict": true /* Ensure 'use strict' is always emitted. */,
35
- "noUnusedLocals": true /* Enable error reporting when local variables aren't read. */,
36
- // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
37
- // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
38
- "noImplicitReturns": true /* Enable error reporting for codepaths that do not explicitly return in a function. */,
39
- "noFallthroughCasesInSwitch": true /* Enable error reporting for fallthrough cases in switch statements. */,
40
- "noUncheckedIndexedAccess": true /* Add 'undefined' to a type when accessed using an index. */,
41
- "noImplicitOverride": true /* Ensure overriding members in derived classes are marked with an override modifier. */,
42
- "noPropertyAccessFromIndexSignature": true /* Enforces using indexed accessors for keys declared using an indexed type. */,
43
- "allowUnusedLabels": false,
44
- "allowUnreachableCode": false,
45
- },
46
- "include": ["./src/**/*", "./test/**/*"],
47
- "exclude": ["./node_modules", "./**/node_modules/*", "./scripts/"],
48
- }
package/vite.config.ts DELETED
@@ -1,69 +0,0 @@
1
- import { defineConfig } from 'vite';
2
- import fs from 'fs';
3
- import path from 'path';
4
- import { fileURLToPath } from 'url';
5
-
6
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
-
8
- // When used via CLI, KISHARE_PROJECT_ROOT points to user's project
9
- // Build output goes to user's project/dist by default
10
- const projectRoot = process.env.KISHARE_PROJECT_ROOT || __dirname;
11
- const defaultOutDir = path.join(projectRoot, 'dist');
12
-
13
- export default defineConfig({
14
- base: "",
15
- build: {
16
- outDir: defaultOutDir,
17
- assetsDir: 'assets',
18
- sourcemap: true,
19
- },
20
- server: {
21
- port: 5173,
22
- open: true,
23
- middlewareMode: false,
24
- },
25
- publicDir: 'public',
26
- appType: 'spa',
27
- plugins: [
28
- {
29
- name: 'serve-public-files',
30
- configureServer(server) {
31
- server.middlewares.use((req, res, next) => {
32
- // Serve files from public directory for specific extensions
33
- if (req.url?.match(/\.(kicad_pro|kicad_sch|kicad_pcb|zip|png|jpg|jpeg|gif|svg|webp|md)$/i)) {
34
- // Security: Normalize path and prevent directory traversal
35
- const requestedPath = req.url.split('?')[0]; // Remove query params
36
- const filePath = path.normalize(path.join(__dirname, 'public', requestedPath));
37
- // Ensure the resolved path is within public directory
38
- const publicDir = path.join(__dirname, 'public');
39
- if (!filePath.startsWith(publicDir)) {
40
- res.statusCode = 403;
41
- res.end('Forbidden');
42
- return;
43
- }
44
-
45
- if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
46
- const content = fs.readFileSync(filePath);
47
-
48
- // Set appropriate Content-Type header
49
- let contentType = 'application/octet-stream';
50
- if (req.url.endsWith('.zip')) contentType = 'application/zip';
51
- else if (req.url.match(/\.(kicad_pro|kicad_sch|kicad_pcb)$/)) contentType = 'application/json';
52
- else if (req.url.endsWith('.png')) contentType = 'image/png';
53
- else if (req.url.match(/\.(jpg|jpeg)$/)) contentType = 'image/jpeg';
54
- else if (req.url.endsWith('.gif')) contentType = 'image/gif';
55
- else if (req.url.endsWith('.svg')) contentType = 'image/svg+xml';
56
- else if (req.url.endsWith('.webp')) contentType = 'image/webp';
57
- else if (req.url.endsWith('.md')) contentType = 'text/markdown';
58
-
59
- res.setHeader('Content-Type', contentType);
60
- res.end(content);
61
- return;
62
- }
63
- }
64
- next();
65
- });
66
- },
67
- },
68
- ],
69
- });