create-nx-workspace 22.4.2 โ†’ 22.4.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-nx-workspace",
3
- "version": "22.4.2",
3
+ "version": "22.4.3",
4
4
  "private": false,
5
5
  "description": "Smart Repos ยท Fast Builds",
6
6
  "repository": {
@@ -1 +1 @@
1
- {"version":3,"file":"create-workspace.d.ts","sourceRoot":"","sources":["../../../../packages/create-nx-workspace/src/create-workspace.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,iBAAiB,CAAC;AAsBzB,wBAAgB,4BAA4B,IAAI;IAC9C,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAEA;AAED,wBAAsB,eAAe,CAAC,CAAC,SAAS,sBAAsB,EACpE,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,CAAC,EACV,OAAO,CAAC,EAAE,CAAC;;;;;GA0LZ;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI7D"}
1
+ {"version":3,"file":"create-workspace.d.ts","sourceRoot":"","sources":["../../../../packages/create-nx-workspace/src/create-workspace.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,iBAAiB,CAAC;AA0BzB,wBAAgB,4BAA4B,IAAI;IAC9C,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAEA;AAED,wBAAsB,eAAe,CAAC,CAAC,SAAS,sBAAsB,EACpE,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,CAAC,EACV,OAAO,CAAC,EAAE,CAAC;;;;;GA6MZ;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI7D"}
@@ -16,6 +16,7 @@ const output_1 = require("./utils/output");
16
16
  const get_third_party_preset_1 = require("./utils/preset/get-third-party-preset");
17
17
  const preset_1 = require("./utils/preset/preset");
18
18
  const clone_template_1 = require("./utils/template/clone-template");
19
+ const update_readme_1 = require("./utils/template/update-readme");
19
20
  const child_process_utils_1 = require("./utils/child-process-utils");
20
21
  const package_manager_1 = require("./utils/package-manager");
21
22
  // State for SIGINT handler - only set after workspace is fully installed
@@ -140,9 +141,25 @@ async function createWorkspace(preset, options, rawArgs) {
140
141
  connectUrl = await (0, nx_cloud_1.createNxCloudOnboardingUrl)(nxCloud, token, directory, useGitHub);
141
142
  // Store for SIGINT handler
142
143
  cloudConnectUrl = connectUrl;
144
+ // Update README with connect URL (strips markers, adds connect section)
145
+ // Then commit the change - amend if not pushed, new commit if already pushed
146
+ if (isTemplate) {
147
+ const readmeUpdated = (0, update_readme_1.addConnectUrlToReadme)(directory, connectUrl);
148
+ if (readmeUpdated && !skipGit && commit) {
149
+ const alreadyPushed = pushedToVcs === git_1.VcsPushStatus.PushedToVcs;
150
+ await (0, update_readme_1.amendOrCommitReadme)(directory, alreadyPushed);
151
+ }
152
+ }
143
153
  nxCloudInfo = await (0, nx_cloud_1.getNxCloudInfo)(connectUrl, pushedToVcs, options.completionMessageKey, name);
144
154
  }
145
155
  else if (isTemplate && nxCloud === 'skip') {
156
+ // Strip marker comments from README even when cloud is skipped
157
+ // so users don't see raw <!-- BEGIN/END: nx-cloud --> markers
158
+ const readmeUpdated = (0, update_readme_1.addConnectUrlToReadme)(directory, undefined);
159
+ if (readmeUpdated && !skipGit && commit) {
160
+ const alreadyPushed = pushedToVcs === git_1.VcsPushStatus.PushedToVcs;
161
+ await (0, update_readme_1.amendOrCommitReadme)(directory, alreadyPushed);
162
+ }
146
163
  // Show nx connect message when user skips cloud in template flow
147
164
  nxCloudInfo = (0, nx_cloud_1.getSkippedNxCloudInfo)();
148
165
  }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Updates README content by processing the nx-cloud marker section.
3
+ * - If connectUrl is provided: replaces markers and content with the connect URL section
4
+ * - If connectUrl is undefined: removes markers and their content entirely
5
+ *
6
+ * This ensures users never see the raw <!-- BEGIN/END: nx-cloud --> markers in their README.
7
+ *
8
+ * @param readmeContent - The current README content
9
+ * @param connectUrl - The Nx Cloud connect URL (optional)
10
+ * @returns The updated README content with markers processed, or original if markers not found
11
+ */
12
+ export declare function updateReadmeContent(readmeContent: string, connectUrl: string | undefined): string;
13
+ /**
14
+ * Updates the README.md file in the given directory with the Nx Cloud connect URL.
15
+ * This is a convenience wrapper around updateReadmeContent that handles file I/O.
16
+ *
17
+ * @param directory - The workspace directory containing README.md
18
+ * @param connectUrl - The Nx Cloud connect URL
19
+ * @returns true if the file was modified, false otherwise
20
+ */
21
+ export declare function addConnectUrlToReadme(directory: string, connectUrl: string | undefined): boolean;
22
+ /**
23
+ * Commits README.md changes, either by amending the initial commit or creating a new one.
24
+ * - If already pushed to VCS: creates a new commit (to avoid requiring force push)
25
+ * - If not pushed: amends the initial commit (cleaner history)
26
+ *
27
+ * @param directory - The workspace directory
28
+ * @param alreadyPushed - Whether the repo was already pushed to VCS
29
+ */
30
+ export declare function amendOrCommitReadme(directory: string, alreadyPushed: boolean): Promise<void>;
31
+ //# sourceMappingURL=update-readme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-readme.d.ts","sourceRoot":"","sources":["../../../../../../packages/create-nx-workspace/src/utils/template/update-readme.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,GAAG,SAAS,GAC7B,MAAM,CAuCR;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GAAG,SAAS,GAC7B,OAAO,CAeT;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,OAAO,GACrB,OAAO,CAAC,IAAI,CAAC,CAWf"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateReadmeContent = updateReadmeContent;
4
+ exports.addConnectUrlToReadme = addConnectUrlToReadme;
5
+ exports.amendOrCommitReadme = amendOrCommitReadme;
6
+ const node_fs_1 = require("node:fs");
7
+ const path_1 = require("path");
8
+ const child_process_utils_1 = require("../child-process-utils");
9
+ const BEGIN_MARKER = '<!-- BEGIN: nx-cloud -->';
10
+ const END_MARKER = '<!-- END: nx-cloud -->';
11
+ const CLOUD_SETUP_SECTION = `## Finish your Nx platform setup
12
+
13
+ ๐Ÿš€ [Finish setting up your workspace]({{CONNECT_URL}}) to get faster builds with remote caching, distributed task execution, and self-healing CI. [Learn more about Nx Cloud](https://nx.dev/ci/intro/why-nx-cloud).
14
+ `;
15
+ /**
16
+ * Updates README content by processing the nx-cloud marker section.
17
+ * - If connectUrl is provided: replaces markers and content with the connect URL section
18
+ * - If connectUrl is undefined: removes markers and their content entirely
19
+ *
20
+ * This ensures users never see the raw <!-- BEGIN/END: nx-cloud --> markers in their README.
21
+ *
22
+ * @param readmeContent - The current README content
23
+ * @param connectUrl - The Nx Cloud connect URL (optional)
24
+ * @returns The updated README content with markers processed, or original if markers not found
25
+ */
26
+ function updateReadmeContent(readmeContent, connectUrl) {
27
+ const beginIndex = readmeContent.indexOf(BEGIN_MARKER);
28
+ const endIndex = readmeContent.indexOf(END_MARKER);
29
+ if (beginIndex === -1 || endIndex === -1 || beginIndex >= endIndex) {
30
+ return readmeContent;
31
+ }
32
+ // If no connect URL, remove the markers and placeholder content entirely
33
+ if (!connectUrl) {
34
+ // Remove the marker section and surrounding newlines to avoid extra blank lines
35
+ // Skip one newline before BEGIN marker (if present)
36
+ const beforeBegin = beginIndex > 0 && readmeContent[beginIndex - 1] === '\n'
37
+ ? beginIndex - 1
38
+ : beginIndex;
39
+ // Skip one newline after END marker (if present)
40
+ const afterEnd = endIndex + END_MARKER.length;
41
+ const skipTrailing = readmeContent[afterEnd] === '\n' ? afterEnd + 1 : afterEnd;
42
+ return (readmeContent.slice(0, beforeBegin) + readmeContent.slice(skipTrailing));
43
+ }
44
+ const section = CLOUD_SETUP_SECTION.replace('{{CONNECT_URL}}', connectUrl);
45
+ // Strip the markers - only include the section content
46
+ // Also skip one trailing newline after END marker since section already has one
47
+ const afterEnd = endIndex + END_MARKER.length;
48
+ const skipNewline = readmeContent[afterEnd] === '\n' ? afterEnd + 1 : afterEnd;
49
+ return (readmeContent.slice(0, beginIndex) +
50
+ section +
51
+ readmeContent.slice(skipNewline));
52
+ }
53
+ /**
54
+ * Updates the README.md file in the given directory with the Nx Cloud connect URL.
55
+ * This is a convenience wrapper around updateReadmeContent that handles file I/O.
56
+ *
57
+ * @param directory - The workspace directory containing README.md
58
+ * @param connectUrl - The Nx Cloud connect URL
59
+ * @returns true if the file was modified, false otherwise
60
+ */
61
+ function addConnectUrlToReadme(directory, connectUrl) {
62
+ const readmePath = (0, path_1.join)(directory, 'README.md');
63
+ if (!(0, node_fs_1.existsSync)(readmePath)) {
64
+ return false;
65
+ }
66
+ const content = (0, node_fs_1.readFileSync)(readmePath, 'utf-8');
67
+ const updated = updateReadmeContent(content, connectUrl);
68
+ if (updated !== content) {
69
+ (0, node_fs_1.writeFileSync)(readmePath, updated);
70
+ return true;
71
+ }
72
+ return false;
73
+ }
74
+ /**
75
+ * Commits README.md changes, either by amending the initial commit or creating a new one.
76
+ * - If already pushed to VCS: creates a new commit (to avoid requiring force push)
77
+ * - If not pushed: amends the initial commit (cleaner history)
78
+ *
79
+ * @param directory - The workspace directory
80
+ * @param alreadyPushed - Whether the repo was already pushed to VCS
81
+ */
82
+ async function amendOrCommitReadme(directory, alreadyPushed) {
83
+ await (0, child_process_utils_1.execAndWait)('git add README.md', directory);
84
+ if (alreadyPushed) {
85
+ await (0, child_process_utils_1.execAndWait)('git commit -m "chore: add Nx Cloud setup link to README"', directory);
86
+ await (0, child_process_utils_1.execAndWait)('git push', directory);
87
+ }
88
+ else {
89
+ await (0, child_process_utils_1.execAndWait)('git commit --amend --no-edit', directory);
90
+ }
91
+ }