@mnci/cli 4.0.7 → 4.0.8
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/cli.js +101 -0
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1343,6 +1343,100 @@ function markPublic(manifestPath) {
|
|
|
1343
1343
|
var WRONG_TYPES_PATH = "./dist/index.esm.d.ts";
|
|
1344
1344
|
var ACTUAL_TYPES_PATH = "./dist/src/index.d.ts";
|
|
1345
1345
|
var DECLARATION_MAP_EXCLUSION = "!**/*.d.ts.map";
|
|
1346
|
+
var ROLLUP_CONFIG_PLACEHOLDER = [
|
|
1347
|
+
" {",
|
|
1348
|
+
" // Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options",
|
|
1349
|
+
" // e.g.",
|
|
1350
|
+
" // output: { sourcemap: true },",
|
|
1351
|
+
" }"
|
|
1352
|
+
].join("\n");
|
|
1353
|
+
var ROLLUP_CONFIG_WITH_DTS_FIX = [
|
|
1354
|
+
" {",
|
|
1355
|
+
" // Added by MoNecromanCI. @nx/rollup's dts-bundle plugin writes dist/index.d.ts",
|
|
1356
|
+
" // as a stub re-exporting the real declarations, and builds that specifier with",
|
|
1357
|
+
" // path.relative() - an OS-NATIVE path. On Windows it emits",
|
|
1358
|
+
String.raw` // export * from "./src\\index";`,
|
|
1359
|
+
" // which is not a valid module specifier on ANY platform: a specifier is",
|
|
1360
|
+
" // URL-style, so / is correct everywhere and a backslash nowhere. It resolves on",
|
|
1361
|
+
" // Windows only because the resolver normalises separators there, leaving the",
|
|
1362
|
+
" // package untyped on Linux and macOS.",
|
|
1363
|
+
" //",
|
|
1364
|
+
" // mnci also points `types` past this stub, so nothing depends on it being",
|
|
1365
|
+
" // correct; this makes the emitted file correct too. Remove once Nx fixes the",
|
|
1366
|
+
" // plugin - its own devkit already exports normalizePath for exactly this.",
|
|
1367
|
+
" plugins: [",
|
|
1368
|
+
" {",
|
|
1369
|
+
" name: 'mnci-normalise-declaration-specifiers',",
|
|
1370
|
+
" writeBundle (outputOptions) {",
|
|
1371
|
+
" const { readFileSync, writeFileSync } = require('node:fs')",
|
|
1372
|
+
" const { join } = require('node:path')",
|
|
1373
|
+
" const stub = join(outputOptions.dir ?? './dist', 'index.d.ts')",
|
|
1374
|
+
" let source",
|
|
1375
|
+
" try {",
|
|
1376
|
+
" source = readFileSync(stub, 'utf8')",
|
|
1377
|
+
" } catch {",
|
|
1378
|
+
" return",
|
|
1379
|
+
" }",
|
|
1380
|
+
" // The stub carries a TWO-character escape (JSON.stringify escaped one",
|
|
1381
|
+
" // backslash), so this must not match a single one - that would turn",
|
|
1382
|
+
String.raw` // "./src\index" into "./src//index". Built from char codes so there is`,
|
|
1383
|
+
" // no escaping in this file to get wrong.",
|
|
1384
|
+
" const separator = String.fromCodePoint(92, 92)",
|
|
1385
|
+
" const normalised = source.replaceAll(separator, '/')",
|
|
1386
|
+
" if (normalised !== source) writeFileSync(stub, normalised)",
|
|
1387
|
+
" }",
|
|
1388
|
+
" }",
|
|
1389
|
+
" ]",
|
|
1390
|
+
" }"
|
|
1391
|
+
].join("\n");
|
|
1392
|
+
function repairDeclarationSpecifiers(projectRoot) {
|
|
1393
|
+
const configPath = (0, import_node_path3.join)(projectRoot, "rollup.config.cjs");
|
|
1394
|
+
if (!fileExists(configPath)) {
|
|
1395
|
+
return;
|
|
1396
|
+
}
|
|
1397
|
+
const config = (0, import_node_fs3.readFileSync)(configPath, "utf8");
|
|
1398
|
+
if (!config.includes(ROLLUP_CONFIG_PLACEHOLDER)) {
|
|
1399
|
+
return;
|
|
1400
|
+
}
|
|
1401
|
+
writeFileEnsured(
|
|
1402
|
+
configPath,
|
|
1403
|
+
config.split(ROLLUP_CONFIG_PLACEHOLDER).join(ROLLUP_CONFIG_WITH_DTS_FIX)
|
|
1404
|
+
);
|
|
1405
|
+
}
|
|
1406
|
+
function writeProjectReadme(projectRoot, projectName, testRunner) {
|
|
1407
|
+
const runner = testRunner === "vitest" ? "[Vitest](https://vitest.dev)" : "[Jest](https://jestjs.io)";
|
|
1408
|
+
writeFileEnsured(
|
|
1409
|
+
(0, import_node_path3.join)(projectRoot, "README.md"),
|
|
1410
|
+
[
|
|
1411
|
+
`# ${projectName}`,
|
|
1412
|
+
"",
|
|
1413
|
+
"Generated by [MoNecromanCI](https://github.com/russoedu/MoNecromanCi).",
|
|
1414
|
+
"",
|
|
1415
|
+
"## Building",
|
|
1416
|
+
"",
|
|
1417
|
+
`Run \`nx build ${projectName}\` to build this project.`,
|
|
1418
|
+
"",
|
|
1419
|
+
"## Running unit tests",
|
|
1420
|
+
"",
|
|
1421
|
+
`Run \`nx test ${projectName}\` to execute the unit tests via ${runner}.`,
|
|
1422
|
+
""
|
|
1423
|
+
].join("\n")
|
|
1424
|
+
);
|
|
1425
|
+
}
|
|
1426
|
+
function removeStaleGitkeeps(workspaceRoot) {
|
|
1427
|
+
for (const scaffold of ["apps", "libs", "packages"]) {
|
|
1428
|
+
const directory = (0, import_node_path3.join)(workspaceRoot, scaffold);
|
|
1429
|
+
try {
|
|
1430
|
+
const holdsAProject = (0, import_node_fs3.readdirSync)(directory, { withFileTypes: true }).some(
|
|
1431
|
+
(entry) => entry.isDirectory()
|
|
1432
|
+
);
|
|
1433
|
+
if (holdsAProject) {
|
|
1434
|
+
(0, import_node_fs3.rmSync)((0, import_node_path3.join)(directory, ".gitkeep"), { force: true });
|
|
1435
|
+
}
|
|
1436
|
+
} catch {
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1346
1440
|
function repairPublishableManifest(manifestPath) {
|
|
1347
1441
|
const manifest = readJson(manifestPath);
|
|
1348
1442
|
if (manifest.types === WRONG_TYPES_PATH) {
|
|
@@ -1412,6 +1506,7 @@ function projectTask(name, kind) {
|
|
|
1412
1506
|
return kind === "start" ? { ...base, isBackground: true } : { ...base, group: kind };
|
|
1413
1507
|
}
|
|
1414
1508
|
function registerProjectCommands(workspaceRoot, name, commands) {
|
|
1509
|
+
removeStaleGitkeeps(workspaceRoot);
|
|
1415
1510
|
const scripts = {
|
|
1416
1511
|
[`${name}:qa`]: `nx run ${name}:lint && nx run ${name}:test`
|
|
1417
1512
|
};
|
|
@@ -1879,6 +1974,8 @@ async function addNpmLib(workspaceRoot, name, options, kindProvided, stack) {
|
|
|
1879
1974
|
const manifestPath = (0, import_node_path7.join)(workspaceRoot, "packages", name, "package.json");
|
|
1880
1975
|
markPublic(manifestPath);
|
|
1881
1976
|
repairPublishableManifest(manifestPath);
|
|
1977
|
+
repairDeclarationSpecifiers((0, import_node_path7.join)(workspaceRoot, `packages/${name}`));
|
|
1978
|
+
writeProjectReadme((0, import_node_path7.join)(workspaceRoot, `packages/${name}`), `${scope}/${name}`, stack.testRunner);
|
|
1882
1979
|
removeGeneratedEslintConfig(workspaceRoot, `packages/${name}`);
|
|
1883
1980
|
registerProjectCommands(workspaceRoot, name, { build: true });
|
|
1884
1981
|
}
|
|
@@ -2207,6 +2304,8 @@ async function addReactLib(workspaceRoot, name, options, kindProvided, stack) {
|
|
|
2207
2304
|
const publishableManifest = (0, import_node_path10.join)(workspaceRoot, "packages", name, "package.json");
|
|
2208
2305
|
markPublic(publishableManifest);
|
|
2209
2306
|
repairPublishableManifest(publishableManifest);
|
|
2307
|
+
repairDeclarationSpecifiers((0, import_node_path10.join)(workspaceRoot, "packages", name));
|
|
2308
|
+
writeProjectReadme((0, import_node_path10.join)(workspaceRoot, "packages", name), `${scope}/${name}`, stack.testRunner);
|
|
2210
2309
|
removeGeneratedEslintConfig(workspaceRoot, `packages/${name}`);
|
|
2211
2310
|
registerProjectCommands(workspaceRoot, name, { build: true });
|
|
2212
2311
|
}
|
|
@@ -2228,6 +2327,8 @@ function addReactInternalLib(workspaceRoot, name, stack) {
|
|
|
2228
2327
|
const privateManifest = (0, import_node_path10.join)(workspaceRoot, "libs", name, "package.json");
|
|
2229
2328
|
markPrivate(privateManifest);
|
|
2230
2329
|
repairPublishableManifest(privateManifest);
|
|
2330
|
+
repairDeclarationSpecifiers((0, import_node_path10.join)(workspaceRoot, "libs", name));
|
|
2331
|
+
writeProjectReadme((0, import_node_path10.join)(workspaceRoot, "libs", name), name, stack.testRunner);
|
|
2231
2332
|
removeGeneratedEslintConfig(workspaceRoot, `libs/${name}`);
|
|
2232
2333
|
registerProjectCommands(workspaceRoot, name, { build: true });
|
|
2233
2334
|
}
|