Skip to content
This repository was archived by the owner on May 30, 2025. It is now read-only.

Commit 19f55e0

Browse files
committed
fix: fly new and fly server can't find examples
1 parent f7206e2 commit 19f55e0

File tree

11 files changed

+69
-10
lines changed

11 files changed

+69
-10
lines changed

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"build:watch": "tsc -b -w -v ."
1818
},
1919
"dependencies": {
20+
"@fly/examples": "0.42.0",
2021
"@fly/v8env": "0.42.0",
2122
"ansi-colors": "^1.1.0",
2223
"axios": "^0.18.0",

packages/core/src/cmd/new.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as path from "path"
33
import * as fs from "fs"
44
import { sync as glob } from "glob"
55
import * as execa from "execa"
6+
import { examplesPath } from "@fly/examples"
67

78
export interface NewOptions {
89
template: string[]
@@ -18,7 +19,7 @@ const newCommand = root
1819
.option("-t, --template [template]", "Name of the template to use. default: getting-started", "getting-started")
1920
.option("-l, --list", "List available templates.")
2021
.action(async (options, args) => {
21-
const templateIndex = new TemplateIndex([path.resolve(__dirname, "..", "..", "examples")])
22+
const templateIndex = new TemplateIndex([examplesPath])
2223

2324
if (args.name === undefined || options.list) {
2425
listTemplates(templateIndex)

packages/core/src/cmd/server.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { spawn } from "child_process"
66
import { FileAppStore } from "../file_app_store"
77
import { Server } from "../server"
88
import { RedisCacheNotifier } from "../redis_cache_notifier"
9+
import { examplesPath } from "@fly/examples"
910

1011
interface ServerOptions {
1112
port?: string
@@ -58,7 +59,8 @@ root
5859
})
5960

6061
async function getExamplePath(name: string) {
61-
const p = path.resolve(__dirname, "..", "..", "examples", name)
62+
const p = path.resolve(examplesPath, name)
63+
6264
if (!fs.existsSync(p)) {
6365
return undefined
6466
}

packages/core/tsconfig.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@
1111
"es2017",
1212
"esnext.asynciterable"
1313
]
14-
}
15-
}
14+
},
15+
"references": [
16+
{
17+
"path": "../examples"
18+
}
19+
]
20+
}

packages/examples/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
apps/*
2+
lib

packages/examples/package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "@fly/examples",
3+
"version": "0.42.0",
4+
"description": "Example apps for the fly edge application runtime.",
5+
"license": "Apache-2.0",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/superfly/fly"
9+
},
10+
"homepage": "https://fly.io",
11+
"main": "lib/index.js",
12+
"files": [
13+
"lib/",
14+
"apps/"
15+
],
16+
"scripts": {
17+
"clean": "rm -rf apps",
18+
"build": "yarn clean && cp -r ../../examples apps",
19+
"prepublishOnly": "yarn build",
20+
"postpublishOnly": "yarn clean"
21+
},
22+
"publishConfig": {
23+
"access": "public"
24+
}
25+
}

packages/examples/src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as path from "path"
2+
import * as fs from "fs"
3+
4+
let examples = path.resolve(__dirname, "..", "apps")
5+
6+
// use examples from the repo root in dev
7+
if (!fs.existsSync(examples)) {
8+
examples = path.resolve(__dirname, "..", "..", "..", "examples")
9+
}
10+
11+
export const examplesPath = examples

packages/examples/tsconfig.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "../../tsconfig.common.json",
3+
"include": [
4+
"./src/**/*"
5+
],
6+
"compilerOptions": {
7+
"composite": true,
8+
"rootDir": "./src",
9+
"outDir": "./lib"
10+
}
11+
}

packages/fly/.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
examples/*
2-
README.md
1+
README.md

packages/fly/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
},
1010
"homepage": "https://fly.io",
1111
"files": [
12-
"examples/",
1312
"bin/"
1413
],
1514
"bin": {
1615
"fly": "./bin/fly.js"
1716
},
1817
"scripts": {
19-
"clean": "rm -rf examples/* README.md",
20-
"build": "cp -r ../../examples/ examples/ && cp ../../README.md .",
18+
"clean": "rm -rf README.md",
19+
"build": "cp ../../README.md .",
2120
"prepublishOnly": "yarn build"
2221
},
2322
"engines": {

0 commit comments

Comments
 (0)