diff --git a/.gitignore b/.gitignore index fa3c30f33..fba1a625a 100644 --- a/.gitignore +++ b/.gitignore @@ -45,7 +45,7 @@ e2e/playwright/temp3.png e2e/playwright/export-snapshots/* !e2e/playwright/export-snapshots/*.png -/kcl-samples +public/kcl-samples* /test-results/ /playwright-report/ /blob-report/ diff --git a/package.json b/package.json index 8610744d7..d7f2995ad 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "fmt": "prettier --write ./src *.ts *.json *.js ./e2e ./packages", "fmt-check": "prettier --check ./src *.ts *.json *.js ./e2e ./packages", "fetch:wasm": "./get-latest-wasm-bundle.sh", - "fetch:samples": "echo \"Fetching latest KCL samples...\" && curl -o public/kcl-samples-manifest-fallback.json https://raw.githubusercontent.com/KittyCAD/kcl-samples/achalmers/kw-pattern-transform2/manifest.json", + "fetch:samples": "curl -L -o public/kcl-samples.zip https://github.com/KittyCAD/kcl-samples/archive/refs/heads/achalmers/kw-pattern-transform2.zip && tar -C public/kcl-samples -xf public/kcl-samples.zip --strip-components=1", "isomorphic-copy-wasm": "(copy src/wasm-lib/pkg/wasm_lib_bg.wasm public || cp src/wasm-lib/pkg/wasm_lib_bg.wasm public)", "build:wasm-dev": "yarn wasm-prep && (cd src/wasm-lib && wasm-pack build --dev --target web --out-dir pkg && cargo test -p kcl-lib export_bindings) && yarn isomorphic-copy-wasm && yarn fmt", "build:wasm": "yarn wasm-prep && cd src/wasm-lib && wasm-pack build --release --target web --out-dir pkg && cargo test -p kcl-lib export_bindings && cd ../.. && yarn isomorphic-copy-wasm && yarn fmt", diff --git a/src/lang/kclSamples.test.ts b/src/lang/kclSamples.test.ts index 2a4e47985..28aaa6fdf 100644 --- a/src/lang/kclSamples.test.ts +++ b/src/lang/kclSamples.test.ts @@ -3,15 +3,13 @@ import { enginelessExecutor } from '../lib/testHelpers' import path from 'node:path' import fs from 'node:fs/promises' -import child_process from 'node:child_process' // The purpose of these tests is to act as a first line of defense // if something gets real screwy with our KCL ecosystem. // THESE TESTS ONLY RUN UNDER A NODEJS ENVIRONMENT. They DO NOT // test under our application. -const DIR_KCL_SAMPLES = 'kcl-samples' -const URL_GIT_KCL_SAMPLES = 'https://github.com/KittyCAD/kcl-samples.git' +const DIR_KCL_SAMPLES = 'public/kcl-samples' interface KclSampleFile { file: string @@ -23,20 +21,11 @@ interface KclSampleFile { try { // @ts-expect-error - await fs.rm(DIR_KCL_SAMPLES, { recursive: true }) + await fs.exists(DIR_KCL_SAMPLES, { recursive: true }) } catch (e) { console.log(e) } -child_process.spawnSync('git', [ - 'clone', - '--single-branch', - '--branch', - 'achalmers/kw-pattern-transform2', - URL_GIT_KCL_SAMPLES, - DIR_KCL_SAMPLES, -]) - // @ts-expect-error let files = await fs.readdir(DIR_KCL_SAMPLES) // @ts-expect-error diff --git a/src/lib/constants.ts b/src/lib/constants.ts index cdf89b01e..b4aaa12a5 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -104,11 +104,7 @@ export const MAKE_TOAST_MESSAGES = { } /** The URL for the KCL samples manifest files */ -export const KCL_SAMPLES_MANIFEST_URLS = { - remote: - 'https://raw.githubusercontent.com/KittyCAD/kcl-samples/main/manifest.json', - localFallback: '/kcl-samples-manifest-fallback.json', -} as const +export const KCL_SAMPLES_MANIFEST_URL = '/kcl-samples/manifest.json' /** URL parameter to create a file */ export const CREATE_FILE_URL_PARAM = 'create-file' diff --git a/src/lib/getKclSamplesManifest.ts b/src/lib/getKclSamplesManifest.ts index d5b43930e..7e5aed276 100644 --- a/src/lib/getKclSamplesManifest.ts +++ b/src/lib/getKclSamplesManifest.ts @@ -1,5 +1,4 @@ -import { KCL_SAMPLES_MANIFEST_URLS } from './constants' -import { isDesktop } from './isDesktop' +import { KCL_SAMPLES_MANIFEST_URL } from './constants' export type KclSamplesManifestItem = { file: string @@ -10,22 +9,13 @@ export type KclSamplesManifestItem = { } export async function getKclSamplesManifest() { - let response = await fetch(KCL_SAMPLES_MANIFEST_URLS.remote) + const response = await fetch(KCL_SAMPLES_MANIFEST_URL) if (!response.ok) { - console.warn( - 'Failed to fetch latest remote KCL samples manifest, falling back to local:', + console.error( + 'Failed to fetch fallback KCL samples manifest:', response.statusText ) - response = await fetch( - (isDesktop() ? '.' : '') + KCL_SAMPLES_MANIFEST_URLS.localFallback - ) - if (!response.ok) { - console.error( - 'Failed to fetch fallback KCL samples manifest:', - response.statusText - ) - return [] - } + return [] } return response.json().then((manifest) => { return manifest as KclSamplesManifestItem[] diff --git a/src/lib/kclCommands.ts b/src/lib/kclCommands.ts index 30990bd89..632078bc6 100644 --- a/src/lib/kclCommands.ts +++ b/src/lib/kclCommands.ts @@ -63,7 +63,8 @@ export function kclCommands(commandProps: KclCommandConfig): Command[] { const pathParts = data.sample.split('/') const projectPathPart = pathParts[0] const primaryKclFile = pathParts[1] - const sampleCodeUrl = `https://raw.githubusercontent.com/KittyCAD/kcl-samples/main/${encodeURIComponent( + // local only + const sampleCodeUrl = `/kcl-samples/${encodeURIComponent( projectPathPart )}/${encodeURIComponent(primaryKclFile)}`