@fgv/repo-template 5.1.0-2 → 5.1.0-21

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 (42) hide show
  1. package/lib/cli.d.ts.map +1 -1
  2. package/lib/cli.js +44 -3
  3. package/lib/cli.js.map +1 -1
  4. package/lib/commands/create.d.ts.map +1 -1
  5. package/lib/commands/create.js +2 -2
  6. package/lib/commands/create.js.map +1 -1
  7. package/lib/commands/init-library.d.ts +13 -0
  8. package/lib/commands/init-library.d.ts.map +1 -1
  9. package/lib/commands/init-library.js +52 -0
  10. package/lib/commands/init-library.js.map +1 -1
  11. package/lib/commands/link.d.ts +20 -0
  12. package/lib/commands/link.d.ts.map +1 -0
  13. package/lib/commands/link.js +273 -0
  14. package/lib/commands/link.js.map +1 -0
  15. package/lib/index.d.ts +1 -0
  16. package/lib/index.d.ts.map +1 -1
  17. package/lib/index.js +5 -1
  18. package/lib/index.js.map +1 -1
  19. package/package.json +10 -10
  20. package/.rush/temp/45a8d0dcbb9c2e59fa02645657661dffbd25461f.tar.log +0 -57
  21. package/.rush/temp/92e27a75687fa5062b71fdb897f0928a8aa4e0c9.tar.log +0 -57
  22. package/.rush/temp/chunked-rush-logs/repo-template.build.chunks.jsonl +0 -7
  23. package/.rush/temp/operation/build/all.log +0 -7
  24. package/.rush/temp/operation/build/log-chunks.jsonl +0 -7
  25. package/.rush/temp/operation/build/state.json +0 -3
  26. package/.rush/temp/shrinkwrap-deps.json +0 -576
  27. package/config/rig.json +0 -4
  28. package/rush-logs/repo-template.build.cache.log +0 -4
  29. package/rush-logs/repo-template.build.log +0 -7
  30. package/src/cli.ts +0 -141
  31. package/src/commands/create.ts +0 -216
  32. package/src/commands/init-library.ts +0 -249
  33. package/src/commands/patch.ts +0 -84
  34. package/src/commands/sync.ts +0 -137
  35. package/src/index.ts +0 -14
  36. package/src/packlets/fs/index.ts +0 -114
  37. package/src/packlets/jsonc/index.ts +0 -134
  38. package/src/packlets/manifest/index.ts +0 -29
  39. package/src/packlets/manifest/types.ts +0 -36
  40. package/src/packlets/template/index.ts +0 -48
  41. package/temp/build/typescript/ts_l9Fw4VUO.json +0 -1
  42. package/tsconfig.json +0 -7
package/config/rig.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json",
3
- "rigPackageName": "@rushstack/heft-node-rig"
4
- }
@@ -1,4 +0,0 @@
1
- This project was not found in the build cache.
2
- Caching build output folders: lib, temp, .rush/temp/operation/build
3
- Successfully set cache entry.
4
- Cache key: 92e27a75687fa5062b71fdb897f0928a8aa4e0c9
@@ -1,7 +0,0 @@
1
- Invoking: heft build --clean
2
- ---- build started ----
3
- [build:clean] Deleted 0 files and 2 folders
4
- [build:typescript] The TypeScript compiler version 5.9.3 is newer than the latest version that was tested with Heft (5.8); it may not work correctly.
5
- [build:typescript] Using TypeScript version 5.9.3
6
- ---- build finished (0.796s) ----
7
- -------------------- Finished (0.797s) --------------------
package/src/cli.ts DELETED
@@ -1,141 +0,0 @@
1
- /**
2
- * CLI entry point — sets up commander with create, sync, and patch subcommands.
3
- */
4
-
5
- import { Command } from 'commander';
6
- import { detectSourceDir } from './packlets/fs';
7
- import { runCreate } from './commands/create';
8
- import { runSync } from './commands/sync';
9
- import { runPatch, parsePatchArgs } from './commands/patch';
10
- import { runInitLibrary, RigType, CategoryType } from './commands/init-library';
11
-
12
- export class RepoTemplateCli {
13
- private readonly _program: Command;
14
-
15
- public constructor() {
16
- this._program = new Command();
17
- this._setupCommands();
18
- }
19
-
20
- public async run(argv: string[]): Promise<void> {
21
- await this._program.parseAsync(argv);
22
- }
23
-
24
- private _setupCommands(): void {
25
- this._program
26
- .name('repo-template')
27
- .description('Create and maintain fgv-derived Rush monorepos')
28
- .version('5.1.0');
29
-
30
- // ── create ──
31
- this._program
32
- .command('create')
33
- .description('Stamp out a new fgv-derived Rush monorepo using rush init + JSONC patching')
34
- .requiredOption('-t, --target-dir <path>', 'Directory to create the new repo in')
35
- .requiredOption('-u, --repo-url <url>', 'GitHub repository URL')
36
- .option('-p, --version-policy <name>', 'Version policy name', 'default')
37
- .option('--initial-version <ver>', 'Initial version', '0.1.0')
38
- .option('-s, --source-dir <path>', 'Source repo for shared files (auto-detected if in fgv repo)')
39
- .option('--allow-existing', 'Allow target directory to already exist', false)
40
- .option('--no-git-init', 'Skip git init and initial commit')
41
- .action(async (opts) => {
42
- const sourceDir = opts.sourceDir ?? this._resolveSourceDir();
43
- await runCreate({
44
- targetDir: opts.targetDir,
45
- repoUrl: opts.repoUrl,
46
- versionPolicy: opts.versionPolicy,
47
- version: opts.initialVersion,
48
- sourceDir,
49
- allowExisting: opts.allowExisting,
50
- gitInit: opts.gitInit
51
- });
52
- });
53
-
54
- // ── sync ──
55
- this._program
56
- .command('sync')
57
- .description('Sync shared files from the fgv source repo to a consumer repo')
58
- .requiredOption('-t, --target-dir <path>', 'Consumer repo to update')
59
- .option('-s, --source-dir <path>', 'Source repo (auto-detected if in fgv repo)')
60
- .option('-n, --dry-run', 'Show what would change without modifying files', false)
61
- .action(async (opts) => {
62
- const sourceDir = opts.sourceDir ?? this._resolveSourceDir();
63
- await runSync({
64
- targetDir: opts.targetDir,
65
- sourceDir,
66
- dryRun: opts.dryRun
67
- });
68
- });
69
-
70
- // ── init-library ──
71
- this._program
72
- .command('init-library')
73
- .description('Scaffold a new library package within an existing Rush monorepo')
74
- .requiredOption('-n, --name <name>', 'Package name (e.g. "ts-my-lib" — auto-prefixed with @fgv/)')
75
- .option('-d, --description <text>', 'Package description', '')
76
- .option('-r, --rig <type>', 'Heft rig: dual (default), node, or browser', 'dual')
77
- .option(
78
- '-c, --category <type>',
79
- 'Category folder: libraries (default), tools, apps, services',
80
- 'libraries'
81
- )
82
- .option('--repo-dir <path>', 'Rush monorepo root (default: cwd)', process.cwd())
83
- .option('-p, --version-policy <name>', 'Version policy name', 'default')
84
- .option('--initial-version <ver>', 'Initial version', '0.1.0')
85
- .option(
86
- '--fgv-dep-version <ver>',
87
- 'Version spec for @fgv/* deps ("workspace:*" in fgv, version range in consumers)',
88
- 'workspace:*'
89
- )
90
- .action(async (opts) => {
91
- await runInitLibrary({
92
- name: opts.name,
93
- description: opts.description,
94
- rig: opts.rig as RigType,
95
- category: opts.category as CategoryType,
96
- repoDir: opts.repoDir,
97
- versionPolicy: opts.versionPolicy,
98
- version: opts.initialVersion,
99
- fgvDepVersion: opts.fgvDepVersion
100
- });
101
- });
102
-
103
- // ── patch ──
104
- this._program
105
- .command('patch <file>')
106
- .description('Apply targeted edits to a JSONC config file while preserving comments')
107
- .allowUnknownOption(true)
108
- .helpOption(false)
109
- .action(async (file, _opts, cmd) => {
110
- // Parse the raw args after the file argument as patch operations
111
- const rawArgs = cmd.args.slice(1); // skip the file arg
112
- // Actually, commander passes remaining args differently. Let's get them from process.argv
113
- const allArgs = process.argv;
114
- const patchIdx = allArgs.indexOf('patch');
115
- const fileIdx = patchIdx + 1;
116
- const opArgs = allArgs.slice(fileIdx + 1);
117
-
118
- const operations = parsePatchArgs(opArgs);
119
- if (operations.length === 0) {
120
- console.error('No operations specified. Use --set, --uncomment, --add-to-array, etc.');
121
- process.exit(1);
122
- }
123
- await runPatch({ file, operations });
124
- });
125
- }
126
-
127
- /**
128
- * Auto-detect the fgv source directory by walking up from the current working directory.
129
- */
130
- private _resolveSourceDir(): string {
131
- const detected = detectSourceDir(process.cwd());
132
- if (!detected) {
133
- console.error(
134
- 'ERROR: Could not auto-detect fgv source repo. ' +
135
- 'Please specify --source-dir or run from within the fgv repository.'
136
- );
137
- process.exit(1);
138
- }
139
- return detected;
140
- }
141
- }
@@ -1,216 +0,0 @@
1
- /**
2
- * Create command — stamps out a new fgv-derived Rush monorepo.
3
- *
4
- * Uses `rush init` to generate base config with full documentation,
5
- * then applies fgv-specific customizations via JSONC patching and shared file sync.
6
- */
7
-
8
- import * as fs from 'fs';
9
- import * as path from 'path';
10
- import { loadManifest, getDefaultManifestPath } from '../packlets/manifest';
11
- import { patchFile, IPatchOperation } from '../packlets/jsonc';
12
- import { renderTemplateFile, getDefaultTemplatesDir, ITemplateVars } from '../packlets/template';
13
- import { copyFile, copyPackage, exec, getGitCommit, getGitRemoteUrl } from '../packlets/fs';
14
-
15
- export interface ICreateOptions {
16
- targetDir: string;
17
- repoUrl: string;
18
- versionPolicy: string;
19
- version: string;
20
- sourceDir: string;
21
- allowExisting: boolean;
22
- gitInit: boolean;
23
- }
24
-
25
- const RUSH_VERSION = '5.172.1';
26
-
27
- const NODE_VERSION_RANGE =
28
- '>=14.15.0 <15.0.0 || >=16.13.0 <17.0.0 || >=18.15.0 <19.0.0 || >=20.18.0 <21.0.0 || >=22.22.0 <23.0.0';
29
-
30
- export async function runCreate(options: ICreateOptions): Promise<void> {
31
- const { targetDir, repoUrl, versionPolicy, version, sourceDir, allowExisting, gitInit } = options;
32
-
33
- // Validate
34
- if (!allowExisting && fs.existsSync(targetDir)) {
35
- throw new Error(`Target directory already exists: ${targetDir} (use --allow-existing to override)`);
36
- }
37
- if (!fs.existsSync(path.join(sourceDir, 'rush.json'))) {
38
- throw new Error(`Source directory is not a Rush repo: ${sourceDir}`);
39
- }
40
-
41
- const manifestPath = getDefaultManifestPath();
42
- const templatesDir = getDefaultTemplatesDir();
43
- const manifest = loadManifest(manifestPath);
44
-
45
- console.log(`Creating new monorepo at: ${targetDir}`);
46
- console.log(` Source repo: ${sourceDir}`);
47
- console.log(` Repo URL: ${repoUrl}`);
48
- console.log(` Version: ${versionPolicy}@${version}`);
49
- console.log('');
50
-
51
- fs.mkdirSync(targetDir, { recursive: true });
52
-
53
- // ── Step 1: rush init ──
54
- if (fs.existsSync(path.join(targetDir, 'rush.json'))) {
55
- console.log('==> Target already has rush.json, skipping rush init');
56
- } else {
57
- console.log('==> Running rush init...');
58
- try {
59
- const output = exec(`npx "@microsoft/rush@${RUSH_VERSION}" init`, { cwd: targetDir });
60
- for (const line of output.split('\n')) {
61
- console.log(` ${line}`);
62
- }
63
- } catch (err: unknown) {
64
- // rush init writes to stderr for some messages, check if rush.json was created
65
- if (!fs.existsSync(path.join(targetDir, 'rush.json'))) {
66
- throw new Error(`rush init failed: ${(err as Error).message}`);
67
- }
68
- }
69
- }
70
-
71
- // ── Step 2: Patch rush.json ──
72
- console.log('');
73
- console.log('==> Patching rush.json with fgv customizations...');
74
-
75
- const rushJsonOps: IPatchOperation[] = [
76
- { type: 'set', path: 'nodeSupportedVersionRange', value: NODE_VERSION_RANGE },
77
- { type: 'set', path: 'ensureConsistentVersions', value: true },
78
- { type: 'uncomment', path: 'projectFolderMinDepth' },
79
- { type: 'set', path: 'projectFolderMinDepth', value: 2 },
80
- { type: 'uncomment', path: 'projectFolderMaxDepth' },
81
- { type: 'set', path: 'projectFolderMaxDepth', value: 2 },
82
- { type: 'uncomment', path: 'url' },
83
- { type: 'set', path: 'repository.url', value: repoUrl },
84
- { type: 'uncomment', path: 'defaultBranch' },
85
- { type: 'uncomment', path: 'defaultRemote' }
86
- ];
87
-
88
- patchFile(path.join(targetDir, 'rush.json'), rushJsonOps);
89
- for (const op of rushJsonOps) {
90
- const desc =
91
- op.type === 'uncomment' || op.type === 'remove'
92
- ? ` ${op.type}: ${op.path}`
93
- : ` ${op.type}: ${op.path}`;
94
- console.log(desc);
95
- }
96
-
97
- // ── Step 3: Patch other rush config files ──
98
- console.log('');
99
- console.log('==> Patching rush config files...');
100
-
101
- patchFile(path.join(targetDir, 'common/config/rush/build-cache.json'), [
102
- { type: 'set', path: 'buildCacheEnabled', value: true }
103
- ]);
104
- console.log(' build-cache.json: buildCacheEnabled = true');
105
-
106
- patchFile(path.join(targetDir, 'common/config/rush/pnpm-config.json'), [
107
- { type: 'uncomment', path: 'strictPeerDependencies' },
108
- { type: 'set', path: 'strictPeerDependencies', value: true }
109
- ]);
110
- console.log(' pnpm-config.json: strictPeerDependencies = true');
111
-
112
- // ── Step 4: Generate templated files ──
113
- console.log('');
114
- console.log('==> Generating templated config files...');
115
-
116
- const templateVars: ITemplateVars = {
117
- REPO_URL: repoUrl,
118
- VERSION_POLICY_NAME: versionPolicy,
119
- VERSION: version
120
- };
121
-
122
- for (const tmpl of manifest.templated.files) {
123
- const templatePath = path.join(sourceDir, tmpl.template);
124
- const destPath = path.join(targetDir, tmpl.destination);
125
- renderTemplateFile(templatePath, destPath, templateVars);
126
- }
127
-
128
- // ── Step 5: Copy shared files ──
129
- console.log('');
130
- console.log('==> Copying shared files...');
131
-
132
- for (const file of manifest.shared.files) {
133
- const srcPath = path.join(sourceDir, file.source);
134
- const destPath = path.join(targetDir, file.destination);
135
- if (!fs.existsSync(srcPath)) {
136
- console.warn(` WARNING: Source file not found, skipping: ${file.source}`);
137
- continue;
138
- }
139
- copyFile(srcPath, destPath);
140
- console.log(` Copied: ${file.destination}`);
141
- }
142
-
143
- for (const pkg of manifest.sharedPackages.packages) {
144
- const srcPath = path.join(sourceDir, pkg.source);
145
- const destPath = path.join(targetDir, pkg.destination);
146
- if (!fs.existsSync(srcPath)) {
147
- console.warn(` WARNING: Source directory not found, skipping: ${pkg.source}`);
148
- continue;
149
- }
150
- copyPackage(srcPath, destPath);
151
- console.log(` Copied package: ${pkg.destination}`);
152
- }
153
-
154
- // ── Step 6: Create standard directories ──
155
- console.log('');
156
- console.log('==> Creating directory structure...');
157
-
158
- const dirs = ['libraries', 'tools', 'apps', 'services', '.claude/project', '.claude/skills'];
159
- for (const dir of dirs) {
160
- fs.mkdirSync(path.join(targetDir, dir), { recursive: true });
161
- }
162
-
163
- const gitkeeps = ['.claude/project/.gitkeep', '.claude/skills/.gitkeep'];
164
- for (const gk of gitkeeps) {
165
- fs.writeFileSync(path.join(targetDir, gk), '');
166
- }
167
- console.log(' Created standard directory structure');
168
-
169
- // ── Step 7: Record template metadata ──
170
- console.log('');
171
- console.log('==> Recording template metadata...');
172
-
173
- const sourceCommit = getGitCommit(sourceDir);
174
- const sourceRepo = getGitRemoteUrl(sourceDir);
175
-
176
- const syncMetadata = {
177
- templateSource: repoUrl,
178
- sourceRepo,
179
- sourceCommit,
180
- createdAt: new Date().toISOString(),
181
- lastSyncedAt: new Date().toISOString(),
182
- manifestVersion: '1.0.0'
183
- };
184
- fs.writeFileSync(path.join(targetDir, '.template-sync'), JSON.stringify(syncMetadata, null, 2) + '\n');
185
- console.log(' Created .template-sync');
186
-
187
- // ── Step 8: Git init ──
188
- if (gitInit) {
189
- console.log('');
190
- console.log('==> Initializing git repository...');
191
- try {
192
- exec('git init -b main', { cwd: targetDir });
193
- exec('git add -A', { cwd: targetDir });
194
- exec(
195
- `git commit -m "Initial commit from fgv monorepo template\n\nSource: ${sourceDir}\nTemplate commit: ${sourceCommit}"`,
196
- { cwd: targetDir }
197
- );
198
- console.log(' Git repository initialized with initial commit');
199
- } catch (err: unknown) {
200
- console.warn(` WARNING: Git init failed: ${(err as Error).message}`);
201
- }
202
- }
203
-
204
- // ── Done ──
205
- console.log('');
206
- console.log(`=== Monorepo created successfully at: ${targetDir} ===`);
207
- console.log('');
208
- console.log('Next steps:');
209
- console.log(' 1. Add your domain packages to libraries/, apps/, tools/, services/');
210
- console.log(' 2. Register them in rush.json');
211
- console.log(' 3. Fill in the project table in CLAUDE.md');
212
- console.log(' 4. Fill in ACTIVE_DEVELOPMENT.md with your domain projects');
213
- console.log(' 5. Add domain-specific Rush commands to common/config/rush/command-line.json');
214
- console.log(` 6. Run: cd ${targetDir} && rush install && rush build`);
215
- console.log('');
216
- }
@@ -1,249 +0,0 @@
1
- /**
2
- * init-library command — scaffolds a new library package within an existing Rush monorepo.
3
- */
4
-
5
- import * as fs from 'fs';
6
- import * as path from 'path';
7
- import { patchFile, IPatchOperation } from '../packlets/jsonc';
8
-
9
- export type RigType = 'dual' | 'node' | 'browser';
10
- export type CategoryType = 'libraries' | 'tools' | 'apps' | 'services';
11
-
12
- export interface IInitLibraryOptions {
13
- /** Package name (e.g. "ts-my-lib" — will be prefixed with @fgv/) */
14
- name: string;
15
- /** Short description */
16
- description: string;
17
- /** Heft rig to use */
18
- rig: RigType;
19
- /** Category folder */
20
- category: CategoryType;
21
- /** Rush monorepo root */
22
- repoDir: string;
23
- /** Version policy name (from version-policies.json) */
24
- versionPolicy: string;
25
- /** Initial version */
26
- version: string;
27
- /** Dependency version for @fgv/* packages ("workspace:*" for fgv, "^5.1.0-0" for consumers) */
28
- fgvDepVersion: string;
29
- }
30
-
31
- interface IRigConfig {
32
- rigPackageName: string;
33
- rigProfile?: string;
34
- rigDevDeps: Record<string, string>;
35
- tsconfigExtends: string;
36
- tsconfigTypes: string[];
37
- tsconfigLib?: string[];
38
- }
39
-
40
- const RIG_CONFIGS: Record<RigType, IRigConfig> = {
41
- dual: {
42
- rigPackageName: '@fgv/heft-dual-rig',
43
- rigDevDeps: {
44
- '@fgv/heft-dual-rig': 'FGV_DEP',
45
- '@rushstack/heft': '1.2.7',
46
- '@rushstack/heft-node-rig': '2.11.27'
47
- },
48
- tsconfigExtends: './node_modules/@rushstack/heft-node-rig/profiles/default/tsconfig-base.json',
49
- tsconfigTypes: ['heft-jest', 'node'],
50
- tsconfigLib: ['es2018']
51
- },
52
- node: {
53
- rigPackageName: '@rushstack/heft-node-rig',
54
- rigDevDeps: {
55
- '@rushstack/heft': '1.2.7',
56
- '@rushstack/heft-node-rig': '2.11.27'
57
- },
58
- tsconfigExtends: './node_modules/@rushstack/heft-node-rig/profiles/default/tsconfig-base.json',
59
- tsconfigTypes: ['heft-jest', 'node']
60
- },
61
- browser: {
62
- rigPackageName: '@rushstack/heft-web-rig',
63
- rigProfile: 'library',
64
- rigDevDeps: {
65
- '@rushstack/heft': '1.2.7',
66
- '@rushstack/heft-web-rig': '1.4.3'
67
- },
68
- tsconfigExtends: './node_modules/@rushstack/heft-web-rig/profiles/library/tsconfig-base.json',
69
- tsconfigTypes: ['heft-jest', 'node'],
70
- tsconfigLib: ['es2018', 'DOM']
71
- }
72
- };
73
-
74
- export async function runInitLibrary(options: IInitLibraryOptions): Promise<void> {
75
- const { name, description, rig, category, repoDir, versionPolicy, version, fgvDepVersion } = options;
76
-
77
- const packageName = name.startsWith('@fgv/') ? name : `@fgv/${name}`;
78
- const shortName = packageName.replace('@fgv/', '');
79
- const projectFolder = `${category}/${shortName}`;
80
- const projectDir = path.join(repoDir, projectFolder);
81
-
82
- if (fs.existsSync(projectDir)) {
83
- throw new Error(`Project directory already exists: ${projectDir}`);
84
- }
85
-
86
- const rushJsonPath = path.join(repoDir, 'rush.json');
87
- if (!fs.existsSync(rushJsonPath)) {
88
- throw new Error(`Not a Rush repo (no rush.json): ${repoDir}`);
89
- }
90
-
91
- const rigConfig = RIG_CONFIGS[rig];
92
-
93
- console.log(`Initializing library: ${packageName}`);
94
- console.log(` Directory: ${projectFolder}`);
95
- console.log(` Rig: ${rig} (${rigConfig.rigPackageName})`);
96
- console.log(` Version: ${versionPolicy}@${version}`);
97
- console.log('');
98
-
99
- // ── Create directory structure ──
100
- fs.mkdirSync(path.join(projectDir, 'src', 'test', 'unit'), { recursive: true });
101
- fs.mkdirSync(path.join(projectDir, 'config'), { recursive: true });
102
-
103
- // ── package.json ──
104
- console.log('==> Creating package.json...');
105
-
106
- const devDependencies: Record<string, string> = {};
107
- // Add rig dependencies — @fgv/* packages use fgvDepVersion, others use their pinned version
108
- for (const [dep, ver] of Object.entries(rigConfig.rigDevDeps)) {
109
- devDependencies[dep] = dep.startsWith('@fgv/') ? fgvDepVersion : ver;
110
- }
111
- // Standard dev dependencies
112
- devDependencies['@fgv/ts-utils-jest'] = fgvDepVersion;
113
- devDependencies['@types/heft-jest'] = '1.0.6';
114
- devDependencies['@types/jest'] = '^29.5.14';
115
- devDependencies['@types/node'] = '^20.14.9';
116
- devDependencies['typescript'] = '5.9.3';
117
- devDependencies['@rushstack/eslint-config'] = '4.6.4';
118
- devDependencies['eslint'] = '^9.39.2';
119
-
120
- const packageJson: Record<string, unknown> = {
121
- name: packageName,
122
- version,
123
- description,
124
- main: 'lib/index.js',
125
- types: 'lib/index.d.ts',
126
- scripts: {
127
- build: 'heft build --clean',
128
- clean: 'heft clean',
129
- test: 'heft test --clean',
130
- coverage: 'jest --coverage',
131
- lint: 'eslint src --ext .ts',
132
- fixlint: 'eslint src --ext .ts --fix'
133
- },
134
- author: '',
135
- license: 'MIT',
136
- dependencies: {
137
- '@fgv/ts-utils': fgvDepVersion,
138
- '@fgv/ts-json-base': fgvDepVersion
139
- },
140
- devDependencies,
141
- repository: {
142
- type: 'git',
143
- url: ''
144
- }
145
- };
146
-
147
- // Add dual-emit exports for dual rig
148
- if (rig === 'dual') {
149
- packageJson['module'] = 'dist/index.js';
150
- packageJson['exports'] = {
151
- '.': {
152
- types: './lib/index.d.ts',
153
- import: './dist/index.js',
154
- require: './lib/index.js',
155
- default: './lib/index.js'
156
- }
157
- };
158
- }
159
-
160
- fs.writeFileSync(path.join(projectDir, 'package.json'), JSON.stringify(packageJson, null, 2) + '\n');
161
-
162
- // ── tsconfig.json ──
163
- console.log(' Creating tsconfig.json...');
164
-
165
- const tsconfig: Record<string, unknown> = {
166
- extends: rigConfig.tsconfigExtends,
167
- compilerOptions: {
168
- types: rigConfig.tsconfigTypes,
169
- ...(rigConfig.tsconfigLib ? { lib: rigConfig.tsconfigLib } : {})
170
- }
171
- };
172
-
173
- fs.writeFileSync(path.join(projectDir, 'tsconfig.json'), JSON.stringify(tsconfig, null, 2) + '\n');
174
-
175
- // ── config/rig.json ──
176
- console.log(' Creating config/rig.json...');
177
-
178
- const rigJson: Record<string, unknown> = {
179
- $schema: 'https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json',
180
- rigPackageName: rigConfig.rigPackageName
181
- };
182
- if (rigConfig.rigProfile) {
183
- rigJson['rigProfile'] = rigConfig.rigProfile;
184
- }
185
-
186
- fs.writeFileSync(path.join(projectDir, 'config', 'rig.json'), JSON.stringify(rigJson, null, 2) + '\n');
187
-
188
- // ── config/jest.config.json ──
189
- console.log(' Creating config/jest.config.json...');
190
-
191
- const jestConfig = {
192
- extends: '@rushstack/heft-node-rig/profiles/default/config/jest.config.json',
193
- coverageThreshold: {
194
- global: {
195
- branches: 100,
196
- functions: 100,
197
- lines: 100,
198
- statements: 100
199
- }
200
- },
201
- collectCoverage: true,
202
- coverageReporters: ['text', 'lcov', 'html']
203
- };
204
-
205
- fs.writeFileSync(
206
- path.join(projectDir, 'config', 'jest.config.json'),
207
- JSON.stringify(jestConfig, null, 2) + '\n'
208
- );
209
-
210
- // ── src/index.ts ──
211
- console.log(' Creating src/index.ts...');
212
-
213
- fs.writeFileSync(
214
- path.join(projectDir, 'src', 'index.ts'),
215
- `/**\n * @packageDocumentation\n * ${description}\n */\n`
216
- );
217
-
218
- // ── Register in rush.json ──
219
- console.log('');
220
- console.log('==> Registering in rush.json...');
221
-
222
- const rushJsonOps: IPatchOperation[] = [
223
- {
224
- type: 'add-to-array',
225
- path: 'projects',
226
- value: JSON.stringify({
227
- packageName,
228
- projectFolder,
229
- shouldPublish: true,
230
- versionPolicyName: versionPolicy,
231
- tags: [category]
232
- })
233
- }
234
- ];
235
-
236
- patchFile(rushJsonPath, rushJsonOps);
237
- console.log(` Added ${packageName} at ${projectFolder}`);
238
-
239
- // ── Done ──
240
- console.log('');
241
- console.log(`=== Library ${packageName} initialized at ${projectFolder} ===`);
242
- console.log('');
243
- console.log('Next steps:');
244
- console.log(` 1. cd ${projectDir}`);
245
- console.log(' 2. rush update');
246
- console.log(' 3. rushx build');
247
- console.log(' 4. Start adding code to src/');
248
- console.log('');
249
- }