kintone-plugin-ide 0.3.0 → 0.4.0
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 -21
- package/README.md +125 -123
- package/dist/index.js +41 -315
- package/dist/kintone-plugin-ide.iife.js +442 -316
- package/package.json +62 -59
- package/src/build/build.js +104 -87
- package/src/config.js +56 -58
- package/src/deps.js +41 -41
- package/src/ide/actions/misc.js +74 -74
- package/src/ide/actions/npm.js +103 -103
- package/src/ide/actions/release.js +57 -57
- package/src/ide/actions/save.js +54 -54
- package/src/ide/actions/zip.js +59 -59
- package/src/ide/commands.js +96 -96
- package/src/ide/css.js +50 -50
- package/src/ide/dialog.js +51 -51
- package/src/ide/editor.js +155 -155
- package/src/ide/index.js +94 -94
- package/src/ide/layout.js +89 -89
- package/src/ide/sample.js +168 -168
- package/src/ide/state.js +58 -58
- package/src/ide/terminal.js +57 -57
- package/src/ide/tree.js +224 -224
- package/src/ide/workspace-fs.js +173 -173
- package/src/index.js +49 -48
- package/src/kintone/api.js +24 -24
- package/src/kintone/plugin.js +37 -37
- package/src/npm/registry.js +32 -32
- package/src/npm/vendor.js +69 -69
- package/src/util/bytes.js +15 -15
- package/src/util/dom.js +15 -15
- package/src/util/idb.js +18 -18
- package/src/util/path.js +14 -14
- package/src/util/settings.js +5 -5
- package/types/index.d.ts +49 -49
- package/src/build/http-plugin.js +0 -32
- package/src/build/transformers.js +0 -168
- package/src/build/vfs-plugin.js +0 -60
- package/src/packer/packer.js +0 -50
package/src/ide/state.js
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
// IDE が持つ状態。ファイルは path → text の Map(バイナリは "base64:...")
|
|
2
|
-
// レコードには、ソース一式を zip にして添付ファイルのフィールドに保存する。
|
|
3
|
-
import { F } from '../config.js';
|
|
4
|
-
import { zipSync, unzipSync } from 'fflate';
|
|
5
|
-
import { downloadFile } from '../kintone/api.js';
|
|
6
|
-
import { fromBytes, toBytes } from '../util/bytes.js';
|
|
7
|
-
import { normalize, isVendor } from '../util/path.js';
|
|
8
|
-
|
|
9
|
-
export async function readSources(record) {
|
|
10
|
-
const files = new Map(), dirs = new Set();
|
|
11
|
-
const f = record[F.source]?.value?.[0];
|
|
12
|
-
if (f) {
|
|
13
|
-
const entries = unzipSync(await downloadFile(f.fileKey));
|
|
14
|
-
for (const [raw, bytes] of Object.entries(entries)) {
|
|
15
|
-
const p = normalize(raw);
|
|
16
|
-
if (!p || isVendor(p)) continue;
|
|
17
|
-
if (raw.endsWith('/')) dirs.add(p); else files.set(p, fromBytes(bytes));
|
|
18
|
-
}
|
|
19
|
-
return { files, dirs, from: 'zip', name: f.name };
|
|
20
|
-
}
|
|
21
|
-
// 前の版(サブテーブル)からの引っ越し
|
|
22
|
-
const L = F.legacy;
|
|
23
|
-
for (const row of record[L?.files]?.value || []) {
|
|
24
|
-
const raw = row.value[L.path].value || '';
|
|
25
|
-
const p = normalize(raw);
|
|
26
|
-
if (!p || isVendor(p)) continue;
|
|
27
|
-
if (raw.endsWith('/')) dirs.add(p); else files.set(p, row.value[L.content].value || '');
|
|
28
|
-
}
|
|
29
|
-
return { files, dirs, from: files.size || dirs.size ? 'legacy' : 'empty' };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function createState({ files: loaded, dirs: loadedDirs, from }) {
|
|
33
|
-
const files = new Map(loaded); // 今の内容(node_modules も含む)
|
|
34
|
-
const saved = from === 'legacy' ? new Map() : new Map(loaded); // 引っ越し前は「全部未保存」扱いにして、保存で zip に移す
|
|
35
|
-
const dirs = new Set(loadedDirs); // 空でも残すフォルダ(zip には "foo/" として入れる)
|
|
36
|
-
const savedDirs = new Set(from === 'legacy' ? [] : loadedDirs);
|
|
37
|
-
const sourcePaths = () => [...files.keys()].filter((p) => !isVendor(p));
|
|
38
|
-
const dirty = () => {
|
|
39
|
-
const changed = sourcePaths().filter((p) => files.get(p) !== saved.get(p));
|
|
40
|
-
const removed = [...saved.keys()].filter((p) => !files.has(p));
|
|
41
|
-
const dirChanged = [...dirs].filter((d) => !savedDirs.has(d)).concat([...savedDirs].filter((d) => !dirs.has(d))).map((d) => d + '/');
|
|
42
|
-
return changed.concat(removed, dirChanged);
|
|
43
|
-
};
|
|
44
|
-
// 中にファイルがあるフォルダは、わざわざ覚えておかなくていい
|
|
45
|
-
const pruneDirs = () => { for (const d of dirs) if ([...files.keys()].some((f) => f.startsWith(d + '/'))) dirs.delete(d); };
|
|
46
|
-
async function toZip() {
|
|
47
|
-
pruneDirs();
|
|
48
|
-
const entries = {};
|
|
49
|
-
for (const p of sourcePaths().sort()) entries[p] = toBytes(files.get(p));
|
|
50
|
-
for (const d of dirs) entries[d + '/'] = new Uint8Array(0);
|
|
51
|
-
return zipSync(entries, { level: 9 });
|
|
52
|
-
}
|
|
53
|
-
const markSaved = () => {
|
|
54
|
-
saved.clear(); for (const p of sourcePaths()) saved.set(p, files.get(p));
|
|
55
|
-
savedDirs.clear(); for (const d of dirs) savedDirs.add(d);
|
|
56
|
-
};
|
|
57
|
-
return { files, saved, dirs, from, sourcePaths, dirty, toZip, markSaved, pruneDirs };
|
|
58
|
-
}
|
|
1
|
+
// IDE が持つ状態。ファイルは path → text の Map(バイナリは "base64:...")
|
|
2
|
+
// レコードには、ソース一式を zip にして添付ファイルのフィールドに保存する。
|
|
3
|
+
import { F } from '../config.js';
|
|
4
|
+
import { zipSync, unzipSync } from 'fflate';
|
|
5
|
+
import { downloadFile } from '../kintone/api.js';
|
|
6
|
+
import { fromBytes, toBytes } from '../util/bytes.js';
|
|
7
|
+
import { normalize, isVendor } from '../util/path.js';
|
|
8
|
+
|
|
9
|
+
export async function readSources(record) {
|
|
10
|
+
const files = new Map(), dirs = new Set();
|
|
11
|
+
const f = record[F.source]?.value?.[0];
|
|
12
|
+
if (f) {
|
|
13
|
+
const entries = unzipSync(await downloadFile(f.fileKey));
|
|
14
|
+
for (const [raw, bytes] of Object.entries(entries)) {
|
|
15
|
+
const p = normalize(raw);
|
|
16
|
+
if (!p || isVendor(p)) continue;
|
|
17
|
+
if (raw.endsWith('/')) dirs.add(p); else files.set(p, fromBytes(bytes));
|
|
18
|
+
}
|
|
19
|
+
return { files, dirs, from: 'zip', name: f.name };
|
|
20
|
+
}
|
|
21
|
+
// 前の版(サブテーブル)からの引っ越し
|
|
22
|
+
const L = F.legacy;
|
|
23
|
+
for (const row of record[L?.files]?.value || []) {
|
|
24
|
+
const raw = row.value[L.path].value || '';
|
|
25
|
+
const p = normalize(raw);
|
|
26
|
+
if (!p || isVendor(p)) continue;
|
|
27
|
+
if (raw.endsWith('/')) dirs.add(p); else files.set(p, row.value[L.content].value || '');
|
|
28
|
+
}
|
|
29
|
+
return { files, dirs, from: files.size || dirs.size ? 'legacy' : 'empty' };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function createState({ files: loaded, dirs: loadedDirs, from }) {
|
|
33
|
+
const files = new Map(loaded); // 今の内容(node_modules も含む)
|
|
34
|
+
const saved = from === 'legacy' ? new Map() : new Map(loaded); // 引っ越し前は「全部未保存」扱いにして、保存で zip に移す
|
|
35
|
+
const dirs = new Set(loadedDirs); // 空でも残すフォルダ(zip には "foo/" として入れる)
|
|
36
|
+
const savedDirs = new Set(from === 'legacy' ? [] : loadedDirs);
|
|
37
|
+
const sourcePaths = () => [...files.keys()].filter((p) => !isVendor(p));
|
|
38
|
+
const dirty = () => {
|
|
39
|
+
const changed = sourcePaths().filter((p) => files.get(p) !== saved.get(p));
|
|
40
|
+
const removed = [...saved.keys()].filter((p) => !files.has(p));
|
|
41
|
+
const dirChanged = [...dirs].filter((d) => !savedDirs.has(d)).concat([...savedDirs].filter((d) => !dirs.has(d))).map((d) => d + '/');
|
|
42
|
+
return changed.concat(removed, dirChanged);
|
|
43
|
+
};
|
|
44
|
+
// 中にファイルがあるフォルダは、わざわざ覚えておかなくていい
|
|
45
|
+
const pruneDirs = () => { for (const d of dirs) if ([...files.keys()].some((f) => f.startsWith(d + '/'))) dirs.delete(d); };
|
|
46
|
+
async function toZip() {
|
|
47
|
+
pruneDirs();
|
|
48
|
+
const entries = {};
|
|
49
|
+
for (const p of sourcePaths().sort()) entries[p] = toBytes(files.get(p));
|
|
50
|
+
for (const d of dirs) entries[d + '/'] = new Uint8Array(0);
|
|
51
|
+
return zipSync(entries, { level: 9 });
|
|
52
|
+
}
|
|
53
|
+
const markSaved = () => {
|
|
54
|
+
saved.clear(); for (const p of sourcePaths()) saved.set(p, files.get(p));
|
|
55
|
+
savedDirs.clear(); for (const d of dirs) savedDirs.add(d);
|
|
56
|
+
};
|
|
57
|
+
return { files, saved, dirs, from, sourcePaths, dirty, toZip, markSaved, pruneDirs };
|
|
58
|
+
}
|
package/src/ide/terminal.js
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
// ターミナル(xterm + xterm-readline)。ログの出力先でもある
|
|
2
|
-
import { loadXterm } from '../deps.js';
|
|
3
|
-
import { el } from '../util/dom.js';
|
|
4
|
-
import { normalize } from '../util/path.js';
|
|
5
|
-
|
|
6
|
-
const COLOR = { info: '\x1b[90m', ok: '\x1b[32m', warn: '\x1b[33m', error: '\x1b[31m', plain: '' };
|
|
7
|
-
|
|
8
|
-
export async function setupTerminal(ctx) {
|
|
9
|
-
const { ui } = ctx;
|
|
10
|
-
const { Terminal, FitAddon, Readline, css } = await loadXterm();
|
|
11
|
-
if (!document.getElementById('kpi-xterm-css')) document.head.append(el('link', { id: 'kpi-xterm-css', rel: 'stylesheet', href: css }));
|
|
12
|
-
const term = new Terminal({
|
|
13
|
-
fontSize: 12, fontFamily: 'ui-monospace,SFMono-Regular,Menlo,Consolas,monospace', cursorBlink: true, convertEol: true, scrollback: 5000,
|
|
14
|
-
theme: { background: '#0e0e0e', foreground: '#dddddd', cursor: '#68d391', selectionBackground: '#2b6cb055' },
|
|
15
|
-
});
|
|
16
|
-
const fit = new FitAddon();
|
|
17
|
-
const rl = new Readline();
|
|
18
|
-
term.loadAddon(fit); term.loadAddon(rl);
|
|
19
|
-
term.open(ui.termEl);
|
|
20
|
-
const ro = new ResizeObserver(() => { try { fit.fit(); } catch {} });
|
|
21
|
-
ro.observe(ui.termEl);
|
|
22
|
-
|
|
23
|
-
// "src/foo.ts:12:3" をクリックするとエディタのその行に飛ぶ / "/k/12/" はアプリを開く
|
|
24
|
-
term.registerLinkProvider({
|
|
25
|
-
provideLinks(y, cb) {
|
|
26
|
-
const text = term.buffer.active.getLine(y - 1)?.translateToString(true) || '';
|
|
27
|
-
const links = [];
|
|
28
|
-
for (const m of text.matchAll(/([\w./@-]+\.(?:tsx?|mts|jsx?|mjs|json|css|html|md)):(\d+)(?::(\d+))?|(\/k\/\d+\/)/g)) {
|
|
29
|
-
const x = [...text.slice(0, m.index)].reduce((w, ch) => w + (ch.charCodeAt(0) > 0x2e80 ? 2 : 1), 0) + 1;
|
|
30
|
-
links.push({
|
|
31
|
-
range: { start: { x, y }, end: { x: x + [...m[0]].length - 1, y } }, text: m[0],
|
|
32
|
-
activate: () => (m[4] ? window.open(m[4], '_blank') : ctx.openFile(normalize(m[1]), +m[2], +(m[3] || 1))),
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
cb(links);
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const log = ctx.log;
|
|
40
|
-
for (const level of Object.keys(COLOR)) {
|
|
41
|
-
log[level] = (text) => {
|
|
42
|
-
const time = `\x1b[2m${new Date().toLocaleTimeString()}\x1b[0m `;
|
|
43
|
-
rl.println(`${level === 'plain' ? '' : time}${COLOR[level]}${text}\x1b[0m`);
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
let alive = true;
|
|
48
|
-
const startRepl = () => (async () => {
|
|
49
|
-
while (alive) {
|
|
50
|
-
const line = await rl.read('\x1b[32m$\x1b[0m ');
|
|
51
|
-
if (!alive) break;
|
|
52
|
-
await ctx.run(() => ctx.command(line));
|
|
53
|
-
}
|
|
54
|
-
})();
|
|
55
|
-
const disposeTerminal = () => { alive = false; ro.disconnect(); term.dispose(); };
|
|
56
|
-
Object.assign(ctx, { term, rl, startRepl, disposeTerminal });
|
|
57
|
-
}
|
|
1
|
+
// ターミナル(xterm + xterm-readline)。ログの出力先でもある
|
|
2
|
+
import { loadXterm } from '../deps.js';
|
|
3
|
+
import { el } from '../util/dom.js';
|
|
4
|
+
import { normalize } from '../util/path.js';
|
|
5
|
+
|
|
6
|
+
const COLOR = { info: '\x1b[90m', ok: '\x1b[32m', warn: '\x1b[33m', error: '\x1b[31m', plain: '' };
|
|
7
|
+
|
|
8
|
+
export async function setupTerminal(ctx) {
|
|
9
|
+
const { ui } = ctx;
|
|
10
|
+
const { Terminal, FitAddon, Readline, css } = await loadXterm();
|
|
11
|
+
if (!document.getElementById('kpi-xterm-css')) document.head.append(el('link', { id: 'kpi-xterm-css', rel: 'stylesheet', href: css }));
|
|
12
|
+
const term = new Terminal({
|
|
13
|
+
fontSize: 12, fontFamily: 'ui-monospace,SFMono-Regular,Menlo,Consolas,monospace', cursorBlink: true, convertEol: true, scrollback: 5000,
|
|
14
|
+
theme: { background: '#0e0e0e', foreground: '#dddddd', cursor: '#68d391', selectionBackground: '#2b6cb055' },
|
|
15
|
+
});
|
|
16
|
+
const fit = new FitAddon();
|
|
17
|
+
const rl = new Readline();
|
|
18
|
+
term.loadAddon(fit); term.loadAddon(rl);
|
|
19
|
+
term.open(ui.termEl);
|
|
20
|
+
const ro = new ResizeObserver(() => { try { fit.fit(); } catch {} });
|
|
21
|
+
ro.observe(ui.termEl);
|
|
22
|
+
|
|
23
|
+
// "src/foo.ts:12:3" をクリックするとエディタのその行に飛ぶ / "/k/12/" はアプリを開く
|
|
24
|
+
term.registerLinkProvider({
|
|
25
|
+
provideLinks(y, cb) {
|
|
26
|
+
const text = term.buffer.active.getLine(y - 1)?.translateToString(true) || '';
|
|
27
|
+
const links = [];
|
|
28
|
+
for (const m of text.matchAll(/([\w./@-]+\.(?:tsx?|mts|jsx?|mjs|json|css|html|md)):(\d+)(?::(\d+))?|(\/k\/\d+\/)/g)) {
|
|
29
|
+
const x = [...text.slice(0, m.index)].reduce((w, ch) => w + (ch.charCodeAt(0) > 0x2e80 ? 2 : 1), 0) + 1;
|
|
30
|
+
links.push({
|
|
31
|
+
range: { start: { x, y }, end: { x: x + [...m[0]].length - 1, y } }, text: m[0],
|
|
32
|
+
activate: () => (m[4] ? window.open(m[4], '_blank') : ctx.openFile(normalize(m[1]), +m[2], +(m[3] || 1))),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
cb(links);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const log = ctx.log;
|
|
40
|
+
for (const level of Object.keys(COLOR)) {
|
|
41
|
+
log[level] = (text) => {
|
|
42
|
+
const time = `\x1b[2m${new Date().toLocaleTimeString()}\x1b[0m `;
|
|
43
|
+
rl.println(`${level === 'plain' ? '' : time}${COLOR[level]}${text}\x1b[0m`);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let alive = true;
|
|
48
|
+
const startRepl = () => (async () => {
|
|
49
|
+
while (alive) {
|
|
50
|
+
const line = await rl.read('\x1b[32m$\x1b[0m ');
|
|
51
|
+
if (!alive) break;
|
|
52
|
+
await ctx.run(() => ctx.command(line));
|
|
53
|
+
}
|
|
54
|
+
})();
|
|
55
|
+
const disposeTerminal = () => { alive = false; ro.disconnect(); term.dispose(); };
|
|
56
|
+
Object.assign(ctx, { term, rl, startRepl, disposeTerminal });
|
|
57
|
+
}
|