@storm-software/workspace-tools
Version:
Tools for managing a Storm workspace, including various Nx generators and executors for common development tasks.
426 lines (412 loc) • 17.6 kB
JavaScript
;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 _chunk5VY5IBBQjs = require('./chunk-5VY5IBBQ.js');
var _chunkAX3RSZT7js = require('./chunk-AX3RSZT7.js');
// src/plugins/typescript/project-config.ts
var _devkit = require('@nx/devkit');
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 createNodesV2 = [
"{project.json,**/project.json}",
async (configFiles, options = { includeApps: true }, context) => {
return await _devkit.createNodesFromFiles.call(void 0,
async (file, options2 = { includeApps: true }, context2) => {
try {
const packageJson = createPackageJson(file, context2.workspaceRoot);
if (!packageJson) {
return [];
}
const tsconfig = await createTsconfig(file, context2.workspaceRoot);
if (!tsconfig) {
return [];
}
const project = createProjectFromPackageJsonNextToProjectJson(
file,
packageJson
);
if (_optionalChain([options2, 'optionalAccess', _ => _.includeApps]) === false && project.projectType === "application") {
return [];
}
let relativeRoot = project.root.replaceAll("\\", "/").replace(context2.workspaceRoot.replaceAll("\\", "/"), "");
if (relativeRoot.startsWith("/")) {
relativeRoot = relativeRoot.slice(1);
}
const enableMarkdownlint = _optionalChain([options2, 'optionalAccess', _2 => _2.enableMarkdownlint]) !== false;
const enableEslint = _optionalChain([options2, 'optionalAccess', _3 => _3.enableEslint]) !== false;
const nxJson = _nxjsonjs.readNxJson.call(void 0, context2.workspaceRoot);
const targets = _packagejson.readTargetsFromPackageJson.call(void 0,
packageJson,
nxJson,
project.root,
context2.workspaceRoot
);
if (_path.join.call(void 0, context2.workspaceRoot, project.root).startsWith(
_path.join.call(void 0, context2.workspaceRoot, "tools")
) && _optionalChain([options2, '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(context2.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) {
_chunkAX3RSZT7js.addProjectTag.call(void 0,
project,
_chunkAX3RSZT7js.ProjectTagConstants.Registry.TAG_ID,
_chunkAX3RSZT7js.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" || _chunkAX3RSZT7js.isEqualProjectTag.call(void 0,
project,
_chunkAX3RSZT7js.ProjectTagConstants.ProjectType.TAG_ID,
_chunkAX3RSZT7js.ProjectTagConstants.ProjectType.APPLICATION
) || _chunkAX3RSZT7js.isEqualProjectTag.call(void 0,
project,
_chunkAX3RSZT7js.ProjectTagConstants.DistStyle.TAG_ID,
_chunkAX3RSZT7js.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")]);
}
}
_chunkAX3RSZT7js.addProjectTag.call(void 0,
project,
_chunkAX3RSZT7js.ProjectTagConstants.Language.TAG_ID,
_chunkAX3RSZT7js.ProjectTagConstants.Language.TYPESCRIPT,
{ overwrite: true }
);
const platform = _chunk5VY5IBBQjs.getProjectPlatform.call(void 0, project);
switch (platform) {
case "worker":
_chunkAX3RSZT7js.addProjectTag.call(void 0,
project,
_chunkAX3RSZT7js.ProjectTagConstants.Platform.TAG_ID,
_chunkAX3RSZT7js.ProjectTagConstants.Platform.WORKER,
{ overwrite: true }
);
break;
case "node":
_chunkAX3RSZT7js.addProjectTag.call(void 0,
project,
_chunkAX3RSZT7js.ProjectTagConstants.Platform.TAG_ID,
_chunkAX3RSZT7js.ProjectTagConstants.Platform.NODE,
{ overwrite: true }
);
break;
case "browser":
_chunkAX3RSZT7js.addProjectTag.call(void 0,
project,
_chunkAX3RSZT7js.ProjectTagConstants.Platform.TAG_ID,
_chunkAX3RSZT7js.ProjectTagConstants.Platform.BROWSER,
{ overwrite: true }
);
break;
default:
_chunkAX3RSZT7js.addProjectTag.call(void 0,
project,
_chunkAX3RSZT7js.ProjectTagConstants.Platform.TAG_ID,
_chunkAX3RSZT7js.ProjectTagConstants.Platform.NEUTRAL,
{ overwrite: true }
);
break;
}
_chunkAX3RSZT7js.setDefaultProjectTags.call(void 0, project, name);
return _optionalChain([project, 'optionalAccess', _13 => _13.name]) ? {
projects: {
[project.name]: {
...project,
root: relativeRoot,
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"
}
}
}
}
} : {};
} catch (e) {
console.error(e);
return {};
}
},
configFiles,
options,
context
);
}
];
function createProjectFromPackageJsonNextToProjectJson(projectJsonPath, packageJson) {
const { nx, name: name2 } = packageJson;
const root = _path.dirname.call(void 0, projectJsonPath);
return {
...nx,
name: name2,
root,
targets: {}
};
}
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.warn(e);
return null;
}
}
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.warn(e);
return null;
}
}
function checkEslintConfigAtPath(directory) {
const hasEslintConfigFile = (fileName) => {
return _fs.existsSync.call(void 0, _path.join.call(void 0, directory, fileName));
};
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;
}
function checkJestConfigAtPath(directory) {
const hasJestConfigFile = (fileName) => {
return _fs.existsSync.call(void 0, _path.join.call(void 0, directory, fileName));
};
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;
}
exports.name = name; exports.createNodesV2 = createNodesV2;