@prettifystudio/lyngo-cli 0.2.2 → 0.2.4

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.
Files changed (3) hide show
  1. package/README.md +8 -3
  2. package/bin/lyngo +52 -13
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -26,8 +26,10 @@ lyngo init # project, i18n setup, languages, agent hook
26
26
 
27
27
  1. Shows the workspace it uses. `--workspace <name>` picks another one.
28
28
  2. Finds the Lyngo project for the repository's `origin` remote, or creates it
29
- when you own the workspace. When GitHub is not connected yet, it prints the
30
- link to connect it and waits.
29
+ when you own the workspace. When the Lyngo GitHub App cannot read the
30
+ repository yet, it prints the GitHub link where you add it; in a terminal it
31
+ waits until you have, in an agent or a script it stops, and the next run
32
+ continues (`--wait` makes it wait anyway).
31
33
  3. Detects the framework and the i18n library.
32
34
  4. Sets the languages: `--languages fr,de`, or it asks.
33
35
  5. Applies the i18n setup as a patch to your working tree. It edits
@@ -45,6 +47,9 @@ already set up.
45
47
  - With an agent: build as usual. The hook runs `lyngo localize` at the end of
46
48
  every task.
47
49
  - Without an agent: run `lyngo localize` before you commit.
50
+ - A repository that was never localized: `lyngo localize --all` once. It walks
51
+ every source file a scan would read, in batches, and leaves the result in
52
+ your working tree to review and commit. No pull request.
48
53
  - Anything pushed without it still gets a pull request from the Lyngo GitHub
49
54
  App.
50
55
 
@@ -56,7 +61,7 @@ already set up.
56
61
  | `lyngo logout` | Revokes the token and deletes it from this machine |
57
62
  | `lyngo whoami` | The account, the token prefix and your workspaces |
58
63
  | `lyngo init` | Connects the repository (see above). Flags: `--languages`, `--workspace`, `--yes`, `--github` |
59
- | `lyngo localize` | Localizes and translates what changed in the working tree. Flags: `--languages`, `--dry` |
64
+ | `lyngo localize` | Localizes and translates what changed in the working tree. Flags: `--all` (the whole repository, in batches of 30), `--languages`, `--no-translate`, `--dry` |
60
65
  | `lyngo check <file>` | The user-facing strings of one file |
61
66
  | `lyngo status` | The project as Lyngo knows it |
62
67
 
package/bin/lyngo CHANGED
@@ -6,9 +6,9 @@
6
6
  // lyngo login sign in once; the token goes to ~/.config/lyngo/token
7
7
  // lyngo logout revoke the token and delete the file
8
8
  // lyngo whoami who the token belongs to
9
- // lyngo init [--languages fr,de] [--primary en] [--workspace <name>] [--yes] [--github]
9
+ // lyngo init [--languages fr,de] [--primary en] [--workspace <name>] [--yes] [--github] [--wait]
10
10
  // connect this repository: project, scaffolding, languages, agent hook
11
- // lyngo localize [--languages fr,de] [--no-translate] [--dry]
11
+ // lyngo localize [--all] [--languages fr,de] [--no-translate] [--dry]
12
12
  // localize (+ translate) the working tree's changes
13
13
  // lyngo check <file> the user-facing strings of one file
14
14
  // lyngo status the project as Lyngo knows it
@@ -228,6 +228,14 @@ async function connectProject(opts, remote, branch) {
228
228
  console.log(messageOf(r.data, r.status));
229
229
  if (r.data.connect_url) console.log(' ' + r.data.connect_url);
230
230
  if (!r.data.owner) { process.exitCode = 1; return null; }
231
+ // No person at a terminal (an agent, a script): waiting would only get
232
+ // the command killed by the caller's timeout. Say what to do and stop;
233
+ // the next run picks up where this one ended (corp2, 2026-10-24).
234
+ if (!process.stdin.isTTY && !opts.github && !opts.wait) {
235
+ console.log('WAITING FOR THE PERSON: open the link above, add the repository to the Lyngo GitHub App, then run lyngo init again.');
236
+ process.exitCode = 3;
237
+ return null;
238
+ }
231
239
  if (opts.github || await confirm('Open it now?', opts)) openUrl(r.data.connect_url);
232
240
  console.log('Waiting for GitHub (up to 10 minutes)...');
233
241
  const q = new URLSearchParams({ remote, ...(opts.workspace ? { workspace: opts.workspace } : {}) });
@@ -626,23 +634,48 @@ function changedFiles(top) {
626
634
  return [...out].sort();
627
635
  }
628
636
 
637
+ // Every tracked source file of the repository, as the scan would pick them:
638
+ // a quick local cut by extension and folder, then the server's own rules.
639
+ async function allSourceFiles(top) {
640
+ const tracked = git(['ls-files', '-z']).split('\0').filter(Boolean).filter((p) => SRC.test(p) && !SKIP.test(p) && fs.existsSync(path.join(top, p)));
641
+ if (tracked.length === 0) return [];
642
+ try {
643
+ const r = await call('select_files', { paths: tracked });
644
+ if (Array.isArray(r.paths)) return r.paths.filter((p) => tracked.includes(p));
645
+ } catch { /* an older server without the tool: the local cut stands */ }
646
+ return tracked;
647
+ }
648
+
629
649
  async function localize(opts) {
630
650
  const top = root();
631
651
  process.chdir(top);
632
652
  const status = await call('status', {});
633
- const folder = (status.i18n?.catalog_folder || 'lang').replace(/\/+$/, '');
634
653
  const langs = opts.languages || [status.primary_language, ...(status.languages || [])];
635
- const catalogs = [];
636
- for (const code of langs) {
637
- const p = path.join(folder, code + '.json');
638
- if (fs.existsSync(p)) catalogs.push({ path: p, content: fs.readFileSync(p, 'utf8') });
639
- }
640
- let files = changedFiles(top);
641
- if (files.length === 0) { console.log('lyngo: nothing changed in the working tree.'); return null; }
654
+ // Both catalog folders (Laravel's lang and the frontend's own), read again
655
+ // before EVERY call: a catalog the previous batch created must go back, or
656
+ // the server diffs it as new twice (corp1, 2026-10-18: "already exists").
657
+ const folders = [...new Set([status.i18n?.catalog_folder || 'lang', status.i18n?.js_catalog_folder].filter(Boolean).map((f) => f.replace(/\/+$/, '')))];
658
+ const catalogsNow = () => {
659
+ const out = [];
660
+ for (const folder of folders) for (const code of langs) {
661
+ const p = path.join(folder, code + '.json');
662
+ if (fs.existsSync(p)) out.push({ path: p, content: fs.readFileSync(p, 'utf8') });
663
+ }
664
+ return out;
665
+ };
666
+ // --all: the whole repository, not the changed files. The server picks the
667
+ // paths a scan would process out of the tracked tree (its own rules, so
668
+ // the two never drift); the batches of 30 below do the rest (2026-10-18).
669
+ let files = opts.all ? await allSourceFiles(top) : changedFiles(top);
670
+ if (files.length === 0) { console.log(opts.all ? 'lyngo: no source file of this project found in the repository.' : 'lyngo: nothing changed in the working tree.'); return null; }
671
+ const total = files.length;
672
+ if (opts.all) console.log(`lyngo: localizing ${total} file${total === 1 ? '' : 's'} in batches of 30 (${Math.ceil(total / 30)} call${total > 30 ? 's' : ''}); each batch applies before the next.`);
642
673
  const report = { files: [], added: [], reused: [], languages: {} };
674
+ let batch = 0;
643
675
  while (files.length) {
676
+ batch++;
644
677
  const payload = files.map((p) => ({ path: p, content: fs.readFileSync(p, 'utf8') }));
645
- const args = { files: payload, catalogs: catalogs.map((c) => ({ path: c.path, content: fs.existsSync(c.path) ? fs.readFileSync(c.path, 'utf8') : c.content })), format: 'patch' };
678
+ const args = { files: payload, catalogs: catalogsNow(), format: 'patch' };
646
679
  if (opts.languages) args.languages = opts.languages.filter((l) => l !== status.primary_language);
647
680
  // --no-translate: keys only, catalogs for translators. Without the flag the project's setting decides.
648
681
  if (opts['no-translate']) args.translate = false;
@@ -666,6 +699,11 @@ async function localize(opts) {
666
699
  report.languages[code] = cur;
667
700
  }
668
701
  files = r.deferred || [];
702
+ if (opts.all) {
703
+ const done = total - files.length;
704
+ const got = (r.report?.files || []).reduce((n, f) => n + (f.wrapped?.length || 0), 0);
705
+ console.log(` batch ${batch}: ${done}/${total} files, ${got} string${got === 1 ? '' : 's'} localized`);
706
+ }
669
707
  }
670
708
  const wrapped = report.files.reduce((n, f) => n + f.wrapped.length, 0);
671
709
  console.log(`lyngo: ${wrapped} string${wrapped === 1 ? '' : 's'} localized in ${report.files.length} file${report.files.length === 1 ? '' : 's'}; ${report.added.length} new key${report.added.length === 1 ? '' : 's'}, ${report.reused.length} reused.`);
@@ -705,14 +743,15 @@ const HELP = `lyngo ${version()}: localization for your repository, from the ter
705
743
  lyngo login sign in once (opens the browser)
706
744
  lyngo logout revoke the token and delete it from this machine
707
745
  lyngo whoami who the token belongs to
708
- lyngo init [--languages fr,de] [--primary en] [--workspace <name>] [--yes] [--github]
746
+ lyngo init [--languages fr,de] [--primary en] [--workspace <name>] [--yes] [--github] [--wait]
709
747
  connect this repository: project, i18n setup, languages, agent hook
710
748
  (--languages are the target languages; the source stays en unless --primary)
711
749
  lyngo onboard --run=<id> [--languages fr,de]
712
750
  the guided setup an agent follows, from lyngo.app/start; run it again to continue
713
- lyngo localize [--languages fr,de] [--no-translate] [--dry]
751
+ lyngo localize [--all] [--languages fr,de] [--no-translate] [--dry]
714
752
  localize what changed in the working tree, and translate it
715
753
  (--no-translate: keys only; the project setting "Translate when localizing" is the default)
754
+ (--all: the whole repository instead of the changed files, in batches of 30)
716
755
  lyngo translate <code> [<code>…] fill every key a language's catalog lacks, from the primary catalog
717
756
  lyngo check <file> the user-facing strings of one file
718
757
  lyngo status the project as Lyngo knows it
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prettifystudio/lyngo-cli",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Localization for Laravel applications, from the terminal: Lyngo wraps user-facing text with your framework's i18n call, reuses your project's keys, translates and verifies the catalogs. Blade, Livewire, PHP, and Inertia with React, Vue or Svelte.",
5
5
  "bin": {
6
6
  "lyngo": "bin/lyngo"