create-rsc-kit 0.22.3 → 0.22.5
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/init.d.ts +18 -0
- package/dist/init.js +48 -3
- package/package.json +1 -1
package/dist/init.d.ts
CHANGED
|
@@ -33,6 +33,24 @@ export declare function isFreshDirectory(dir: string): boolean;
|
|
|
33
33
|
export declare function projectMarker(dir: string): string | null;
|
|
34
34
|
export declare function detect(dir: string): Detected;
|
|
35
35
|
export declare function initialise(o: Options, found: Detected, dir: string): Step[];
|
|
36
|
+
/**
|
|
37
|
+
* What init assumes when nobody says: whether to offer Tailwind first, and
|
|
38
|
+
* whether to install.
|
|
39
|
+
*
|
|
40
|
+
* An existing JavaScript project has a package manager and a lockfile of its
|
|
41
|
+
* own - `bun install` in an npm project writes a second lockfile - and its own
|
|
42
|
+
* styling, so init installs nothing there and adds Tailwind only where it
|
|
43
|
+
* already is. A project with no package.json (a Go service) has neither: init
|
|
44
|
+
* writes its first package.json, so this is a new frontend, and it gets what
|
|
45
|
+
* create gives a new app - Tailwind, and dependencies installed.
|
|
46
|
+
*/
|
|
47
|
+
export declare function initDefaults(found: {
|
|
48
|
+
createdPackageJson: boolean;
|
|
49
|
+
hasTailwind: boolean;
|
|
50
|
+
}): {
|
|
51
|
+
tailwind: boolean;
|
|
52
|
+
install: boolean;
|
|
53
|
+
};
|
|
36
54
|
/**
|
|
37
55
|
* Add RSC to a project that already exists.
|
|
38
56
|
*
|
package/dist/init.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// the exact edit is printed for the reader to make. A tool that silently
|
|
10
10
|
// reformats a working server has to be right about more than it can know.
|
|
11
11
|
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync, renameSync } from 'node:fs';
|
|
12
|
+
import { spawnSync } from 'node:child_process';
|
|
12
13
|
import { randomBytes } from 'node:crypto';
|
|
13
14
|
import { basename, dirname, join } from 'node:path';
|
|
14
15
|
import { argv, cwd, exit, stdout } from 'node:process';
|
|
@@ -659,10 +660,31 @@ const INIT_HELP = `
|
|
|
659
660
|
http://127.0.0.1:8080 (assumed when go.mod is here);
|
|
660
661
|
laravel reads APP_URL instead
|
|
661
662
|
--compiler=… none | oxc | babel
|
|
662
|
-
--tailwind
|
|
663
|
+
--tailwind / --no-tailwind
|
|
664
|
+
Tailwind; yes for a project with no package.json yet
|
|
665
|
+
(a Go service), otherwise only if it is already there
|
|
666
|
+
--no-install don't install; a project with no package.json yet is
|
|
667
|
+
installed by default, any other never is
|
|
663
668
|
-y, --yes accept what was detected, ask nothing
|
|
664
669
|
-h, --help this
|
|
665
670
|
`;
|
|
671
|
+
/**
|
|
672
|
+
* What init assumes when nobody says: whether to offer Tailwind first, and
|
|
673
|
+
* whether to install.
|
|
674
|
+
*
|
|
675
|
+
* An existing JavaScript project has a package manager and a lockfile of its
|
|
676
|
+
* own - `bun install` in an npm project writes a second lockfile - and its own
|
|
677
|
+
* styling, so init installs nothing there and adds Tailwind only where it
|
|
678
|
+
* already is. A project with no package.json (a Go service) has neither: init
|
|
679
|
+
* writes its first package.json, so this is a new frontend, and it gets what
|
|
680
|
+
* create gives a new app - Tailwind, and dependencies installed.
|
|
681
|
+
*/
|
|
682
|
+
export function initDefaults(found) {
|
|
683
|
+
return {
|
|
684
|
+
tailwind: found.hasTailwind || found.createdPackageJson,
|
|
685
|
+
install: found.createdPackageJson,
|
|
686
|
+
};
|
|
687
|
+
}
|
|
666
688
|
/**
|
|
667
689
|
* Add RSC to a project that already exists.
|
|
668
690
|
*
|
|
@@ -712,14 +734,21 @@ export async function runInit(args) {
|
|
|
712
734
|
stdout.write(` ${dim('backend')} ${backendUrl}${flags.backend ? '' : dim(' (go.mod is here)')}\n`);
|
|
713
735
|
}
|
|
714
736
|
stdout.write('\n');
|
|
737
|
+
const defaults = initDefaults(found);
|
|
715
738
|
let compiler = flags.compiler ?? 'none';
|
|
716
|
-
let tailwind = flags.tailwind ??
|
|
739
|
+
let tailwind = flags.tailwind ?? defaults.tailwind;
|
|
740
|
+
// Only ever for a project init gave its first package.json: anywhere else
|
|
741
|
+
// the project's own package manager installs, not this.
|
|
742
|
+
let install = defaults.install && flags.install !== false;
|
|
717
743
|
if (!unattended) {
|
|
718
744
|
const p = new Prompter();
|
|
719
745
|
try {
|
|
720
746
|
compiler = flags.compiler ?? ((await p.confirm('React Compiler', true)) ? DEFAULT_COMPILER : 'none');
|
|
721
747
|
if (flags.tailwind === undefined && !found.hasTailwind) {
|
|
722
|
-
tailwind = await p.confirm('Tailwind CSS',
|
|
748
|
+
tailwind = await p.confirm('Tailwind CSS', defaults.tailwind);
|
|
749
|
+
}
|
|
750
|
+
if (defaults.install && flags.install === undefined) {
|
|
751
|
+
install = await p.confirm('Install dependencies now', true);
|
|
723
752
|
}
|
|
724
753
|
}
|
|
725
754
|
finally {
|
|
@@ -752,10 +781,26 @@ export async function runInit(args) {
|
|
|
752
781
|
stdout.write(` ${mark[step.kind]} ${step.what}${step.detail ? dim(' — ' + step.detail) : ''}\n`);
|
|
753
782
|
}
|
|
754
783
|
const manual = steps.filter((s) => s.kind === 'manual');
|
|
784
|
+
// Before the steps by hand, not instead of them: a Go project always has
|
|
785
|
+
// one - its own server answering host calls - and none of it is about the
|
|
786
|
+
// JavaScript side, which is ready to install either way.
|
|
787
|
+
let installed = false;
|
|
788
|
+
if (install) {
|
|
789
|
+
const pm = options.host === 'node' ? 'npm' : 'bun';
|
|
790
|
+
stdout.write(`\n${dim('Installing dependencies…')}\n`);
|
|
791
|
+
installed = spawnSync(pm, ['install'], { cwd: dir, stdio: 'inherit' }).status === 0;
|
|
792
|
+
if (!installed) {
|
|
793
|
+
stdout.write(`\n${bold('Dependencies did not install.')} The files are written; run the install yourself.\n`);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
755
796
|
if (manual.length > 0) {
|
|
756
797
|
stdout.write(`\n${bold('Then, by hand:')} the steps marked ! above.\n\n`);
|
|
757
798
|
return;
|
|
758
799
|
}
|
|
800
|
+
if (installed) {
|
|
801
|
+
stdout.write(`\n ${cyan(`${options.host === 'node' ? 'npm run' : 'bun run'} dev`)} and you are ready.\n\n`);
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
759
804
|
stdout.write(options.host === 'laravel'
|
|
760
805
|
? `\n ${cyan('npm install')}, then ${cyan('npm run dev')} — and open the app at its own domain.\n\n`
|
|
761
806
|
: `\n ${cyan('bun install')} and you are ready.\n\n`);
|