@fave1/create-app 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +52 -2
- package/dist/create-app.js +247 -0
- package/dist/reserved-ids.js +2 -0
- package/package.json +29 -4
- package/templates/break/README.md +88 -0
- package/templates/break/_gitignore +5 -0
- package/templates/break/icon.png +0 -0
- package/templates/break/manifest.json +11 -0
- package/templates/break/package.json +18 -0
- package/templates/break/src/index.ts +64 -0
- package/templates/break/tsconfig.json +15 -0
- package/templates/break/types/fave1.d.ts +499 -0
- package/templates/minimal/README.md +88 -0
- package/templates/minimal/_gitignore +5 -0
- package/templates/minimal/icon.png +0 -0
- package/templates/minimal/manifest.json +11 -0
- package/templates/minimal/package.json +18 -0
- package/templates/minimal/src/index.ts +10 -0
- package/templates/minimal/tsconfig.json +15 -0
- package/templates/minimal/types/fave1.d.ts +499 -0
- package/templates/panel/README.md +88 -0
- package/templates/panel/_gitignore +5 -0
- package/templates/panel/icon.png +0 -0
- package/templates/panel/manifest.json +11 -0
- package/templates/panel/package.json +18 -0
- package/templates/panel/src/index.ts +25 -0
- package/templates/panel/tsconfig.json +15 -0
- package/templates/panel/types/fave1.d.ts +499 -0
- package/templates/storage/README.md +93 -0
- package/templates/storage/_gitignore +5 -0
- package/templates/storage/icon.png +0 -0
- package/templates/storage/manifest.json +11 -0
- package/templates/storage/package.json +18 -0
- package/templates/storage/src/index.ts +66 -0
- package/templates/storage/tsconfig.json +15 -0
- package/templates/storage/types/fave1.d.ts +499 -0
- package/templates/templates.json +6 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fave Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,53 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @fave1/create-app
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Start a [Fave1](https://developers.fave1.com) app.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm create @fave1/app my-app
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Pick a template, or name one — and give the app a display name if it should differ
|
|
10
|
+
from what you typed:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm create @fave1/app my-app -- --template panel --name "My App"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Flags go after `--` so npm passes them on. The first word becomes the app ID —
|
|
17
|
+
Latin letters, digits and hyphens, up to 48. The display name (`--name`) can be
|
|
18
|
+
anything, in any language, up to 40 characters:
|
|
19
|
+
`npm create @fave1/app my-app -- --name "Café Crème ☕"`.
|
|
20
|
+
|
|
21
|
+
Where it goes: `my-app` makes a `my-app` folder here. `.` uses the folder you're in —
|
|
22
|
+
it has to be empty, and the ID comes from its name. `apps/my-app` makes `my-app`
|
|
23
|
+
inside `apps`, which has to exist already.
|
|
24
|
+
|
|
25
|
+
The ID becomes permanent once you create the app in the console
|
|
26
|
+
([developers.fave1.com/apps](https://developers.fave1.com/apps?create=1)) — use the
|
|
27
|
+
same ID there, since uploads go to the app with that ID. Some IDs are taken —
|
|
28
|
+
our own (`www`, `api`, `settings` …) and Fave1's apps (`notes`, `images` …); the
|
|
29
|
+
scaffold tells you when you pick one. You need Node.js 20 or newer, and Fave1 in
|
|
30
|
+
your bookmarks bar to try your app on real sites —
|
|
31
|
+
[www.fave1.com/get-started](https://www.fave1.com/get-started).
|
|
32
|
+
|
|
33
|
+
| Template | |
|
|
34
|
+
|---|---|
|
|
35
|
+
| `minimal` | `manifest.json` + `index.ts` |
|
|
36
|
+
| `panel` | block UI example, no permissions |
|
|
37
|
+
| `break` | `page` permission — full DOM |
|
|
38
|
+
| `storage` | `storage` permission — keeps data on the person’s Fave1 account |
|
|
39
|
+
|
|
40
|
+
## What it makes
|
|
41
|
+
|
|
42
|
+
Behavior lives in `src/index.ts`. Everything else — id, name, icon, permissions
|
|
43
|
+
— lives in `manifest.json`. The store reads that manifest **without running your
|
|
44
|
+
code**, and the shell builds a permission-scoped `ctx` from it before calling
|
|
45
|
+
`onLaunch`. Your bundle cannot ask for more than the manifest declares.
|
|
46
|
+
|
|
47
|
+
`npm run build` type-checks and bundles `src/index.ts` — and anything it imports, CSS
|
|
48
|
+
and SVG as text and PNG, JPEG, GIF and WebP as data URLs included — into one classic
|
|
49
|
+
script, `dist/index.js`. That one file is what ships. `npm run dev` rebuilds on save
|
|
50
|
+
with the same esbuild command (`npm run bundle`). Guides:
|
|
51
|
+
[developers.fave1.com/docs](https://developers.fave1.com/docs).
|
|
52
|
+
|
|
53
|
+
MIT
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const readline = require('readline');
|
|
6
|
+
const TEMPLATES = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'templates', 'templates.json'), 'utf8'));
|
|
7
|
+
const TEMPLATE_IDS = TEMPLATES.map((t) => t.id);
|
|
8
|
+
const ORIGIN = 'https://developers.fave1.com';
|
|
9
|
+
const GET_STARTED = 'https://www.fave1.com/get-started';
|
|
10
|
+
const RESERVED = (() => { try {
|
|
11
|
+
return require('./reserved-ids.js');
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return [];
|
|
15
|
+
} })();
|
|
16
|
+
const NAME_MAX = 40;
|
|
17
|
+
const ID_MAX = 48;
|
|
18
|
+
function die(msg, hint) {
|
|
19
|
+
process.stderr.write(`\n ✗ ${msg}\n`);
|
|
20
|
+
if (hint)
|
|
21
|
+
process.stderr.write(` ${hint}\n`);
|
|
22
|
+
process.stderr.write('\n');
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
function slug(name, full) {
|
|
26
|
+
const s = String(name).normalize('NFKD').replace(/[\u0300-\u036f]/g, '').toLowerCase().trim()
|
|
27
|
+
.replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
28
|
+
return full ? s : s.slice(0, ID_MAX).replace(/-+$/, '');
|
|
29
|
+
}
|
|
30
|
+
function clip(text, max) {
|
|
31
|
+
if (text.length <= max)
|
|
32
|
+
return text;
|
|
33
|
+
let out = text.slice(0, max);
|
|
34
|
+
if (/[\uD800-\uDBFF]$/.test(out))
|
|
35
|
+
out = out.slice(0, -1);
|
|
36
|
+
const space = out.lastIndexOf(' ');
|
|
37
|
+
if (text[out.length] !== ' ' && space >= max / 2)
|
|
38
|
+
out = out.slice(0, space);
|
|
39
|
+
return out.trim();
|
|
40
|
+
}
|
|
41
|
+
function isEmptyDir(dir) {
|
|
42
|
+
return fs.readdirSync(dir).every((n) => n === '.git' || n === '.DS_Store');
|
|
43
|
+
}
|
|
44
|
+
function nameFromId(id) {
|
|
45
|
+
return id.split('-').filter(Boolean).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(' ');
|
|
46
|
+
}
|
|
47
|
+
function ask(question) {
|
|
48
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
49
|
+
return new Promise((resolve) => rl.question(question, (a) => { rl.close(); resolve(a); }));
|
|
50
|
+
}
|
|
51
|
+
async function pickTemplate(flag) {
|
|
52
|
+
if (flag !== null) {
|
|
53
|
+
if (!flag)
|
|
54
|
+
die('--template needs a name.', `Try: ${TEMPLATE_IDS.join(' · ')}`);
|
|
55
|
+
const t = TEMPLATES.find((x) => x.id === flag);
|
|
56
|
+
if (!t)
|
|
57
|
+
die(`No template called "${flag}".`, `Try: ${TEMPLATE_IDS.join(' · ')}`);
|
|
58
|
+
return t.id;
|
|
59
|
+
}
|
|
60
|
+
if (!process.stdin.isTTY)
|
|
61
|
+
return 'minimal';
|
|
62
|
+
process.stdout.write('\n Template\n');
|
|
63
|
+
TEMPLATES.forEach((t, i) => {
|
|
64
|
+
process.stdout.write(` ${i + 1}. ${t.label.padEnd(16)} ${t.hint}\n`);
|
|
65
|
+
});
|
|
66
|
+
for (;;) {
|
|
67
|
+
const a = (await ask(`\n Pick (1-${TEMPLATES.length}, enter = 1): `)).trim();
|
|
68
|
+
const n = a === '' ? 1 : Number(a);
|
|
69
|
+
const t = TEMPLATES[n - 1] || TEMPLATES.find((x) => x.id === a);
|
|
70
|
+
if (t)
|
|
71
|
+
return t.id;
|
|
72
|
+
process.stdout.write(` Type a number from 1 to ${TEMPLATES.length}.\n`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const TEXT = /(\.(md|json|ts|js|mjs|cjs|css|html|txt|svg)|^\.gitignore|^_gitignore)$/i;
|
|
76
|
+
function copyTemplate(from, to, vars) {
|
|
77
|
+
for (const entry of fs.readdirSync(from, { withFileTypes: true })) {
|
|
78
|
+
const src = path.join(from, entry.name);
|
|
79
|
+
const name = entry.name === '_gitignore' ? '.gitignore' : entry.name;
|
|
80
|
+
const dst = path.join(to, name);
|
|
81
|
+
if (entry.isDirectory()) {
|
|
82
|
+
fs.mkdirSync(dst, { recursive: true });
|
|
83
|
+
copyTemplate(src, dst, vars);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
fs.mkdirSync(path.dirname(dst), { recursive: true });
|
|
87
|
+
if (!TEXT.test(name)) {
|
|
88
|
+
fs.copyFileSync(src, dst);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
let text = fs.readFileSync(src, 'utf8');
|
|
92
|
+
const esc = /\.json$/.test(name) ? (v) => JSON.stringify(v).slice(1, -1)
|
|
93
|
+
: /\.(ts|js)$/.test(name) ? (v) => v.replace(/\\/g, '\\\\').replace(/'/g, "\\'")
|
|
94
|
+
: (v) => v;
|
|
95
|
+
for (const [k, v] of Object.entries(vars))
|
|
96
|
+
text = text.split(`{{${k}}}`).join(esc(v));
|
|
97
|
+
fs.writeFileSync(dst, text);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function parseArgs(argv, env) {
|
|
101
|
+
let flag = null;
|
|
102
|
+
let nameFlag = '';
|
|
103
|
+
const rest = [];
|
|
104
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
105
|
+
const a = argv[i];
|
|
106
|
+
if (a === '--')
|
|
107
|
+
continue;
|
|
108
|
+
if (a === '--template' || a === '-t') {
|
|
109
|
+
const v = argv[i + 1];
|
|
110
|
+
if (v !== undefined && !v.startsWith('-')) {
|
|
111
|
+
flag = v;
|
|
112
|
+
i += 1;
|
|
113
|
+
}
|
|
114
|
+
else
|
|
115
|
+
flag = '';
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (a.startsWith('--template=')) {
|
|
119
|
+
flag = a.slice('--template='.length);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (a === '--name' || a === '-n') {
|
|
123
|
+
const v = argv[i + 1];
|
|
124
|
+
if (v === undefined || v.startsWith('-'))
|
|
125
|
+
die('--name needs a value.', 'npm create @fave1/app my-app -- --name "My App"');
|
|
126
|
+
nameFlag = v;
|
|
127
|
+
i += 1;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (a.startsWith('--name=')) {
|
|
131
|
+
nameFlag = a.slice('--name='.length);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (a.startsWith('-'))
|
|
135
|
+
die(`Unknown option ${a}.`, 'npm create @fave1/app my-app -- --template panel --name "My App"');
|
|
136
|
+
rest.push(a);
|
|
137
|
+
}
|
|
138
|
+
const leftovers = rest.slice(1);
|
|
139
|
+
const envTemplate = env.npm_config_template;
|
|
140
|
+
if (flag === null && envTemplate !== undefined && envTemplate !== 'true' && envTemplate !== '')
|
|
141
|
+
flag = envTemplate;
|
|
142
|
+
if (flag === null) {
|
|
143
|
+
const at = leftovers.findIndex((x) => TEMPLATE_IDS.includes(x));
|
|
144
|
+
if (at >= 0)
|
|
145
|
+
flag = leftovers.splice(at, 1)[0];
|
|
146
|
+
else if (envTemplate === 'true')
|
|
147
|
+
flag = leftovers.length ? leftovers.shift() : '';
|
|
148
|
+
}
|
|
149
|
+
const envName = env.npm_config_name;
|
|
150
|
+
if (!nameFlag && envName !== undefined && envName !== 'true' && envName !== '')
|
|
151
|
+
nameFlag = envName;
|
|
152
|
+
else if (!nameFlag && envName === 'true' && leftovers.length)
|
|
153
|
+
nameFlag = leftovers.shift();
|
|
154
|
+
if (leftovers.length) {
|
|
155
|
+
process.stderr.write(`\n ! Ignored ${leftovers.map((x) => JSON.stringify(x)).join(' ')} — flags go after --:\n`);
|
|
156
|
+
process.stderr.write(' npm create @fave1/app my-app -- --template panel --name "My App"\n');
|
|
157
|
+
}
|
|
158
|
+
return { flag, nameFlag, arg: rest[0] };
|
|
159
|
+
}
|
|
160
|
+
async function main() {
|
|
161
|
+
const { flag, nameFlag, arg } = parseArgs(process.argv.slice(2), process.env);
|
|
162
|
+
const typed = arg || (process.stdin.isTTY ? (await ask('\n App name: ')).trim() : '');
|
|
163
|
+
if (!typed)
|
|
164
|
+
die('Give it a name.', 'npm create @fave1/app my-app -- --template panel');
|
|
165
|
+
const cwd = process.cwd();
|
|
166
|
+
const pathLike = !!arg && (arg === '.' || arg === '..' || arg.includes('/') || (path.sep === '\\' && arg.includes('\\')));
|
|
167
|
+
let raw = typed;
|
|
168
|
+
let parent = cwd;
|
|
169
|
+
let here = null;
|
|
170
|
+
if (pathLike) {
|
|
171
|
+
const target = path.resolve(cwd, arg);
|
|
172
|
+
const lastSeg = arg.replace(/[\\/]+$/, '').split(/[\\/]/).pop();
|
|
173
|
+
raw = path.basename(target);
|
|
174
|
+
if (lastSeg === '.' || lastSeg === '..' || lastSeg === '') {
|
|
175
|
+
here = target;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
parent = path.dirname(target);
|
|
179
|
+
if (!fs.existsSync(parent) || !fs.statSync(parent).isDirectory()) {
|
|
180
|
+
die(`${path.relative(cwd, parent) || parent} isn’t a folder here.`, `Make it first, or create the app where you are: npm create @fave1/app ${slug(raw) || 'my-app'}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const id = slug(raw);
|
|
185
|
+
if (!id) {
|
|
186
|
+
const shown = raw.trim().replace(/"/g, '\\"');
|
|
187
|
+
if (here) {
|
|
188
|
+
die(`The app ID comes from the folder name, and “${raw}” has no Latin letters or numbers.`, `Rename the folder, or make a new one: npm create @fave1/app my-app -- --name "${shown}"`);
|
|
189
|
+
}
|
|
190
|
+
die('The app ID needs Latin letters or numbers — the name you typed has none.', `The display name can be anything: npm create @fave1/app my-app -- --name "${shown}"`);
|
|
191
|
+
}
|
|
192
|
+
const notes = [];
|
|
193
|
+
if (slug(raw, true).length > ID_MAX)
|
|
194
|
+
notes.push(`The app ID can be up to ${ID_MAX} characters — it’s ${id}.`);
|
|
195
|
+
const wanted = nameFlag.trim() || (raw.trim() === slug(raw, true) ? nameFromId(slug(raw, true)) : raw.trim());
|
|
196
|
+
const name = clip(wanted, NAME_MAX);
|
|
197
|
+
if (name !== wanted)
|
|
198
|
+
notes.push(`The display name can be up to ${NAME_MAX} characters — it’s “${name}”. Change "name" in manifest.json any time.`);
|
|
199
|
+
const dir = here || path.join(parent, arg && /^[\w.-]+$/.test(raw.trim()) ? raw.trim() : id);
|
|
200
|
+
if (fs.existsSync(dir) && (!fs.statSync(dir).isDirectory() || !isEmptyDir(dir))) {
|
|
201
|
+
if (here)
|
|
202
|
+
die('This folder isn’t empty.', `Run it in an empty folder, or make a new one: npm create @fave1/app ${id}`);
|
|
203
|
+
const what = fs.statSync(dir).isDirectory() ? "already exists and isn't empty" : 'is already a file here';
|
|
204
|
+
die(`${path.basename(dir)} ${what}.`, `Pick another name: npm create @fave1/app ${id}-2`);
|
|
205
|
+
}
|
|
206
|
+
const template = await pickTemplate(flag);
|
|
207
|
+
const from = path.join(__dirname, '..', 'templates', template);
|
|
208
|
+
if (!fs.existsSync(from))
|
|
209
|
+
die(`Template "${template}" is missing.`);
|
|
210
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
211
|
+
copyTemplate(from, dir, { id, name });
|
|
212
|
+
const relRaw = path.relative(cwd, dir);
|
|
213
|
+
const rel = /^[\w./-]+$/.test(relRaw) ? relRaw : `"${relRaw}"`;
|
|
214
|
+
process.stdout.write(`\n ✓ ${name} · ${id}\n`);
|
|
215
|
+
process.stdout.write(` ${TEMPLATES.find((t) => t.id === template).label}\n`);
|
|
216
|
+
for (const n of notes)
|
|
217
|
+
process.stdout.write(` ! ${n}\n`);
|
|
218
|
+
process.stdout.write('\n');
|
|
219
|
+
if (relRaw)
|
|
220
|
+
process.stdout.write(` cd ${rel}\n`);
|
|
221
|
+
process.stdout.write(' npm install\n');
|
|
222
|
+
process.stdout.write(' npm run dev\n\n');
|
|
223
|
+
process.stdout.write(` No Fave1 in your bookmarks bar yet? Add it first: ${GET_STARTED}\n\n`);
|
|
224
|
+
if (RESERVED.includes(id)) {
|
|
225
|
+
const alt = [`${id}-app`, `my-${id}`].find((x) => x.length <= ID_MAX && !RESERVED.includes(x)) || `${id}-2`;
|
|
226
|
+
process.stdout.write(` ! “${id}” is taken on Fave1 — the console won’t create an app with that ID.\n`);
|
|
227
|
+
process.stdout.write(` Change "id" in manifest.json (and "name" in package.json) before you create it — for example to ${alt}.\n`);
|
|
228
|
+
process.stdout.write(` Then create it at ${ORIGIN}/apps?create=1 with that ID.\n\n`);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
process.stdout.write(` The ID ${id} becomes permanent once you create the app in the console — the store URL is built from it.\n`);
|
|
232
|
+
process.stdout.write(` Create it at ${ORIGIN}/apps?create=1 with the id "${id}" — uploads go to the app with that ID.\n\n`);
|
|
233
|
+
}
|
|
234
|
+
const FS_SAYS = {
|
|
235
|
+
ENOTDIR: 'a file is in the way — part of that path is a file, not a folder',
|
|
236
|
+
EACCES: 'no permission to write there',
|
|
237
|
+
EPERM: 'no permission to write there',
|
|
238
|
+
EEXIST: 'something with that name is already there',
|
|
239
|
+
ENOSPC: 'the disk is full',
|
|
240
|
+
EROFS: 'that disk is read-only',
|
|
241
|
+
};
|
|
242
|
+
main().catch((e) => {
|
|
243
|
+
const code = e && e.code;
|
|
244
|
+
if (code && FS_SAYS[code])
|
|
245
|
+
die(`Couldn't make the app — ${FS_SAYS[code]}.`, e.path ? `${e.path}` : undefined);
|
|
246
|
+
die('Something went wrong.', String(e && e.message || e));
|
|
247
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
module.exports = ["admin", "api", "apps", "auth", "bridge", "buddy", "chomp", "collab", "cram", "developers", "docs", "fave1", "favorites", "fonts", "get-started", "hello", "home", "images", "lucky-ladder", "myapps", "notes", "page-break", "party", "quotebook", "screenshot", "settings", "share", "show-me", "signin", "site-quake", "site-raid", "slugger", "sticky", "vibes", "www"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fave1/create-app",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Start a Fave1 app.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"fave1",
|
|
7
|
+
"scaffold",
|
|
8
|
+
"create",
|
|
9
|
+
"apps"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"homepage": "https://developers.fave1.com",
|
|
13
|
+
"bin": {
|
|
14
|
+
"create-app": "dist/create-app.js"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"prepack": "node ../../tools/strip-comments.mjs"
|
|
18
|
+
},
|
|
19
|
+
"type": "commonjs",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"templates",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# {{name}}
|
|
2
|
+
|
|
3
|
+
A Fave1 app. Behavior lives in `src/index.ts`; everything else — id, name, icon,
|
|
4
|
+
permissions — lives in `manifest.json`. The store reads the manifest **without
|
|
5
|
+
running your code**, and the shell builds a permission-scoped `ctx` from it.
|
|
6
|
+
|
|
7
|
+
You need Node.js 20 or newer, and Chrome or Edge on a computer while you build —
|
|
8
|
+
Safari blocks `http://localhost` on https sites, so your local build can't load there.
|
|
9
|
+
To check Safari, upload and press **Test** in Versions (below). You test on real
|
|
10
|
+
sites through Fave1 in your bookmarks bar — no Fave1 there yet? Add it first at
|
|
11
|
+
[www.fave1.com/get-started](https://www.fave1.com/get-started).
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install
|
|
15
|
+
npm run dev # serves your app at http://localhost:7300 — leave it running
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Open Fave1 from your bookmarks bar on any shop or article, hold the Fave1 logo,
|
|
19
|
+
paste `http://localhost:7300` and save. Your app shows up first with a DEV badge.
|
|
20
|
+
Chrome asks once per site to allow local network access — allow it, and press
|
|
21
|
+
Save again if the panel already said it found nothing. Save a file, reopen the
|
|
22
|
+
app, and it's the new build. Changed
|
|
23
|
+
`manifest.json`? Close Fave1 and click it in your bookmarks bar again — reopening
|
|
24
|
+
the app isn't enough. Port 7300 taken? `npm run dev -- --port 7400`.
|
|
25
|
+
Leave that terminal running and type everything else — `npm run submit` too — in a
|
|
26
|
+
second one; a command typed where the dev server runs does nothing.
|
|
27
|
+
|
|
28
|
+
## Ship it
|
|
29
|
+
|
|
30
|
+
Once, in the console: **Create app** at
|
|
31
|
+
[developers.fave1.com/apps](https://developers.fave1.com/apps) with the same ID as
|
|
32
|
+
`id` in `manifest.json` (`{{id}}`) — uploads go to the app with that ID. Then make a
|
|
33
|
+
publish key at [developers.fave1.com/keys](https://developers.fave1.com/keys) and put
|
|
34
|
+
it in a `.env` file in this folder (it's git-ignored):
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
FAVE1_KEY=f1_live_…
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`icon.png` is a placeholder so your DEV build has something to show in the launcher. Make
|
|
41
|
+
your own icon and upload it in the console's **Listing** tab (512×512 PNG or JPEG, square
|
|
42
|
+
corners) — the store doesn't read this file. Apps that use this placeholder are rejected
|
|
43
|
+
in review.
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm run submit # builds, then uploads dist/index.js
|
|
47
|
+
npm run submit -- --whats-new "Remembers your place" # with a line for the store
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
It prints a **Test** link — your app on its own home (`{{id}}.fave1.app`), in any
|
|
51
|
+
browser, for 12 hours. That's how you see the home screen (`ctx.surface === 'app'`)
|
|
52
|
+
on a phone or in Safari. On your laptop, the build you saved as the DEV source also
|
|
53
|
+
shows up in [My Fave1](https://www.fave1.com/myapps) — open it there to try its home
|
|
54
|
+
in a window.
|
|
55
|
+
|
|
56
|
+
That window opens phone-size. Built your home to use more room? Add
|
|
57
|
+
`"window": "medium"` (760 wide) or `"window": "wide"` (1120) to `manifest.json` — it
|
|
58
|
+
opens that wide when the screen allows, and people can still resize it. Phones always
|
|
59
|
+
get the full screen.
|
|
60
|
+
|
|
61
|
+
An exported `FAVE1_KEY` in your terminal or CI wins over `.env.local`, which wins
|
|
62
|
+
over `.env`.
|
|
63
|
+
|
|
64
|
+
**Uploading does not make it public.** The build lands in **Versions** as Ready;
|
|
65
|
+
you press **Submit for review** in the console. That split is deliberate — a
|
|
66
|
+
listing sent to review half-empty gets rejected by default.
|
|
67
|
+
|
|
68
|
+
Next to each build in Versions, **Test** gives you the same kind of link — Safari,
|
|
69
|
+
an iPad, a teammate's laptop. While a build is still Ready, `npm run submit` with
|
|
70
|
+
the same version replaces it; once it has gone to review, bump the version —
|
|
71
|
+
`npx fave1 version patch` updates `manifest.json`, `package.json` and
|
|
72
|
+
`package-lock.json` together. An update needs a version above the live one.
|
|
73
|
+
|
|
74
|
+
## Split your code however you like
|
|
75
|
+
|
|
76
|
+
`npm run build` type-checks with `tsc` and bundles `src/index.ts` — and everything
|
|
77
|
+
it imports, npm packages included — into one classic script (`dist/index.js`,
|
|
78
|
+
esbuild). That single file is what the shell loads and what `npm run submit`
|
|
79
|
+
uploads; keep it under 512 KB. CSS and SVG files you import come in as text, pictures
|
|
80
|
+
(PNG, JPEG, GIF, WebP) as `data:` URLs (`import css from './panel.css'`), so they ship
|
|
81
|
+
inside it too. `npm run dev` rebuilds with the same esbuild command on every save
|
|
82
|
+
(`npm run bundle`), so what you try is what you ship.
|
|
83
|
+
On sites with a strict security policy a `<style>` element is blocked — style with
|
|
84
|
+
`new CSSStyleSheet()` + `replaceSync(css)` + `adoptedStyleSheets`, or
|
|
85
|
+
`el.style.cssText`. `Fave1` is a global the runtime provides while your bundle runs — call
|
|
86
|
+
`Fave1.defineApp` once, at the top; there is nothing to import for it. The types are in `types/fave1.d.ts`.
|
|
87
|
+
|
|
88
|
+
Docs: [developers.fave1.com/docs](https://developers.fave1.com/docs)
|
|
Binary file
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{id}}",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "tsc --noEmit && npm run bundle",
|
|
7
|
+
"watch": "npm run bundle -- --watch",
|
|
8
|
+
"bundle": "esbuild src/index.ts --bundle --format=iife --target=es2019 --loader:.css=text --loader:.svg=text --loader:.png=dataurl --loader:.jpg=dataurl --loader:.jpeg=dataurl --loader:.gif=dataurl --loader:.webp=dataurl --outfile=dist/index.js",
|
|
9
|
+
"check": "tsc --noEmit",
|
|
10
|
+
"dev": "fave1 dev",
|
|
11
|
+
"submit": "npm run build && fave1 submit"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@fave1/cli": "^0.1.0",
|
|
15
|
+
"esbuild": "^0.25.0",
|
|
16
|
+
"typescript": "^5.7.0"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// `page` is the live DOM. People see “Changes this page freely.”
|
|
2
|
+
// Only reading text? Declare `page.text` instead — review goes faster.
|
|
3
|
+
// The images this app changed, and the filter each one had before.
|
|
4
|
+
const touched = new Map<HTMLElement, string>();
|
|
5
|
+
|
|
6
|
+
Fave1.defineApp({
|
|
7
|
+
onLaunch(ctx) {
|
|
8
|
+
const ui = ctx.ui;
|
|
9
|
+
|
|
10
|
+
// At home — your own <id>.fave1.app, opened from My Fave1 — there's no site to change.
|
|
11
|
+
// Say what the app does on one instead of draining your own page.
|
|
12
|
+
if (ctx.surface === 'app') {
|
|
13
|
+
ui.render([
|
|
14
|
+
ui.heading('{{name}}'),
|
|
15
|
+
ui.text('Drains the color from every picture on the page you’re reading.'),
|
|
16
|
+
ui.muted('Open any shop or article, click Fave1 in your bookmarks bar, and pick {{name}}.'),
|
|
17
|
+
]);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// People can switch `page` off in Fave1 settings — then none of ctx.page's DOM is there.
|
|
22
|
+
// Checking `document` once also tells TypeScript the rest of ctx.page is there.
|
|
23
|
+
const page = ctx.page;
|
|
24
|
+
if (!ctx.can('page') || !page.document) {
|
|
25
|
+
ui.render([
|
|
26
|
+
ui.heading('{{name}}'),
|
|
27
|
+
ui.empty('🔒', 'Page access is off for {{name}}.'),
|
|
28
|
+
ui.button('Turn it on in settings', { variant: 'ghost', onClick: () => ctx.perms.open() }),
|
|
29
|
+
]);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let on = false;
|
|
34
|
+
|
|
35
|
+
const toggle = () => {
|
|
36
|
+
on = !on;
|
|
37
|
+
page.queryAll('img').forEach((img) => {
|
|
38
|
+
// Remember what the site had, so putting it back doesn't wipe the site's own styles.
|
|
39
|
+
if (!touched.has(img)) touched.set(img, img.style.filter);
|
|
40
|
+
img.style.filter = on ? 'grayscale(1)' : touched.get(img) ?? '';
|
|
41
|
+
});
|
|
42
|
+
draw();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const draw = () => {
|
|
46
|
+
ui.render([
|
|
47
|
+
ui.heading('{{name}}'),
|
|
48
|
+
ui.muted(`${page.queryAll('img').length} images on this page`),
|
|
49
|
+
ui.button(on ? 'Put the color back' : 'Drain the color', {
|
|
50
|
+
variant: on ? 'ghost' : 'purple',
|
|
51
|
+
onClick: toggle,
|
|
52
|
+
}),
|
|
53
|
+
]);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
draw();
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
// Changed the page? Put it back on the way out — only what you touched.
|
|
60
|
+
onDestroy() {
|
|
61
|
+
touched.forEach((filter, img) => { img.style.filter = filter; });
|
|
62
|
+
touched.clear();
|
|
63
|
+
},
|
|
64
|
+
});
|