create-ifc-lite 1.14.8 → 1.14.9

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/dist/index.js CHANGED
@@ -71,6 +71,18 @@ async function main() {
71
71
  projectName = arg;
72
72
  }
73
73
  }
74
+ // Reject path separators, '..', and names that would yield an invalid npm
75
+ // `name`, so join(process.cwd(), projectName) stays under cwd and the
76
+ // generated package.json is valid. Mirrors config-fixers.ts VALID_PACKAGE_NAME.
77
+ const VALID_PROJECT_NAME = /^(?:@[\w.-]+\/)?[\w.-]+$/;
78
+ // A scoped name like `@scope/..` passes the char regex but its last segment
79
+ // is a dot-segment that `join(cwd, name)` resolves outside the intended dir,
80
+ // so reject any `.`/`..` segment (scoped or not), not just a bare projectName.
81
+ const hasDotSegment = projectName.split('/').some((seg) => seg === '.' || seg === '..');
82
+ if (!VALID_PROJECT_NAME.test(projectName) || hasDotSegment) {
83
+ console.error(`Invalid project name "${projectName}". Use letters, digits, '.', '-' or '_' (no path separators).`);
84
+ process.exit(1);
85
+ }
74
86
  const targetDir = join(process.cwd(), projectName);
75
87
  if (existsSync(targetDir)) {
76
88
  console.error(`Directory "${projectName}" already exists.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ifc-lite",
3
- "version": "1.14.8",
3
+ "version": "1.14.9",
4
4
  "description": "Create IFC-Lite projects with one command",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,7 +0,0 @@
1
- /**
2
- * Download the viewer application from the ifc-lite GitHub repository.
3
- *
4
- * Tries `npx degit` first (fastest path). Falls back to a git sparse
5
- * checkout when degit is unavailable or fails.
6
- */
7
- export declare function downloadViewer(targetDir: string, _projectName: string): Promise<boolean>;
@@ -1,63 +0,0 @@
1
- /* This Source Code Form is subject to the terms of the Mozilla Public
2
- * License, v. 2.0. If a copy of the MPL was not distributed with this
3
- * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
- import { rmSync } from 'fs';
5
- import { join, dirname } from 'path';
6
- import { execSync } from 'child_process';
7
- const REPO_URL = 'https://github.com/LTplus-AG/ifc-lite';
8
- const VIEWER_PATH = 'apps/viewer';
9
- /**
10
- * Run a shell command silently. Returns true on success, false on failure.
11
- */
12
- function runCommand(cmd, cwd) {
13
- try {
14
- execSync(cmd, { cwd, stdio: 'pipe' });
15
- return true;
16
- }
17
- catch {
18
- return false;
19
- }
20
- }
21
- /**
22
- * Download the viewer application from the ifc-lite GitHub repository.
23
- *
24
- * Tries `npx degit` first (fastest path). Falls back to a git sparse
25
- * checkout when degit is unavailable or fails.
26
- */
27
- export async function downloadViewer(targetDir, _projectName) {
28
- // Try degit first (fastest)
29
- if (runCommand('npx --version')) {
30
- console.log(' Downloading viewer template...');
31
- try {
32
- execSync(`npx degit ${REPO_URL}/${VIEWER_PATH} "${targetDir}"`, {
33
- stdio: 'pipe',
34
- timeout: 60000
35
- });
36
- return true;
37
- }
38
- catch {
39
- // degit failed, try git sparse checkout
40
- }
41
- }
42
- // Fallback: git sparse checkout
43
- if (runCommand('git --version')) {
44
- console.log(' Downloading via git...');
45
- const tempDir = join(dirname(targetDir), `.temp-${Date.now()}`);
46
- try {
47
- execSync(`git clone --filter=blob:none --sparse "${REPO_URL}.git" "${tempDir}"`, {
48
- stdio: 'pipe',
49
- timeout: 120000
50
- });
51
- execSync(`git sparse-checkout set ${VIEWER_PATH}`, { cwd: tempDir, stdio: 'pipe' });
52
- // Move viewer to target
53
- const viewerSrc = join(tempDir, VIEWER_PATH);
54
- execSync(`mv "${viewerSrc}" "${targetDir}"`, { stdio: 'pipe' });
55
- rmSync(tempDir, { recursive: true, force: true });
56
- return true;
57
- }
58
- catch {
59
- rmSync(tempDir, { recursive: true, force: true });
60
- }
61
- }
62
- return false;
63
- }