foldrun 0.3.0 → 0.3.1
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 +1 -1
- package/src/commands.mjs +27 -5
package/package.json
CHANGED
package/src/commands.mjs
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import os from "node:os";
|
|
6
6
|
import path from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
7
8
|
import { credentialFor, defaultPlatform, saveCredential, removeCredential, readCredentials, normaliseUrl } from "./credentials.mjs";
|
|
8
9
|
|
|
9
10
|
const c = {
|
|
@@ -47,6 +48,22 @@ function templateFilesFrom(dir) {
|
|
|
47
48
|
return out;
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
/** The root of the installed @foldrun/core package — dist/index.js is two levels down. */
|
|
52
|
+
function coreRoot() {
|
|
53
|
+
const entry = fileURLToPath(import.meta.resolve("@foldrun/core"));
|
|
54
|
+
return path.resolve(path.dirname(entry), "..");
|
|
55
|
+
}
|
|
56
|
+
function shippedTemplate(rel) {
|
|
57
|
+
if (path.isAbsolute(rel)) return null;
|
|
58
|
+
const abs = path.join(coreRoot(), rel);
|
|
59
|
+
return fs.existsSync(abs) && fs.statSync(abs).isDirectory() ? abs : null;
|
|
60
|
+
}
|
|
61
|
+
function shippedTemplates() {
|
|
62
|
+
const dir = path.join(coreRoot(), "templates");
|
|
63
|
+
if (!fs.existsSync(dir)) return [];
|
|
64
|
+
return fs.readdirSync(dir).filter((n) => fs.statSync(path.join(dir, n)).isDirectory()).map((n) => `templates/${n}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
50
67
|
async function init(workspace, from) {
|
|
51
68
|
// The same definition the dashboard's "+ New workspace" uses — see
|
|
52
69
|
// core/src/starter.ts for why it is not two lists.
|
|
@@ -55,11 +72,16 @@ async function init(workspace, from) {
|
|
|
55
72
|
// A template is a source, a workspace is a destination. Keeping the two
|
|
56
73
|
// words apart is the whole reason `templates/` is not called `examples/`:
|
|
57
74
|
// there is one place a workspace lives, and it is wherever you make one.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
75
|
+
// A relative --from is first a directory here, then the same path inside
|
|
76
|
+
// the installed @foldrun/core package, which is where the shipped
|
|
77
|
+
// templates/ live — `--from templates/hello` must work from any directory
|
|
78
|
+
// after `npm i foldrun`, not only from a checkout of the repo.
|
|
79
|
+
const source = from && !fs.existsSync(from) ? shippedTemplate(from) : from;
|
|
80
|
+
if (from && !source) {
|
|
81
|
+
throw new Error(`no template at ${from} — pass a directory, or one that ships with foldrun: ${shippedTemplates().join(", ") || "none found"}`);
|
|
82
|
+
}
|
|
83
|
+
const files = source
|
|
84
|
+
? templateFilesFrom(source)
|
|
63
85
|
: starterFiles(path.basename(path.resolve(workspace)));
|
|
64
86
|
|
|
65
87
|
// Whatever the source, the new workspace must ignore the key that decrypts
|