UNPKG

@storm-software/workspace-tools

Version:

Tools for managing a Storm workspace, including various Nx generators and executors for common development tasks.

451 lines (437 loc) • 16.3 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _chunkUF6KFXG5js = require('./chunk-UF6KFXG5.js'); var _chunk7YRW5HNXjs = require('./chunk-7YRW5HNX.js'); var _chunk3GQAWCBQjs = require('./chunk-3GQAWCBQ.js'); // src/plugins/typescript/project-config.ts var _fs = require('fs'); var _path = require('path'); var _nxjsonjs = require('nx/src/config/nx-json.js'); var _fileutils = require('nx/src/utils/fileutils'); var _packagejson = require('nx/src/utils/package-json'); var _pkgtypes = require('pkg-types'); var name = "storm-software/typescript"; var createNodes = [ "{project.json,**/project.json}", async (file, opts = { includeApps: true }, ctx) => { const packageJson = createPackageJson(file, ctx.workspaceRoot); if (!packageJson) { return {}; } const tsconfig = await createTsconfig(file, ctx.workspaceRoot); if (!tsconfig) { return {}; } const project = createProjectFromPackageJsonNextToProjectJson(file, packageJson); if (_optionalChain([opts, 'optionalAccess', _ => _.includeApps]) === false && project.projectType === "application") { return {}; } const enableMarkdownlint = _optionalChain([opts, 'optionalAccess', _2 => _2.enableMarkdownlint]) !== false; const enableEslint = _optionalChain([opts, 'optionalAccess', _3 => _3.enableEslint]) !== false; const nxJson = _nxjsonjs.readNxJson.call(void 0, ctx.workspaceRoot); const targets = _packagejson.readTargetsFromPackageJson.call(void 0, packageJson, nxJson); if (_path.join.call(void 0, ctx.workspaceRoot, project.root).startsWith(_path.join.call(void 0, ctx.workspaceRoot, "tools")) && _optionalChain([opts, 'optionalAccess', _4 => _4.lintInternalTools]) !== true) { targets.lint = { dependsOn: [ "^lint" ], executor: "nx:run-commands", options: { command: "echo 'Skipping linting of internal tools package \"{projectName}\". This can be changed by setting `lintInternalTools` to `true` in the Storm TypeScript plugin options.' " } }; } else { if (!targets["lint-ls"]) { targets["lint-ls"] = { cache: true, inputs: [ "linting", "typescript", "^production" ], dependsOn: [ "^lint-ls" ], executor: "nx:run-commands", options: { command: 'pnpm exec ls-lint --config="node_modules/@storm-software/linting-tools/ls-lint/.ls-lint.yml" ' } }; } if (!targets["lint-markdown"] && enableMarkdownlint) { targets["lint-markdown"] = { cache: true, outputs: [ "{projectRoot}/**/*.md", "{projectRoot}/**/*.mdx" ], inputs: [ "linting", "{projectRoot}/**/*.md", "{projectRoot}/**/*.mdx" ], dependsOn: [ "^lint-markdown" ], executor: "nx:run-commands", options: { command: 'pnpm exec markdownlint-cli2 "{projectRoot}/*.{md,mdx}" "{projectRoot}/**/*.{md,mdx}" --config "node_modules/@storm-software/markdownlint/config/base.markdownlint-cli2.jsonc" --fix' } }; } if (!targets.lint && enableEslint) { let eslintConfig = checkEslintConfigAtPath(project.root); if (!eslintConfig) { eslintConfig = checkEslintConfigAtPath(ctx.workspaceRoot); } if (eslintConfig) { targets.lint = { cache: true, inputs: [ "linting", "typescript", "^production" ], outputs: [ "{projectRoot}/**/*.{ts,tsx,js,jsx,json,md,mdx,yaml,yml,html,css,scss,sass,less,graphql,gql}" ], dependsOn: [ "lint-markdown", "lint-knip", "^lint" ], executor: "@nx/eslint:lint", options: { format: "stylish", fix: true, errorOnUnmatchedPattern: false, cache: true, cacheLocation: "{workspaceRoot}/node_modules/.cache/eslint/{projectRoot}", eslintConfig } }; } } } if (!targets["format-toml"]) { targets["format-toml"] = { inputs: [ "linting", "{projectRoot}/**/*.toml" ], outputs: [ "{projectRoot}/**/*.toml" ], dependsOn: [ "^format-toml" ], executor: "nx:run-commands", options: { command: 'pnpm exec taplo format --config="node_modules/@storm-software/linting-tools/taplo/config.toml" --cache-path="node_modules/.cache/taplo/{projectRoot}" --colors="always" "{projectRoot}/*.toml" "{projectRoot}/**/*.toml" ' } }; } if (!targets["format-readme"]) { targets["format-readme"] = { inputs: [ "linting", "documentation", "{projectRoot}/{README.md,package.json,Cargo.toml,executors.json,generators.json}" ], outputs: [ "{projectRoot}/README.md" ], dependsOn: [ "^format-readme" ], executor: "nx:run-commands", options: { command: 'pnpm exec storm-git readme --templates="tools/readme-templates" --project="{projectName}"' } }; } if (!targets["format-prettier"]) { targets["format-prettier"] = { inputs: [ "linting", "typescript", "^production" ], outputs: [ "{projectRoot}/**/*" ], dependsOn: [ "^format-prettier" ], executor: "nx:run-commands", options: { command: 'pnpm exec prettier "{projectRoot}/**/*" --write --ignore-unknown --no-error-on-unmatched-pattern --config="node_modules/@storm-software/prettier/config.json" --ignore-path="node_modules/@storm-software/prettier/.prettierignore" --cache --cache-location="node_modules/.cache/prettier/{projectRoot}" ' } }; } if (!targets.format) { targets.format = { dependsOn: [ "format-readme", "format-toml", "format-prettier", "^format" ], executor: "nx:run-commands", options: { command: `echo 'Formatting the project files in "{projectRoot}"' ` } }; } if (!targets.clean) { targets.clean = { cache: true, executor: "nx:run-commands", inputs: [ "typescript", "^production" ], outputs: [ "{workspaceRoot}/dist/{projectRoot}" ], options: { command: "pnpm exec rimraf dist/{projectRoot}", color: true, cwd: "{workspaceRoot}" } }; } if (!targets.rebuild) { targets.rebuild = { cache: false, executor: "nx:run-commands", dependsOn: [ "clean", "^build" ], inputs: [ "typescript", "default", "^production" ], outputs: [ "{workspaceRoot}/dist/{projectRoot}" ], options: { command: `pnpm exec nx run ${project.name}:build` } }; } if (!targets.test && checkJestConfigAtPath(project.root)) { targets.test = { cache: true, executor: "@nx/jest:jest", inputs: [ "testing", "typescript", "^production" ], outputs: [ "{workspaceRoot}/coverage/{projectRoot}" ], defaultConfiguration: "development", options: { jestConfig: "{projectRoot}/jest.config.ts", passWithNoTests: true }, configurations: { development: { ci: false, codeCoverage: true }, production: { ci: true, codeCoverage: true } } }; } targets["size-limit"] = { dependsOn: [ "build", "^size-limit" ], options: {} }; const isPrivate = _nullishCoalesce(packageJson.private, () => ( false)); if (!isPrivate) { _chunk7YRW5HNXjs.addProjectTag.call(void 0, project, _chunk7YRW5HNXjs.ProjectTagConstants.Registry.TAG_ID, _chunk7YRW5HNXjs.ProjectTagConstants.Registry.NPM, { overwrite: true }); targets["nx-release-publish"] = { dependsOn: [ "build", "size-limit", "^nx-release-publish" ], executor: "@storm-software/workspace-tools:npm-publish", options: {} }; if (project.projectType === "application" || _chunk7YRW5HNXjs.isEqualProjectTag.call(void 0, project, _chunk7YRW5HNXjs.ProjectTagConstants.ProjectType.TAG_ID, _chunk7YRW5HNXjs.ProjectTagConstants.ProjectType.APPLICATION) || _chunk7YRW5HNXjs.isEqualProjectTag.call(void 0, project, _chunk7YRW5HNXjs.ProjectTagConstants.DistStyle.TAG_ID, _chunk7YRW5HNXjs.ProjectTagConstants.DistStyle.CLEAN)) { targets["clean-package"] = { cache: true, dependsOn: [ "build" ], inputs: [ "linting", "testing", "documentation", "default", "^production" ], outputs: [ "{workspaceRoot}/dist/{projectRoot}" ], executor: "@storm-software/workspace-tools:clean-package", options: { cleanReadMe: true, cleanComments: true } }; _optionalChain([targets, 'access', _5 => _5["nx-release-publish"], 'access', _6 => _6.dependsOn, 'optionalAccess', _7 => _7.push, 'call', _8 => _8("clean-package")]); _optionalChain([targets, 'access', _9 => _9["size-limit"], 'access', _10 => _10.dependsOn, 'optionalAccess', _11 => _11.push, 'call', _12 => _12("clean-package")]); } } _chunk7YRW5HNXjs.addProjectTag.call(void 0, project, _chunk7YRW5HNXjs.ProjectTagConstants.Language.TAG_ID, _chunk7YRW5HNXjs.ProjectTagConstants.Language.TYPESCRIPT, { overwrite: true }); const platform = _chunkUF6KFXG5js.getProjectPlatform.call(void 0, project); switch (platform) { case "worker": _chunk7YRW5HNXjs.addProjectTag.call(void 0, project, _chunk7YRW5HNXjs.ProjectTagConstants.Platform.TAG_ID, _chunk7YRW5HNXjs.ProjectTagConstants.Platform.WORKER, { overwrite: true }); break; case "node": _chunk7YRW5HNXjs.addProjectTag.call(void 0, project, _chunk7YRW5HNXjs.ProjectTagConstants.Platform.TAG_ID, _chunk7YRW5HNXjs.ProjectTagConstants.Platform.NODE, { overwrite: true }); break; case "browser": _chunk7YRW5HNXjs.addProjectTag.call(void 0, project, _chunk7YRW5HNXjs.ProjectTagConstants.Platform.TAG_ID, _chunk7YRW5HNXjs.ProjectTagConstants.Platform.BROWSER, { overwrite: true }); break; default: _chunk7YRW5HNXjs.addProjectTag.call(void 0, project, _chunk7YRW5HNXjs.ProjectTagConstants.Platform.TAG_ID, _chunk7YRW5HNXjs.ProjectTagConstants.Platform.NEUTRAL, { overwrite: true }); break; } _chunk7YRW5HNXjs.setDefaultProjectTags.call(void 0, project, name); return _optionalChain([project, 'optionalAccess', _13 => _13.name]) ? { projects: { [project.name]: { ...project, targets, release: { ..._optionalChain([project, 'optionalAccess', _14 => _14.release]), version: { ..._optionalChain([project, 'optionalAccess', _15 => _15.release, 'optionalAccess', _16 => _16.version]), generator: "@storm-software/workspace-tools:release-version" } } } } } : {}; } ]; function createProjectFromPackageJsonNextToProjectJson(projectJsonPath, packageJson) { const { nx, name: name2 } = packageJson; const root = _path.dirname.call(void 0, projectJsonPath); return { ...nx, name: name2, root, targets: {} }; } _chunk3GQAWCBQjs.__name.call(void 0, createProjectFromPackageJsonNextToProjectJson, "createProjectFromPackageJsonNextToProjectJson"); function createPackageJson(projectJsonPath, workspaceRoot) { try { const root = _path.dirname.call(void 0, projectJsonPath); const packageJsonPath = _path.join.call(void 0, workspaceRoot, root, "package.json"); if (!_fs.existsSync.call(void 0, packageJsonPath)) { return null; } return _fileutils.readJsonFile.call(void 0, packageJsonPath); } catch (e) { console.log(e); return null; } } _chunk3GQAWCBQjs.__name.call(void 0, createPackageJson, "createPackageJson"); async function createTsconfig(projectJsonPath, workspaceRoot) { try { const root = _path.dirname.call(void 0, projectJsonPath); const tsconfigJsonPath = _path.join.call(void 0, workspaceRoot, root, "tsconfig.json"); if (!_fs.existsSync.call(void 0, tsconfigJsonPath)) { return null; } return _pkgtypes.readTSConfig.call(void 0, tsconfigJsonPath); } catch (e) { console.log(e); return null; } } _chunk3GQAWCBQjs.__name.call(void 0, createTsconfig, "createTsconfig"); function checkEslintConfigAtPath(directory) { const hasEslintConfigFile = /* @__PURE__ */ _chunk3GQAWCBQjs.__name.call(void 0, (fileName) => { return _fs.existsSync.call(void 0, _path.join.call(void 0, directory, fileName)); }, "hasEslintConfigFile"); if (hasEslintConfigFile(".eslintrc.js")) { return ".eslintrc.js"; } else if (hasEslintConfigFile(".eslintrc.cjs")) { return ".eslintrc.cjs"; } else if (hasEslintConfigFile(".eslintrc.yaml")) { return ".eslintrc.yaml"; } else if (hasEslintConfigFile(".eslintrc.yml")) { return ".eslintrc.yml"; } else if (hasEslintConfigFile(".eslintrc.json")) { return ".eslintrc.json"; } else if (hasEslintConfigFile(".eslintrc")) { return ".eslintrc"; } else if (hasEslintConfigFile("eslint.config.js")) { return "eslint.config.js"; } else if (hasEslintConfigFile("eslint.config.cjs")) { return "eslint.config.cjs"; } else if (hasEslintConfigFile("eslint.config.mjs")) { return "eslint.config.mjs"; } else if (hasEslintConfigFile("eslint.config.ts")) { return "eslint.config.ts"; } else if (hasEslintConfigFile("eslint.config.cts")) { return "eslint.config.cts"; } else if (hasEslintConfigFile("eslint.config.mts")) { return "eslint.config.mts"; } return null; } _chunk3GQAWCBQjs.__name.call(void 0, checkEslintConfigAtPath, "checkEslintConfigAtPath"); function checkJestConfigAtPath(directory) { const hasJestConfigFile = /* @__PURE__ */ _chunk3GQAWCBQjs.__name.call(void 0, (fileName) => { return _fs.existsSync.call(void 0, _path.join.call(void 0, directory, fileName)); }, "hasJestConfigFile"); if (hasJestConfigFile("eslint.config.js")) { return "jest.config.js"; } else if (hasJestConfigFile("eslint.config.cjs")) { return "jest.config.cjs"; } else if (hasJestConfigFile("eslint.config.mjs")) { return "jest.config.mjs"; } else if (hasJestConfigFile("eslint.config.ts")) { return "jest.config.ts"; } else if (hasJestConfigFile("jest.config.cts")) { return "jest.config.cts"; } else if (hasJestConfigFile("jest.config.mts")) { return "jest.config.mts"; } return null; } _chunk3GQAWCBQjs.__name.call(void 0, checkJestConfigAtPath, "checkJestConfigAtPath"); exports.name = name; exports.createNodes = createNodes;