Download kcl-samples as zip to public dir
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -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/
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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[]
|
||||
|
||||
@ -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)}`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user