@aws/create-nx-workspace 0.119.0 → 0.121.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/bin/index.cjs +42 -11
- package/package.json +1 -1
package/bin/index.cjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
let child_process = require("child_process");
|
|
3
|
+
let fs = require("fs");
|
|
4
|
+
let path = require("path");
|
|
3
5
|
//#endregion
|
|
4
6
|
//#region src/create-nx-workspace.ts
|
|
5
7
|
/**
|
|
@@ -127,7 +129,7 @@ const NX_VERSION = {
|
|
|
127
129
|
zod: "4.4.3",
|
|
128
130
|
ws: "8.21.0"
|
|
129
131
|
}["create-nx-workspace"];
|
|
130
|
-
const PRESET =
|
|
132
|
+
const PRESET = `@aws/nx-plugin@${JSON.parse((0, fs.readFileSync)((0, path.resolve)(__dirname, "..", "package.json"), "utf-8")).version}`;
|
|
131
133
|
const DEFAULT_FLAGS = ["--ci=skip", "--analytics=false"];
|
|
132
134
|
/**
|
|
133
135
|
* Detect the package manager from the npm_config_user_agent environment variable.
|
|
@@ -141,37 +143,60 @@ const detectPackageManager = () => {
|
|
|
141
143
|
if (userAgent.startsWith("bun/")) return "bun";
|
|
142
144
|
if (userAgent.startsWith("npm/")) return "npm";
|
|
143
145
|
};
|
|
144
|
-
const
|
|
145
|
-
const hasSkipGitFlag = (flagArgs) => flagArgs.some((a) => a === "--skipGit" || a.startsWith("--skipGit="));
|
|
146
|
-
const hasCiOverride = (flagArgs) => flagArgs.some((a) => a.startsWith("--ci") || a.startsWith("--nxCloud"));
|
|
146
|
+
const shouldSkipGit = (flagArgs) => flagArgs.some((a) => a === "--skipGit" || a === "--skipGit=true");
|
|
147
147
|
const buildArgs = (args) => {
|
|
148
148
|
const positionalArgs = args.filter((a) => !a.startsWith("-"));
|
|
149
149
|
const flagArgs = args.filter((a) => a.startsWith("-"));
|
|
150
|
-
const defaultFlags = [...DEFAULT_FLAGS];
|
|
150
|
+
const defaultFlags = [...DEFAULT_FLAGS, "--skipGit"];
|
|
151
151
|
if (!flagArgs.some((a) => a.startsWith("--pm"))) {
|
|
152
152
|
const pm = detectPackageManager();
|
|
153
153
|
if (pm) defaultFlags.push(`--pm=${pm}`);
|
|
154
154
|
}
|
|
155
|
-
|
|
156
|
-
const flagsToAdd = defaultFlags.filter((flag) => !
|
|
155
|
+
const userFlagsWithoutSkipGit = flagArgs.filter((a) => !a.startsWith("--skipGit"));
|
|
156
|
+
const flagsToAdd = defaultFlags.filter((flag) => !userFlagsWithoutSkipGit.some((a) => a.startsWith(flag.split("=")[0])));
|
|
157
157
|
return [
|
|
158
158
|
...positionalArgs,
|
|
159
159
|
`--preset=${PRESET}`,
|
|
160
160
|
...flagsToAdd,
|
|
161
|
-
...
|
|
161
|
+
...userFlagsWithoutSkipGit
|
|
162
162
|
];
|
|
163
163
|
};
|
|
164
|
+
const initGitRepo = (dir) => {
|
|
165
|
+
const shell = process.platform === "win32";
|
|
166
|
+
(0, child_process.spawnSync)("git", ["init"], {
|
|
167
|
+
cwd: dir,
|
|
168
|
+
stdio: "pipe"
|
|
169
|
+
});
|
|
170
|
+
(0, child_process.spawnSync)(detectPackageManager() ?? "npm", ["run", "prepare"], {
|
|
171
|
+
cwd: dir,
|
|
172
|
+
stdio: "pipe",
|
|
173
|
+
shell
|
|
174
|
+
});
|
|
175
|
+
(0, child_process.spawnSync)("git", ["add", "."], {
|
|
176
|
+
cwd: dir,
|
|
177
|
+
stdio: "pipe"
|
|
178
|
+
});
|
|
179
|
+
(0, child_process.spawnSync)("git", [
|
|
180
|
+
"commit",
|
|
181
|
+
"-m",
|
|
182
|
+
"Initial commit"
|
|
183
|
+
], {
|
|
184
|
+
cwd: dir,
|
|
185
|
+
stdio: "pipe"
|
|
186
|
+
});
|
|
187
|
+
};
|
|
164
188
|
/**
|
|
165
189
|
* Create a new Nx workspace with the @aws/nx-plugin preset.
|
|
166
190
|
* All arguments are forwarded to create-nx-workspace.
|
|
167
191
|
*/
|
|
168
192
|
const createNxWorkspace = (args) => {
|
|
169
193
|
if (args.some((a) => a.startsWith("--preset"))) {
|
|
170
|
-
console.error(
|
|
194
|
+
console.error("Error: --preset cannot be used with @aws/create-nx-workspace.\nThis package always creates a workspace with the @aws/nx-plugin preset.\nTo use a different preset, run create-nx-workspace directly:\n\n npx create-nx-workspace <name> --preset=<your-preset>\n");
|
|
171
195
|
return 1;
|
|
172
196
|
}
|
|
197
|
+
const skipGit = shouldSkipGit(args.filter((a) => a.startsWith("-")));
|
|
173
198
|
const allArgs = buildArgs(args);
|
|
174
|
-
|
|
199
|
+
const result = (0, child_process.spawnSync)("npx", [
|
|
175
200
|
"-y",
|
|
176
201
|
`create-nx-workspace@${NX_VERSION}`,
|
|
177
202
|
...allArgs
|
|
@@ -182,7 +207,13 @@ const createNxWorkspace = (args) => {
|
|
|
182
207
|
pnpm_config_strict_dep_builds: "false"
|
|
183
208
|
},
|
|
184
209
|
shell: process.platform === "win32"
|
|
185
|
-
})
|
|
210
|
+
});
|
|
211
|
+
if (result.status !== 0) return result.status ?? 1;
|
|
212
|
+
if (!skipGit) {
|
|
213
|
+
const workspaceName = args.filter((a) => !a.startsWith("-"))[0];
|
|
214
|
+
if (workspaceName) initGitRepo((0, path.resolve)(workspaceName));
|
|
215
|
+
}
|
|
216
|
+
return 0;
|
|
186
217
|
};
|
|
187
218
|
//#endregion
|
|
188
219
|
//#region bin/index.ts
|