@aliens-syndicate/cli 0.1.10 → 0.1.11
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/README.es-ES.md +9 -11
- package/README.md +9 -11
- package/README.pt-BR.md +9 -11
- package/README.zh-CN.md +10 -12
- package/package.json +3 -2
- package/tools/build.mjs +15 -7
- package/tools/cli-shared.mjs +11 -2
- package/tools/cli.mjs +1 -0
- package/tools/create.mjs +14 -4
- package/tools/playground/client.mjs +500 -0
- package/tools/playground/examples/computed/app.markup +3 -0
- package/tools/playground/examples/computed/cart.logic +22 -0
- package/tools/playground/examples/computed/cart.markup +10 -0
- package/tools/playground/examples/computed/cart.style +13 -0
- package/tools/playground/examples/counter/app.markup +3 -0
- package/tools/playground/examples/counter/counter.logic +19 -0
- package/tools/playground/examples/counter/counter.markup +7 -0
- package/tools/playground/examples/counter/counter.style +11 -0
- package/tools/playground/examples/effect-cleanup/app.markup +3 -0
- package/tools/playground/examples/effect-cleanup/stopwatch.logic +28 -0
- package/tools/playground/examples/effect-cleanup/stopwatch.markup +6 -0
- package/tools/playground/examples/effect-cleanup/stopwatch.style +11 -0
- package/tools/playground/examples/element-properties/app.markup +5 -0
- package/tools/playground/examples/element-properties/app.style +3 -0
- package/tools/playground/examples/element-properties/greeting.markup +4 -0
- package/tools/playground/examples/element-properties/greeting.style +7 -0
- package/tools/playground/examples/fix-the-error/app.markup +3 -0
- package/tools/playground/examples/fix-the-error/light.logic +10 -0
- package/tools/playground/examples/fix-the-error/light.markup +6 -0
- package/tools/playground/examples/fix-the-error/light.style +7 -0
- package/tools/playground/examples/hello-world/app.markup +4 -0
- package/tools/playground/examples/hello-world/app.style +7 -0
- package/tools/playground/examples/icons/app.markup +7 -0
- package/tools/playground/examples/icons/app.style +5 -0
- package/tools/playground/examples/list-for/app.markup +3 -0
- package/tools/playground/examples/list-for/planets.logic +15 -0
- package/tools/playground/examples/list-for/planets.markup +6 -0
- package/tools/playground/examples/list-for/planets.style +7 -0
- package/tools/playground/examples/ready-elements/app.markup +3 -0
- package/tools/playground/examples/ready-elements/app.style +3 -0
- package/tools/playground/examples/ready-elements/mission.logic +9 -0
- package/tools/playground/examples/ready-elements/mission.markup +7 -0
- package/tools/playground/examples/ready-elements/mission.style +5 -0
- package/tools/playground/examples/streams/app.markup +3 -0
- package/tools/playground/examples/streams/planet-search.logic +24 -0
- package/tools/playground/examples/streams/planet-search.markup +9 -0
- package/tools/playground/examples/streams/planet-search.style +9 -0
- package/tools/playground/examples/styles-modifiers/app.markup +5 -0
- package/tools/playground/examples/styles-modifiers/app.style +10 -0
- package/tools/playground/examples/watch/app.markup +3 -0
- package/tools/playground/examples/watch/volume.logic +20 -0
- package/tools/playground/examples/watch/volume.markup +9 -0
- package/tools/playground/examples/watch/volume.style +11 -0
- package/tools/playground.mjs +222 -0
- package/tools/project-layout.mjs +1 -1
- package/tools/runtime.mjs +16 -6
- package/tools/serve.mjs +15 -2
- package/tools/starter/app/pages/home/home.markup +19 -0
- package/tools/starter/app/pages/home/home.style +51 -0
- package/tools/starter/language/.en-US +10 -73
- package/tools/starter/language/.es-ES +10 -73
- package/tools/starter/language/.pt-BR +10 -73
- package/tools/starter/language/.zh-CN +10 -73
- package/tools/starter/styles/generic/ui-base.style +4 -5
- package/tools/test.mjs +20 -0
- package/tools/utilities-docs.mjs +0 -5
- package/tools/watch.mjs +3 -2
- package/tools/starter/app/elements/atoms/kit-nav-link/kit-nav-link.markup +0 -2
- package/tools/starter/app/elements/molecules/kit-button-demo/kit-button-demo.logic +0 -14
- package/tools/starter/app/elements/molecules/kit-button-demo/kit-button-demo.markup +0 -8
- package/tools/starter/app/elements/molecules/kit-card-link/kit-card-link.markup +0 -4
- package/tools/starter/app/elements/organisms/kit-navigation/kit-navigation.markup +0 -19
- package/tools/starter/app/pages/kit-border/kit-border.markup +0 -38
- package/tools/starter/app/pages/kit-color/kit-color.markup +0 -58
- package/tools/starter/app/pages/kit-components/kit-components.markup +0 -95
- package/tools/starter/app/pages/kit-overview/kit-overview.markup +0 -25
- package/tools/starter/app/pages/kit-radius/kit-radius.markup +0 -34
- package/tools/starter/app/pages/kit-space/kit-space.markup +0 -61
- package/tools/starter/app/pages/kit-type/kit-type.markup +0 -48
- package/tools/starter/app/pages/style-guide/style-guide.markup +0 -10
- package/tools/starter/app/pages/style-guide/style-guide.style +0 -252
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Markup Light
|
|
2
|
+
# This example starts broken on purpose. Read the error on the right, then fix it:
|
|
3
|
+
# the button calls an action that light.logic does not declare.
|
|
4
|
+
section id="light"
|
|
5
|
+
p={Off} id="light-label"
|
|
6
|
+
button text="Switch" variant="light-button" action="swich"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Logic Planets
|
|
2
|
+
# Each item has a name: that name is its identity, so no track is needed.
|
|
3
|
+
list planets:
|
|
4
|
+
mercury:
|
|
5
|
+
name: Mercury
|
|
6
|
+
moons: 0
|
|
7
|
+
earth:
|
|
8
|
+
name: Earth
|
|
9
|
+
moons: 1
|
|
10
|
+
mars:
|
|
11
|
+
name: Mars
|
|
12
|
+
moons: 2
|
|
13
|
+
jupiter:
|
|
14
|
+
name: Jupiter
|
|
15
|
+
moons: 95
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Markup Mission
|
|
2
|
+
# ui-card, ui-button and ui-badge come from @aliens-syndicate/elements.
|
|
3
|
+
section id="mission"
|
|
4
|
+
ui-card variant="ui-card ui-card_raised" eyebrow="Mission" title="Launch window" text="The next window opens in 3 days."
|
|
5
|
+
div id="mission-actions"
|
|
6
|
+
ui-button label="Confirm" variant="ui-button ui-button_primary" action="confirm"
|
|
7
|
+
ui-badge text="Waiting" variant="ui-badge ui-badge_warning"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Logic PlanetSearch
|
|
2
|
+
# Needs @aliens-syndicate/reactive. debounce waits for a pause; distinctUntilChanged skips repeats.
|
|
3
|
+
stream keys: number =
|
|
4
|
+
fromEvent(element("planet-search-input"), "input")
|
|
5
|
+
.scan(count => count + 1, 0)
|
|
6
|
+
|
|
7
|
+
stream query: string =
|
|
8
|
+
fromEvent(element("planet-search-input"), "input")
|
|
9
|
+
.map(event => event.target.value.trim().toLowerCase())
|
|
10
|
+
.debounce(300)
|
|
11
|
+
.distinctUntilChanged()
|
|
12
|
+
|
|
13
|
+
stream count: number =
|
|
14
|
+
from(() => this.query)
|
|
15
|
+
.filter(query => query !== undefined)
|
|
16
|
+
.scan(count => count + 1, 0)
|
|
17
|
+
|
|
18
|
+
computed result: string = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn"].filter(name => name.toLowerCase().includes(this.query ?? "")).join(" · ") || "No planet found"
|
|
19
|
+
|
|
20
|
+
bind:
|
|
21
|
+
planet-search-keys:
|
|
22
|
+
text: this.keys ?? 0
|
|
23
|
+
planet-search-count:
|
|
24
|
+
text: this.count ?? 0
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Markup PlanetSearch
|
|
2
|
+
section id="planet-search"
|
|
3
|
+
input type="search" id="planet-search-input" placeholder="Type a planet" autocomplete="off"
|
|
4
|
+
p id="planet-search-stats"
|
|
5
|
+
span text="Keystrokes"
|
|
6
|
+
output={0} id="planet-search-keys"
|
|
7
|
+
span text="Searches"
|
|
8
|
+
output={0} id="planet-search-count"
|
|
9
|
+
p id="planet-search-result"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Style App
|
|
2
|
+
# A selector is the id or variant itself; _name is a modifier of it.
|
|
3
|
+
app
|
|
4
|
+
flex flex-wrap gap-2 p-6
|
|
5
|
+
app-badge
|
|
6
|
+
py-1 px-3 rounded-full border border-outline text-sm font-semibold
|
|
7
|
+
app-badge_success
|
|
8
|
+
bg-success-bg text-success border-success
|
|
9
|
+
app-badge_danger
|
|
10
|
+
bg-danger-bg text-danger border-danger
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Logic Volume
|
|
2
|
+
# watch runs when level changes and receives the old value as previous.
|
|
3
|
+
signal level: number = 5
|
|
4
|
+
signal last: string = "—"
|
|
5
|
+
|
|
6
|
+
watch level:
|
|
7
|
+
body:
|
|
8
|
+
this.last = `${previous} → ${this.level}`
|
|
9
|
+
console.log("level changed", previous, "→", this.level)
|
|
10
|
+
|
|
11
|
+
actions:
|
|
12
|
+
down:
|
|
13
|
+
returns: void
|
|
14
|
+
body:
|
|
15
|
+
if (this.level > 0) this.level -= 1
|
|
16
|
+
|
|
17
|
+
up:
|
|
18
|
+
returns: void
|
|
19
|
+
body:
|
|
20
|
+
if (this.level < 10) this.level += 1
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Markup Volume
|
|
2
|
+
section id="volume"
|
|
3
|
+
div id="volume-row"
|
|
4
|
+
button text="−" variant="volume-step" action="down" label="Lower"
|
|
5
|
+
output={5} id="volume-level"
|
|
6
|
+
button text="+" variant="volume-step" action="up" label="Raise"
|
|
7
|
+
p id="volume-change"
|
|
8
|
+
span text="Last change:"
|
|
9
|
+
output={—} id="volume-last"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Style Volume
|
|
2
|
+
volume
|
|
3
|
+
grid justify-items-center gap-2 p-8
|
|
4
|
+
volume-row
|
|
5
|
+
flex items-center gap-4
|
|
6
|
+
volume-step
|
|
7
|
+
w-11 h-11 rounded-lg border border-outline bg-surface text-xl
|
|
8
|
+
volume-level
|
|
9
|
+
text-4xl font-bold text-brand
|
|
10
|
+
volume-change
|
|
11
|
+
flex gap-2 text-muted
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// The Playground page compiles Space in the browser with this same build. emitPlayground writes dist/playground/:
|
|
2
|
+
// compiler.mjs is build.mjs wrapped in build() and pointed at shims.mjs, an in-memory file system that stands in for
|
|
3
|
+
// node:fs, node:path, node:module and node:url. Next to it go the Space highlighter, the extension packages, the
|
|
4
|
+
// starter styles, the examples (tools/playground/examples/<id>/) and client.mjs, the page itself. build.mjs calls this
|
|
5
|
+
// only when a page renders a tag with data-playground, so projects never load it.
|
|
6
|
+
import { cp, mkdir, readFile, readdir, writeFile } from 'node:fs/promises';
|
|
7
|
+
import { createRequire } from 'node:module';
|
|
8
|
+
import { dirname, join, relative } from 'node:path';
|
|
9
|
+
|
|
10
|
+
const tools = import.meta.dirname;
|
|
11
|
+
const packageNames = { utilities: '@aliens-syndicate/utilities', icons: '@aliens-syndicate/icons', elements: '@aliens-syndicate/elements', reactive: '@aliens-syndicate/reactive' };
|
|
12
|
+
|
|
13
|
+
async function filesUnder(directory) {
|
|
14
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
15
|
+
const nested = await Promise.all(entries.map(entry => entry.isDirectory() ? filesUnder(join(directory, entry.name)) : [join(directory, entry.name)]));
|
|
16
|
+
return nested.flat();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Every import of node:… points at the shims; prefix is the path from the module to shims.mjs.
|
|
20
|
+
const toShims = (source, prefix) => source.replace(/from '(node:[\w/]+)'/g, `from '${prefix}shims.mjs'`);
|
|
21
|
+
|
|
22
|
+
function replaceOnce(source, search, replacement, what) {
|
|
23
|
+
if (!source.includes(search)) throw new Error(`playground: build.mjs changed; update ${what} in tools/playground.mjs.`);
|
|
24
|
+
return source.replace(search, replacement);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// build.mjs runs once from top to bottom. The browser copy keeps its imports at the top and wraps the rest in build(),
|
|
28
|
+
// so the Playground runs it again on every edit without loading a new module each time.
|
|
29
|
+
function browserCompiler(source) {
|
|
30
|
+
let code = toShims(source, './');
|
|
31
|
+
code = replaceOnce(code, "import spaceSyntax from './vscode-space/syntax.cjs';", "import spaceSyntax from './syntax.mjs';", 'the highlighter import');
|
|
32
|
+
code = code.replaceAll('import.meta.dirname', "'/tools'");
|
|
33
|
+
code = replaceOnce(code, /^.*playground:node-only.*$/m.exec(code)?.[0] ?? '\u0000', '', 'the Playground call');
|
|
34
|
+
code = replaceOnce(code, 'console.log(`Aliens Web preview generated in ${output}`);', '', 'the closing log');
|
|
35
|
+
const lines = code.split('\n');
|
|
36
|
+
let end = 0;
|
|
37
|
+
while (lines[end].startsWith('import ')) end++;
|
|
38
|
+
return `${lines.slice(0, end).join('\n')}\n\nexport async function build() {\n${lines.slice(end).join('\n')}\n}\n`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// The highlighter is CommonJS. syntax.mjs carries its three files and a require() that only knows them.
|
|
42
|
+
async function browserSyntax() {
|
|
43
|
+
const files = { './syntax.cjs': 'syntax.cjs', './style-colors.cjs': 'style-colors.cjs', './vendor/color-name.cjs': 'vendor/color-name.cjs' };
|
|
44
|
+
const modules = await Promise.all(Object.entries(files).map(async ([name, file]) =>
|
|
45
|
+
`${JSON.stringify(name)}: function (module, exports, require) {\n${await readFile(join(tools, 'vscode-space', file), 'utf8')}\n}`));
|
|
46
|
+
return `const sources = {\n${modules.join(',\n')}\n};
|
|
47
|
+
const cache = {};
|
|
48
|
+
function require(name) {
|
|
49
|
+
const key = name.replace(/^\\.\\/vendor\\//, './vendor/');
|
|
50
|
+
if (cache[key]) return cache[key].exports;
|
|
51
|
+
const module = { exports: {} };
|
|
52
|
+
cache[key] = module;
|
|
53
|
+
sources[key](module, module.exports, require);
|
|
54
|
+
return module.exports;
|
|
55
|
+
}
|
|
56
|
+
export default require('./syntax.cjs');
|
|
57
|
+
`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const shims = `// The file system, paths and modules that build.mjs and the packages expect, for the browser. Paths are absolute and
|
|
61
|
+
// POSIX; the Playground fills files before each build and reads dist/ from it afterwards.
|
|
62
|
+
export const files = new Map();
|
|
63
|
+
const base = new URL('./', import.meta.url);
|
|
64
|
+
const fetched = new Map();
|
|
65
|
+
export const packageEntries = new Map();
|
|
66
|
+
const failure = (code, path) => Object.assign(new Error(code + ': ' + path), { code });
|
|
67
|
+
const pathOf = target => target instanceof URL ? decodeURIComponent(target.pathname) : String(target);
|
|
68
|
+
|
|
69
|
+
export function normalize(path) {
|
|
70
|
+
const absolute = path.startsWith('/');
|
|
71
|
+
const parts = [];
|
|
72
|
+
for (const part of path.split('/')) {
|
|
73
|
+
if (!part || part === '.') continue;
|
|
74
|
+
if (part === '..' && parts.length && parts.at(-1) !== '..') parts.pop();
|
|
75
|
+
else if (part !== '..' || !absolute) parts.push(part);
|
|
76
|
+
}
|
|
77
|
+
const joined = parts.join('/');
|
|
78
|
+
return absolute ? '/' + joined : joined || '.';
|
|
79
|
+
}
|
|
80
|
+
export const join = (...parts) => normalize(parts.filter(part => part !== '').join('/'));
|
|
81
|
+
export function resolve(...parts) {
|
|
82
|
+
let path = '/';
|
|
83
|
+
for (const part of parts) path = part.startsWith('/') ? part : path + '/' + part;
|
|
84
|
+
return normalize(path);
|
|
85
|
+
}
|
|
86
|
+
export function dirname(path) {
|
|
87
|
+
const clean = normalize(path);
|
|
88
|
+
const index = clean.lastIndexOf('/');
|
|
89
|
+
return index < 0 ? '.' : index === 0 ? '/' : clean.slice(0, index);
|
|
90
|
+
}
|
|
91
|
+
export function basename(path, extension) {
|
|
92
|
+
let name = normalize(path).split('/').pop();
|
|
93
|
+
if (extension && name.endsWith(extension) && name !== extension) name = name.slice(0, -extension.length);
|
|
94
|
+
return name;
|
|
95
|
+
}
|
|
96
|
+
export function extname(path) {
|
|
97
|
+
const name = basename(path);
|
|
98
|
+
const index = name.lastIndexOf('.');
|
|
99
|
+
return index <= 0 ? '' : name.slice(index);
|
|
100
|
+
}
|
|
101
|
+
export function relative(from, to) {
|
|
102
|
+
const source = resolve(from).split('/').filter(Boolean);
|
|
103
|
+
const target = resolve(to).split('/').filter(Boolean);
|
|
104
|
+
let common = 0;
|
|
105
|
+
while (common < source.length && source[common] === target[common]) common++;
|
|
106
|
+
return [...source.slice(common).map(() => '..'), ...target.slice(common)].join('/');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function existsSync(target) {
|
|
110
|
+
const path = normalize(pathOf(target));
|
|
111
|
+
if (files.has(path)) return true;
|
|
112
|
+
for (const key of files.keys()) if (key.startsWith(path + '/')) return true;
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
export async function readFile(target) {
|
|
116
|
+
const path = normalize(pathOf(target));
|
|
117
|
+
if (files.has(path)) return files.get(path);
|
|
118
|
+
// A file that ships next to the compiler, like the icon catalog, comes from the server once.
|
|
119
|
+
if (path.startsWith(base.pathname)) {
|
|
120
|
+
if (!fetched.has(path)) fetched.set(path, fetch(path).then(response => response.ok ? response.text() : Promise.reject(failure('ENOENT', path))));
|
|
121
|
+
return fetched.get(path);
|
|
122
|
+
}
|
|
123
|
+
throw failure('ENOENT', path);
|
|
124
|
+
}
|
|
125
|
+
export async function readdir(target, options) {
|
|
126
|
+
const prefix = normalize(pathOf(target)).replace(/\\/$/, '') + '/';
|
|
127
|
+
const names = new Map();
|
|
128
|
+
for (const key of files.keys()) {
|
|
129
|
+
if (!key.startsWith(prefix)) continue;
|
|
130
|
+
const [name, ...rest] = key.slice(prefix.length).split('/');
|
|
131
|
+
names.set(name, names.get(name) || rest.length > 0);
|
|
132
|
+
}
|
|
133
|
+
if (!names.size) throw failure('ENOENT', prefix);
|
|
134
|
+
const entries = [...names].sort(([left], [right]) => left < right ? -1 : 1);
|
|
135
|
+
return options?.withFileTypes ? entries.map(([name, directory]) => ({ name, isDirectory: () => directory, isFile: () => !directory })) : entries.map(([name]) => name);
|
|
136
|
+
}
|
|
137
|
+
export async function writeFile(target, content) { files.set(normalize(pathOf(target)), String(content)); }
|
|
138
|
+
export async function mkdir() {}
|
|
139
|
+
export async function cp() {}
|
|
140
|
+
|
|
141
|
+
export function createRequire() {
|
|
142
|
+
return { resolve(name) {
|
|
143
|
+
if (!packageEntries.has(name)) throw failure('MODULE_NOT_FOUND', name);
|
|
144
|
+
return packageEntries.get(name);
|
|
145
|
+
} };
|
|
146
|
+
}
|
|
147
|
+
// Nothing strips TypeScript here: compileLogic writes plain JavaScript, and a typed body fails as a syntax error.
|
|
148
|
+
export const stripTypeScriptTypes = code => code;
|
|
149
|
+
export const pathToFileURL = path => new URL(path, location.origin);
|
|
150
|
+
export const fileURLToPath = url => decodeURIComponent(new URL(url).pathname);
|
|
151
|
+
`;
|
|
152
|
+
|
|
153
|
+
export async function emitPlayground({ workspace, output }) {
|
|
154
|
+
const target = join(output, 'playground');
|
|
155
|
+
await mkdir(join(target, 'packages'), { recursive: true });
|
|
156
|
+
const preload = {};
|
|
157
|
+
|
|
158
|
+
// The tool files build.mjs reads by path.
|
|
159
|
+
preload['/tools/runtime.mjs'] = await readFile(join(tools, 'runtime.mjs'), 'utf8');
|
|
160
|
+
preload['/tools/vscode-space/package.json'] = await readFile(join(tools, 'vscode-space', 'package.json'), 'utf8');
|
|
161
|
+
|
|
162
|
+
// The tokens and themes of the starter (its settings layer) and a base for the page: the other starter layers style
|
|
163
|
+
// the starter pages, which an example does not have.
|
|
164
|
+
const settings = join(tools, 'starter', 'styles', 'settings');
|
|
165
|
+
for (const file of await filesUnder(settings)) preload[`/project/styles/settings/${relative(settings, file)}`] = await readFile(file, 'utf8');
|
|
166
|
+
preload['/project/styles/generic/base.style'] = `Style Base
|
|
167
|
+
body
|
|
168
|
+
margin: 0
|
|
169
|
+
background-color: var(--color-canvas)
|
|
170
|
+
color: var(--color-text)
|
|
171
|
+
font-family: system-ui, -apple-system, "Segoe UI", sans-serif
|
|
172
|
+
line-height: 1.5
|
|
173
|
+
`;
|
|
174
|
+
preload['/project/styles/main.style'] = 'Style Main\n default:\n settings\n generic\n';
|
|
175
|
+
|
|
176
|
+
// The packages, with their node: imports pointed at the shims. Their files load relative to compiler.mjs, so the
|
|
177
|
+
// keys that start with packages/ become absolute paths in the browser.
|
|
178
|
+
const require = createRequire(join(workspace, 'package.json'));
|
|
179
|
+
const versions = {};
|
|
180
|
+
for (const [short, name] of Object.entries(packageNames)) {
|
|
181
|
+
const entry = require.resolve(name);
|
|
182
|
+
let directory = dirname(entry);
|
|
183
|
+
while (!(await readFile(join(directory, 'package.json'), 'utf8').then(() => true, () => false))) directory = dirname(directory);
|
|
184
|
+
const manifest = await readFile(join(directory, 'package.json'), 'utf8');
|
|
185
|
+
versions[short] = JSON.parse(manifest).version;
|
|
186
|
+
preload[`packages/${short}/package.json`] = manifest;
|
|
187
|
+
let source = toShims(await readFile(entry, 'utf8'), '../../');
|
|
188
|
+
if (short === 'icons') {
|
|
189
|
+
// The catalog is large: parse it once per page, not once per build.
|
|
190
|
+
source = replaceOnce(source, 'export async function readCatalog() {', 'async function readCatalogFile() {', 'the icon catalog reader') +
|
|
191
|
+
'\nlet catalogRead;\nexport function readCatalog() {\n return catalogRead ??= readCatalogFile();\n}\n';
|
|
192
|
+
await cp(join(directory, 'catalog.json'), join(target, 'packages', short, 'catalog.json'));
|
|
193
|
+
}
|
|
194
|
+
if (short === 'elements') {
|
|
195
|
+
const elements = join(directory, 'elements');
|
|
196
|
+
for (const file of await filesUnder(elements)) preload[`packages/${short}/elements/${relative(elements, file)}`] = await readFile(file, 'utf8');
|
|
197
|
+
}
|
|
198
|
+
await mkdir(join(target, 'packages', short), { recursive: true });
|
|
199
|
+
await writeFile(join(target, 'packages', short, 'index.mjs'), source);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Each example is a folder of Space files; its title and description live in the page translations.
|
|
203
|
+
const examplesDirectory = join(tools, 'playground', 'examples');
|
|
204
|
+
const examples = {};
|
|
205
|
+
for (const entry of await readdir(examplesDirectory, { withFileTypes: true })) {
|
|
206
|
+
if (!entry.isDirectory()) continue;
|
|
207
|
+
examples[entry.name] = {};
|
|
208
|
+
for (const file of (await readdir(join(examplesDirectory, entry.name))).sort()) {
|
|
209
|
+
examples[entry.name][file] = await readFile(join(examplesDirectory, entry.name, file), 'utf8');
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
await Promise.all([
|
|
214
|
+
writeFile(join(target, 'compiler.mjs'), browserCompiler(await readFile(join(tools, 'build.mjs'), 'utf8'))),
|
|
215
|
+
writeFile(join(target, 'project-layout.mjs'), toShims(await readFile(join(tools, 'project-layout.mjs'), 'utf8'), './')),
|
|
216
|
+
writeFile(join(target, 'syntax.mjs'), await browserSyntax()),
|
|
217
|
+
writeFile(join(target, 'shims.mjs'), shims),
|
|
218
|
+
writeFile(join(target, 'files.json'), JSON.stringify({ versions, files: preload })),
|
|
219
|
+
writeFile(join(target, 'examples.json'), JSON.stringify(examples)),
|
|
220
|
+
cp(join(tools, 'playground', 'client.mjs'), join(target, 'client.mjs'))
|
|
221
|
+
]);
|
|
222
|
+
}
|
package/tools/project-layout.mjs
CHANGED
|
@@ -31,7 +31,7 @@ export const elementLevels = ['atoms', 'molecules', 'organisms', 'templates'];
|
|
|
31
31
|
// package is an npm name or a local folder (./path), the variant picks an option of the package (the icon style, as in
|
|
32
32
|
// @aliens-syndicate/icons/stroke-rounded) and the version is the one installed, quoted or not.
|
|
33
33
|
export const dependencyGroups = ['dependencies', 'devDependencies'];
|
|
34
|
-
export const dependencySections = ['framework', 'utilities', 'icons', 'elements', 'reactive'];
|
|
34
|
+
export const dependencySections = ['framework', 'utilities', 'test', 'icons', 'elements', 'reactive'];
|
|
35
35
|
export function parseDependency(line) {
|
|
36
36
|
const version = '"?(\\d+\\.\\d+\\.\\d+[\\w.+-]*)"?';
|
|
37
37
|
const local = new RegExp(`^(\\.{1,2}\\/[^\\s:]+):\\s*${version}$`).exec(line.trim());
|
package/tools/runtime.mjs
CHANGED
|
@@ -336,13 +336,16 @@ function applyTheme(name, persist = false) {
|
|
|
336
336
|
if (persist) savePreference(themeKey, theme);
|
|
337
337
|
}
|
|
338
338
|
|
|
339
|
-
// Short fragments from older links: #logic opens logic-guide, #mock opens type-
|
|
340
|
-
|
|
341
|
-
const
|
|
342
|
-
|
|
339
|
+
// Short fragments from older links: #logic opens logic-guide, #mock opens space-language-type-mock. The file types and
|
|
340
|
+
// the Files page moved into the Space page, so #files-index, #markup-reference and #type-index-<type> open there.
|
|
341
|
+
const shortViews = new Map([['home', 'home-guide'], ['logic', 'logic-guide'], ['search', 'site-search']]);
|
|
342
|
+
const legacyViews = new Map([...shortViews, ['markup', 'space-language-type-markup'], ['markup-reference', 'space-language-type-markup'],
|
|
343
|
+
['files-index', 'space-language-files'], ['style-docs', 'utilities-docs'],
|
|
344
|
+
['styles', 'space-language-type-style'], ['mockup', 'space-language-type-mock']]);
|
|
345
|
+
// The search shows a view by its short name: space-language-type-agent is .agent, logic-guide is .logic.
|
|
343
346
|
function shortName(id) {
|
|
344
347
|
for (const [short, full] of shortViews) if (full === id) return short;
|
|
345
|
-
return id.
|
|
348
|
+
return id.split('-').at(-1);
|
|
346
349
|
}
|
|
347
350
|
|
|
348
351
|
function normalizeSearch(value) {
|
|
@@ -612,13 +615,18 @@ document.addEventListener('keydown', event => {
|
|
|
612
615
|
if (view?.hidden) location.hash = view.id;
|
|
613
616
|
else searchForm.querySelector('input').focus();
|
|
614
617
|
});
|
|
618
|
+
let playground = null;
|
|
615
619
|
const views = [...document.querySelectorAll('[data-view]')];
|
|
616
620
|
const navigation = [...document.querySelectorAll('[data-nav]')];
|
|
617
621
|
function resolveView(id) {
|
|
622
|
+
if (id.startsWith('type-index-')) id = 'space-language-type-' + id.slice('type-index-'.length);
|
|
618
623
|
const direct = document.getElementById(id);
|
|
619
624
|
if (direct?.closest('[data-view]')) return direct;
|
|
620
625
|
const legacy = legacyViews.get(id) ?? views.find(view => view.id.endsWith('-' + id))?.id;
|
|
621
|
-
|
|
626
|
+
if (legacy) return document.getElementById(legacy);
|
|
627
|
+
// An address under a view opens that view: #playground-counter opens the Playground, which reads the example.
|
|
628
|
+
const owner = !direct && views.find(view => id.startsWith(view.id + '-'));
|
|
629
|
+
return owner || direct || document.getElementById('space-language-type-' + id);
|
|
622
630
|
}
|
|
623
631
|
|
|
624
632
|
const consoleBadge = 'color: #fff; background: #111; padding: 1px 6px; border-radius: 4px';
|
|
@@ -659,6 +667,8 @@ function showView({ scroll = false } = {}) {
|
|
|
659
667
|
// A view that holds the search focuses its field, ready to type.
|
|
660
668
|
requested?.querySelector('[data-doc-search] input')?.focus({ preventScroll: true });
|
|
661
669
|
for (const catalog of iconCatalogs) if (catalog.visible()) catalog.load();
|
|
670
|
+
// The Playground loads its editor and the browser copy of the build the first time its page opens.
|
|
671
|
+
if (requested?.querySelector('[data-playground]')) playground ??= import('./playground/client.mjs').catch(error => console.error(error));
|
|
662
672
|
}
|
|
663
673
|
|
|
664
674
|
document.addEventListener('click', event => {
|
package/tools/serve.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { createServer } from 'node:http';
|
|
|
5
5
|
import { networkInterfaces } from 'node:os';
|
|
6
6
|
import { extname, join, normalize, relative, sep } from 'node:path';
|
|
7
7
|
import {
|
|
8
|
-
CliError, bold, cyan, defaultPort, dim, green, parseFlags, pick, readConfig, red, requireProject, runBuild
|
|
8
|
+
CliError, bold, cyan, defaultPort, dim, green, parseFlags, pick, readConfig, red, requireProject, runBuild, runTests
|
|
9
9
|
} from './cli-shared.mjs';
|
|
10
10
|
|
|
11
11
|
const text = {
|
|
@@ -110,11 +110,23 @@ export async function serve(args) {
|
|
|
110
110
|
console.log(`\n ${dim(t('watching'))}\n`);
|
|
111
111
|
|
|
112
112
|
// The build writes dist/ and the .map itself, so those changes never start another build.
|
|
113
|
-
|
|
113
|
+
// The test report (.test, and app.test or .aliens/ from 0.1.0) is rewritten by every build, so it must not start another one.
|
|
114
|
+
const ignored = new Set(['dist', 'node_modules', '.git', '.DS_Store', '.test', 'app.test', '.aliens']);
|
|
114
115
|
const skip = file => file.split(sep).some(part => ignored.has(part)) || file.endsWith('.map');
|
|
115
116
|
let running = false;
|
|
116
117
|
let pending = false;
|
|
117
118
|
let timer;
|
|
119
|
+
// The tests run on every save, after the rebuild and apart from it, so a slow test never delays the reload.
|
|
120
|
+
let testing = false;
|
|
121
|
+
let testAgain = false;
|
|
122
|
+
async function test() {
|
|
123
|
+
if (testing) { testAgain = true; return; }
|
|
124
|
+
testing = true;
|
|
125
|
+
await runTests(root);
|
|
126
|
+
testing = false;
|
|
127
|
+
if (testAgain) { testAgain = false; test(); }
|
|
128
|
+
}
|
|
129
|
+
test();
|
|
118
130
|
async function rebuild() {
|
|
119
131
|
if (running) {
|
|
120
132
|
pending = true;
|
|
@@ -130,6 +142,7 @@ export async function serve(args) {
|
|
|
130
142
|
} else {
|
|
131
143
|
console.log(`${green('✓')} ${t('rebuilt', { ms: Date.now() - started })}`);
|
|
132
144
|
send('reload');
|
|
145
|
+
test();
|
|
133
146
|
}
|
|
134
147
|
running = false;
|
|
135
148
|
if (pending) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Markup Home
|
|
2
|
+
main id="home"
|
|
3
|
+
p={@welcome.eyebrow} id="home-eyebrow"
|
|
4
|
+
h1={@welcome.title} id="home-title"
|
|
5
|
+
p={@welcome.lead} id="home-lead"
|
|
6
|
+
h2={@welcome.stepsTitle} id="home-steps-title"
|
|
7
|
+
ol id="home-steps"
|
|
8
|
+
li variant="home-step"
|
|
9
|
+
span={@welcome.stepPage}
|
|
10
|
+
code={aliens generate page about}
|
|
11
|
+
li variant="home-step"
|
|
12
|
+
span={@welcome.stepElement}
|
|
13
|
+
code={aliens generate element card}
|
|
14
|
+
li variant="home-step"
|
|
15
|
+
span={@welcome.stepExample}
|
|
16
|
+
code={project/app/elements/molecules/hero-card}
|
|
17
|
+
p id="home-links"
|
|
18
|
+
a={@welcome.docs} href="https://github.com/AliensSyndicate/aliens-syndicate-framework#readme" variant="home-link"
|
|
19
|
+
a={@welcome.npm} href="https://www.npmjs.com/package/@aliens-syndicate/cli" variant="home-link"
|