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