stonyx 0.2.3-alpha.49 → 0.2.3-alpha.50
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/cli/new.d.ts +24 -1
- package/dist/cli/new.js +52 -4
- package/package.json +1 -1
package/dist/cli/new.d.ts
CHANGED
|
@@ -4,8 +4,31 @@ interface ModuleOption {
|
|
|
4
4
|
dirs?: string[];
|
|
5
5
|
files?: Record<string, () => string>;
|
|
6
6
|
}
|
|
7
|
+
export declare const MODULE_OPTIONS: ModuleOption[];
|
|
7
8
|
export declare function generateDbSchema(): string;
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* The version of the `stonyx` package running this generator, read from its own
|
|
11
|
+
* `package.json` at call time.
|
|
12
|
+
*
|
|
13
|
+
* Read rather than hardcoded on purpose: a literal would be correct on the day
|
|
14
|
+
* it was written and silently stale on every day after (abofs/stonyx#113).
|
|
15
|
+
*/
|
|
16
|
+
export declare function readCoreVersion(): string;
|
|
17
|
+
/**
|
|
18
|
+
* The npm dist-tag naming the release line a version belongs to:
|
|
19
|
+
* `0.2.3-beta.96` -> `beta`, `0.2.3-alpha.4` -> `alpha`, `0.2.2` -> `latest`.
|
|
20
|
+
*
|
|
21
|
+
* Every scaffolded `@stonyx/*` module is requested on the same line as the core
|
|
22
|
+
* that scaffolded it, so the generated project cannot mix a prerelease core with
|
|
23
|
+
* modules from the stable line (or the reverse).
|
|
24
|
+
*
|
|
25
|
+
* Bound: this assumes a prerelease identifier is also a published dist-tag name.
|
|
26
|
+
* True for `beta` and `alpha`, which are the only two lines the fleet publishes.
|
|
27
|
+
* A core released as e.g. `0.2.3-rc.1` with no `rc` dist-tag would scaffold an
|
|
28
|
+
* unresolvable module specifier -- loudly, at install, not silently.
|
|
29
|
+
*/
|
|
30
|
+
export declare function releaseTagFor(version: string): string;
|
|
31
|
+
export declare function generatePackageJson(name: string, selectedModules: ModuleOption[], coreVersion?: string): string;
|
|
9
32
|
export declare function generateAppTs(): string;
|
|
10
33
|
export declare function generateEnvironmentTs(): string;
|
|
11
34
|
export declare function generateTestEnvironmentTs(): string;
|
package/dist/cli/new.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { confirm, prompt } from '@stonyx/utils/prompt';
|
|
2
2
|
import { createFile, createDirectory, copyFile, fileExists } from '@stonyx/utils/file';
|
|
3
3
|
import { spawn } from 'child_process';
|
|
4
|
+
import { readFileSync } from 'fs';
|
|
4
5
|
import path from 'path';
|
|
5
6
|
import { fileURLToPath } from 'url';
|
|
6
|
-
const MODULE_OPTIONS = [
|
|
7
|
+
export const MODULE_OPTIONS = [
|
|
7
8
|
{
|
|
8
9
|
question: 'Will this project need a REST server?',
|
|
9
10
|
package: '@stonyx/rest-server',
|
|
@@ -48,15 +49,61 @@ export default class DBModel extends Model {
|
|
|
48
49
|
}
|
|
49
50
|
`;
|
|
50
51
|
}
|
|
51
|
-
|
|
52
|
+
/**
|
|
53
|
+
* The npm dist-tag that points at a package's stable release line. Only ever
|
|
54
|
+
* used as a *release line* selector for `@stonyx/*` modules (see
|
|
55
|
+
* `releaseTagFor`) -- never as the specifier for the core, which is always
|
|
56
|
+
* pinned exactly.
|
|
57
|
+
*/
|
|
58
|
+
const STABLE_DIST_TAG = 'latest';
|
|
59
|
+
/** Absolute path to this package's own root, from both `src/` and `dist/`. */
|
|
60
|
+
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..');
|
|
61
|
+
/**
|
|
62
|
+
* The version of the `stonyx` package running this generator, read from its own
|
|
63
|
+
* `package.json` at call time.
|
|
64
|
+
*
|
|
65
|
+
* Read rather than hardcoded on purpose: a literal would be correct on the day
|
|
66
|
+
* it was written and silently stale on every day after (abofs/stonyx#113).
|
|
67
|
+
*/
|
|
68
|
+
export function readCoreVersion() {
|
|
69
|
+
const raw = readFileSync(path.join(packageRoot, 'package.json'), 'utf8');
|
|
70
|
+
const version = JSON.parse(raw).version;
|
|
71
|
+
if (typeof version !== 'string' || !version) {
|
|
72
|
+
throw new Error(`Could not read the stonyx version from ${path.join(packageRoot, 'package.json')}`);
|
|
73
|
+
}
|
|
74
|
+
return version;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The npm dist-tag naming the release line a version belongs to:
|
|
78
|
+
* `0.2.3-beta.96` -> `beta`, `0.2.3-alpha.4` -> `alpha`, `0.2.2` -> `latest`.
|
|
79
|
+
*
|
|
80
|
+
* Every scaffolded `@stonyx/*` module is requested on the same line as the core
|
|
81
|
+
* that scaffolded it, so the generated project cannot mix a prerelease core with
|
|
82
|
+
* modules from the stable line (or the reverse).
|
|
83
|
+
*
|
|
84
|
+
* Bound: this assumes a prerelease identifier is also a published dist-tag name.
|
|
85
|
+
* True for `beta` and `alpha`, which are the only two lines the fleet publishes.
|
|
86
|
+
* A core released as e.g. `0.2.3-rc.1` with no `rc` dist-tag would scaffold an
|
|
87
|
+
* unresolvable module specifier -- loudly, at install, not silently.
|
|
88
|
+
*/
|
|
89
|
+
export function releaseTagFor(version) {
|
|
90
|
+
const prerelease = /^\d+\.\d+\.\d+-([0-9A-Za-z-]+)(?:\.|$)/.exec(version);
|
|
91
|
+
return prerelease ? prerelease[1] : STABLE_DIST_TAG;
|
|
92
|
+
}
|
|
93
|
+
export function generatePackageJson(name, selectedModules, coreVersion = readCoreVersion()) {
|
|
94
|
+
// The framework is a runtime dependency of the application, pinned exactly to
|
|
95
|
+
// the core that generated the project.
|
|
96
|
+
const dependencies = { stonyx: coreVersion };
|
|
52
97
|
const devDependencies = {
|
|
53
98
|
qunit: '^2.24.1',
|
|
54
|
-
stonyx: 'latest',
|
|
55
99
|
tsx: '^4.21.0',
|
|
56
100
|
typescript: '^5.8.3'
|
|
57
101
|
};
|
|
102
|
+
// Modules are discovered from devDependencies (see docs/modules.md), and are
|
|
103
|
+
// requested on the core's own release line rather than at `latest`.
|
|
104
|
+
const moduleTag = releaseTagFor(coreVersion);
|
|
58
105
|
for (const mod of selectedModules) {
|
|
59
|
-
devDependencies[mod.package] =
|
|
106
|
+
devDependencies[mod.package] = moduleTag;
|
|
60
107
|
}
|
|
61
108
|
// Sort dependencies alphabetically
|
|
62
109
|
const sorted = Object.fromEntries(Object.entries(devDependencies).sort(([a], [b]) => a.localeCompare(b)));
|
|
@@ -71,6 +118,7 @@ export function generatePackageJson(name, selectedModules) {
|
|
|
71
118
|
start: 'stonyx serve',
|
|
72
119
|
test: "NODE_ENV=test node --import tsx/esm --import ./test/setup.ts node_modules/qunit/bin/qunit.js 'test/**/*-test.ts'"
|
|
73
120
|
},
|
|
121
|
+
dependencies,
|
|
74
122
|
devDependencies: sorted
|
|
75
123
|
}, null, 2) + '\n';
|
|
76
124
|
}
|