@trackunit/nx-utils 0.0.41 → 0.0.44

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/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [0.0.44](https://github.com/Trackunit/manager/compare/nx-utils/0.0.43...nx-utils/0.0.44) (2023-11-16)
6
+
7
+ ### Dependency Updates
8
+
9
+ * `test-setup` updated to version `0.0.43`
10
+ ## [0.0.43](https://github.com/Trackunit/manager/compare/nx-utils/0.0.42...nx-utils/0.0.43) (2023-11-14)
11
+
12
+ ## [0.0.42](https://github.com/Trackunit/manager/compare/nx-utils/0.0.41...nx-utils/0.0.42) (2023-11-14)
13
+
14
+ ### Dependency Updates
15
+
16
+ * `test-setup` updated to version `0.0.41`
5
17
  ## [0.0.41](https://github.com/Trackunit/manager/compare/nx-utils/0.0.40...nx-utils/0.0.41) (2023-11-13)
6
18
 
7
19
  ### Dependency Updates
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/nx-utils",
3
- "version": "0.0.41",
3
+ "version": "0.0.44",
4
4
  "main": "./src/index.js",
5
5
  "repository": "https://github.com/Trackunit/manager",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
@@ -10,7 +10,7 @@
10
10
  "dependencies": {
11
11
  "@nx/devkit": "17.0.3",
12
12
  "@nx/plugin": "17.0.3",
13
- "tslib": "^2.4.0"
13
+ "tslib": "^2.6.2"
14
14
  },
15
15
  "type": "commonjs"
16
16
  }
@@ -79,46 +79,75 @@ const runNxNewCommand = (nxRoot, silent) => {
79
79
  * @param rootDir command execution directory
80
80
  * @param opts options
81
81
  * @param opts.silenceError silence errors logged to console
82
+ * @param opts.waitForProcessToTerminate Wait for the process to terminate before resolving.
82
83
  * @param opts.env environment variables to pass to the command
83
84
  */
84
85
  function runCommandAsync(command, rootDir, opts = {
85
86
  silenceError: false,
87
+ waitForProcessToTerminate: true,
86
88
  }) {
87
89
  return new Promise((resolve, reject) => {
88
- (0, child_process_1.exec)(command, {
90
+ const [cmd, ...args] = [...command.split(" ")];
91
+ const childProcess = (0, child_process_1.spawn)(cmd, args, {
89
92
  cwd: rootDir,
90
93
  env: Object.assign(Object.assign({}, process.env), opts.env),
91
- }, (err, stdout, stderr) => {
92
- if (command.includes("--verbose") || stderr.length > 0) {
94
+ shell: true,
95
+ });
96
+ let stdout = "";
97
+ let stderr = "";
98
+ childProcess.stdout.on("data", data => {
99
+ stdout += data.toString();
100
+ if (!opts.waitForProcessToTerminate && command.includes("--verbose")) {
101
+ // eslint-disable-next-line no-console
102
+ console.log(data.toString());
103
+ }
104
+ });
105
+ childProcess.stderr.on("data", data => {
106
+ stderr += data.toString();
107
+ if (!opts.waitForProcessToTerminate && command.includes("--verbose")) {
93
108
  // eslint-disable-next-line no-console
94
- console.log(`---------------------\n`, `Cwd: ${rootDir}\n`, `Cmd: ${command}\n`, `Stdout:\n`, stdout, `\nStderr:\n`, stderr, `\n---------------------`);
109
+ console.log(data.toString());
110
+ }
111
+ });
112
+ childProcess.on("close", code => {
113
+ if (code !== 0 && !opts.silenceError) {
114
+ reject(new Error(stderr));
95
115
  }
96
- if (!opts.silenceError && err) {
116
+ else if (opts.waitForProcessToTerminate) {
117
+ if (command.includes("--verbose") || stderr.length > 0) {
118
+ // eslint-disable-next-line no-console
119
+ console.log(`---------------------\n`, `Cwd: ${rootDir}\n`, `Cmd: ${command}\n`, `Stdout:\n`, stdout, `\nStderr:\n`, stderr, `\n---------------------`);
120
+ }
121
+ resolve({ process: childProcess, stdout, stderr });
122
+ }
123
+ });
124
+ childProcess.on("error", err => {
125
+ if (!opts.silenceError) {
97
126
  reject(err);
98
127
  }
99
- resolve({ stdout, stderr });
100
128
  });
129
+ if (!opts.waitForProcessToTerminate) {
130
+ resolve({ process: childProcess, stdout: "", stderr: "" });
131
+ }
101
132
  });
102
133
  }
103
134
  exports.runCommandAsync = runCommandAsync;
104
135
  /**
105
- * Run a nx command asynchronously inside the nx workspace directory
136
+ * Run a nx command asynchronously inside the given nx workspace directory
106
137
  *
107
138
  * @param command command to run
108
139
  * @param nxRootDir the nx workspace root directory
109
140
  * @param opts options
110
141
  * @param opts.silenceError silence errors logged to console
142
+ * @param opts.waitForProcessToTerminate Wait for the process to terminate before resolving.
111
143
  * @param opts.env environment variables to pass to the command
112
144
  */
113
145
  function runNxCommandAsync(command, nxRootDir, opts = {
114
146
  silenceError: false,
147
+ waitForProcessToTerminate: true,
115
148
  }) {
116
- if (process.platform === "win32") {
117
- return runCommandAsync(`./nx.bat ${command}`, nxRootDir, opts);
118
- }
119
- else {
120
- return runCommandAsync(`nx ${command}`, nxRootDir, opts);
121
- }
149
+ const cmd = `${process.platform === "win32" ? "./nx.bat" : "nx"} ${command}`;
150
+ return runCommandAsync(cmd, nxRootDir, opts);
122
151
  }
123
152
  exports.runNxCommandAsync = runNxCommandAsync;
124
153
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"projectUtils.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/projectUtils.ts"],"names":[],"mappings":";;;;AAAA,uCAAqE;AACrE,iDAAiD;AACjD,gDAAmE;AACnE,iDAA+C;AAC/C,2BAAyF;AACzF,2BAA4B;AAC5B,+BAAsD;AAUtD;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,GAAsB,EAAE;;IAChD,MAAM,UAAU,GAAG,IAAI,mBAAU,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACjD,MAAM,eAAe,GAAG,UAAU,CAAC,0BAA0B,EAAE,CAAC;IAEhE,MAAM,QAAQ,GAAsB,EAAE,CAAC;IACvC,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE;QAC9D,MAAM,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,MAAA,aAA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EAAE,EAAE;IACrC,OAAO,IAAA,cAAI,EAAC,IAAI,CAAC,CAAC;AACpB,CAAC,CAAC;AAFW,QAAA,MAAM,UAEjB;AAEF;;GAEG;AACH,SAAgB,gBAAgB,CAAC,UAAkB;IACjD,IAAI,IAAA,eAAU,EAAC,UAAU,CAAC,EAAE;QAC1B,IAAA,WAAM,EAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;KACzC;IACD,IAAA,cAAS,EAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3C,sCAAsC;IACtC,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,UAAU,CAAC,CAAC;AACpD,CAAC;AAPD,4CAOC","sourcesContent":["import { readJsonFile, Workspaces, writeJsonFile } from \"@nx/devkit\";\n// eslint-disable-next-line no-restricted-imports\nimport { fileExists, tmpProjPath, uniq } from \"@nx/plugin/testing\";\nimport { exec, execSync } from \"child_process\";\nimport { copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, rmSync } from \"fs\";\nimport { tmpdir } from \"os\";\nimport { dirname, isAbsolute, join, sep } from \"path\";\n\n/**\n * The path to the project's dist folder based on the package.json name\n */\nexport interface ProjectDistPath {\n package: string;\n path: string;\n}\n\n/**\n * Returns the path to the project's dist folder based on the package name\n *\n * @returns { ProjectDistPath[] } the path to the project's dist folder based on the package.json name\n */\nconst getProjectDetails = (): ProjectDistPath[] => {\n const workspaces = new Workspaces(process.cwd());\n const workspaceConfig = workspaces.readWorkspaceConfiguration();\n\n const projects: ProjectDistPath[] = [];\n for (const project of Object.entries(workspaceConfig.projects)) {\n const projectConfig = project[1];\n if (projectConfig.targets?.build) {\n let outputPath: string | undefined = projectConfig.targets.build.options.outputPath;\n if (!outputPath && projectConfig.targets.build.outputs && projectConfig.targets.build.outputs[0]) {\n outputPath = projectConfig.targets.build.outputs[0].replace(\"{workspaceRoot}/\", \"\");\n }\n if (outputPath) {\n const packageJsonPath = join(process.cwd(), projectConfig.root, \"package.json\");\n if (fileExists(packageJsonPath)) {\n const packageJson = readJsonFile(packageJsonPath);\n const projectDetails = {\n package: packageJson.name,\n path: outputPath,\n };\n projects.push(projectDetails);\n }\n }\n }\n }\n return projects;\n};\n\nfunction copyFolderSync(source: string, destination: string) {\n // Check if source exists and is a directory\n if (!existsSync(source) || !lstatSync(source).isDirectory()) {\n return;\n }\n\n // Create destination directory if it doesn't exist\n if (!existsSync(destination)) {\n mkdirSync(destination);\n }\n\n // Get all files and directories inside the source directory\n const items = readdirSync(source);\n\n // Iterate over each item and copy it to the destination directory\n items.forEach(item => {\n const itemPath = join(source, item);\n const destinationPath = join(destination, item);\n\n // If the item is a directory, recursively copy it\n if (lstatSync(itemPath).isDirectory()) {\n copyFolderSync(itemPath, destinationPath);\n } else {\n // Otherwise, copy the file\n copyFileSync(itemPath, destinationPath);\n }\n });\n}\n\nconst runNxNewCommand = (nxRoot: string, silent?: boolean) => {\n const projectName = nxRoot.split(sep).pop();\n const nxRootParent = dirname(nxRoot);\n\n const cmd = `npx create-nx-workspace@17.0.3 ${projectName} --appName=e2e --interactive=false --npmScope=e2e --preset=react-monorepo --verbose --nxCloud=false --packageManager=yarn --skipGit --bundler=webpack --style=css --e2eTestRunner=none`;\n\n return execSync(cmd, {\n cwd: nxRootParent,\n ...(silent ? { stdio: [\"ignore\", \"ignore\", \"ignore\"] } : {}),\n });\n};\n\n/**\n * Run a command asynchronously with the option of outputting stdout and stderr.\n *\n * @param command command to run\n * @param rootDir command execution directory\n * @param opts options\n * @param opts.silenceError silence errors logged to console\n * @param opts.env environment variables to pass to the command\n */\nexport function runCommandAsync(\n command: string,\n rootDir: string,\n opts: { silenceError?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n }\n): Promise<{ stdout: string; stderr: string }> {\n return new Promise((resolve, reject) => {\n exec(\n command,\n {\n cwd: rootDir,\n env: { ...process.env, ...opts.env },\n },\n (err, stdout, stderr) => {\n if (command.includes(\"--verbose\") || stderr.length > 0) {\n // eslint-disable-next-line no-console\n console.log(\n `---------------------\\n`,\n `Cwd: ${rootDir}\\n`,\n `Cmd: ${command}\\n`,\n `Stdout:\\n`,\n stdout,\n `\\nStderr:\\n`,\n stderr,\n `\\n---------------------`\n );\n }\n if (!opts.silenceError && err) {\n reject(err);\n }\n resolve({ stdout, stderr });\n }\n );\n });\n}\n\n/**\n * Run a nx command asynchronously inside the nx workspace directory\n *\n * @param command command to run\n * @param nxRootDir the nx workspace root directory\n * @param opts options\n * @param opts.silenceError silence errors logged to console\n * @param opts.env environment variables to pass to the command\n */\nexport function runNxCommandAsync(\n command: string,\n nxRootDir: string,\n opts: { silenceError?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n }\n): Promise<{ stdout: string; stderr: string }> {\n if (process.platform === \"win32\") {\n return runCommandAsync(`./nx.bat ${command}`, nxRootDir, opts);\n } else {\n return runCommandAsync(`nx ${command}`, nxRootDir, opts);\n }\n}\n\n/**\n * Create new Nx workspace\n *\n * @param nxRootDir the nx workspace root directory\n * @param dependencies dependencies to add to the nx repos package.json\n * @param devDependencies devDependencies to add to the nx repos package.json\n */\nconst newNxWorkspace = async (nxRootDir: string, dependencies: string[], devDependencies: string[]) => {\n if (!isAbsolute(nxRootDir)) {\n throw new Error(\"nxRootDir must be absolute path\");\n }\n runNxNewCommand(nxRootDir, true);\n updateWorkspaceLayout(nxRootDir);\n\n // copy dist folder to nxRootDir\n const newDistFolder = join(nxRootDir, \"dist\");\n const managerDistFolder = join(process.cwd(), \"dist\");\n copyFolderSync(managerDistFolder, newDistFolder);\n\n // Patch package.json with own dependencies\n const details = getProjectDetails();\n patchMainPackageJson(nxRootDir, dependencies, details, \"dependencies\");\n patchMainPackageJson(nxRootDir, devDependencies, details, \"devDependencies\");\n\n // Since npm install is not installing local dependencies, we need to run this command\n await runCommandAsync(\"yarn install\", nxRootDir);\n};\n\n/**\n * Create a new nx workspace with the given dependencies and devDependencies.\n * The workspace will be created in the given nxRootDir.\n * If the nxRootDir already exists, it will be deleted first then created.\n * The nxRootDir must be an absolute path.\n * The dependencies and devDependencies will be added to the nx workspace package.json.\n * It is expected that the dist folder of your repo has built the needed packages beforehand.\n * The dist folder will be copied to the nx workspace root directory.\n * The nx workspace will be created with the following options:\n * - preset=react-monorepo\n * - npmScope=e2e\n * - skip-install\n * - interactive=false\n * - nxCloud=false\n * - packageManager=yarn\n *\n * @param dependencies dependencies to add to the nx repos package.json\n * @param devDependencies devDependencies to add to the nx repos package.json\n * @param nxRootDir the nx workspace root directory\n */\nexport const createNxWorkspaceSetup = async (dependencies: string[], devDependencies: string[], nxRootDir: string) => {\n createRootFolder(nxRootDir);\n await newNxWorkspace(nxRootDir, dependencies, devDependencies);\n};\n\n/**\n * Patch the main nx repo package.json with the given dependencies given type\n *\n * @param nxRootDir the nx workspace root directory\n * @param packagesToAdd packages to add\n * @param paths paths to the dist folder of the packages\n * @param type type of dependency to add\n */\nconst patchMainPackageJson = (\n nxRootDir: string,\n packagesToAdd: string[],\n paths: ProjectDistPath[],\n type: \"dependencies\" | \"devDependencies\"\n) => {\n const absPackageJson = join(nxRootDir, \"package.json\");\n const packageJson = readJsonFile(absPackageJson);\n const packageDeps = packageJson?.[type] || {};\n\n const newPackageJson = { ...packageJson };\n\n for (const packageToAdd of packagesToAdd) {\n const path = paths.filter(p => p.package === packageToAdd)[0].path;\n if (path) {\n const absDistPath = `file:${join(nxRootDir, path)}`;\n packageDeps[packageToAdd] = absDistPath;\n }\n }\n newPackageJson[type] = packageDeps;\n writeJsonFile(absPackageJson, newPackageJson);\n};\n\n/**\n * Update the nx.json workspaceLayout to apps/libs format\n * This is needed because the nx.json workspaceLayout is not updated when creating a new nx workspace\n * with the nx cli.\n *\n * @param nxRootPath the nx workspace root directory\n */\nconst updateWorkspaceLayout = (nxRootPath: string) => {\n const nxJsonPath = join(nxRootPath, \"nx.json\");\n const nxJson = readJsonFile(nxJsonPath);\n nxJson.workspaceLayout = {\n appsDir: \"apps\",\n libsDir: \"libs\",\n };\n writeJsonFile(nxJsonPath, nxJson);\n};\n\n/**\n * Creates a unique path to a folder in the tmp directory of the OS or in the tmp directory of this repo.\n *\n * @returns { string } unique path\n */\nexport const uniqNxFolder = (name: string, parentFolder: \"OS_TMP\" | \"THIS_REPO\") => {\n if (parentFolder === \"THIS_REPO\") {\n return join(tmpProjPath(), uniq(name));\n }\n return join(tmpdir(), \"e2e\", uniq(name));\n};\n\n/**\n * Creates a unique name for a project.\n *\n * @returns { string } unique name\n */\nexport const unique = (name: string) => {\n return uniq(name);\n};\n\n/**\n * Creates a new root folder for the end 2 end test.\n */\nexport function createRootFolder(e2eRootDir: string) {\n if (existsSync(e2eRootDir)) {\n rmSync(e2eRootDir, { recursive: true });\n }\n mkdirSync(e2eRootDir, { recursive: true });\n // eslint-disable-next-line no-console\n console.log(\"Using E2E root folder:\", e2eRootDir);\n}\n"]}
1
+ {"version":3,"file":"projectUtils.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/projectUtils.ts"],"names":[],"mappings":";;;;AAAA,uCAAqE;AACrE,iDAAiD;AACjD,gDAAmE;AACnE,iDAAgF;AAChF,2BAAyF;AACzF,2BAA4B;AAC5B,+BAAsD;AAUtD;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,GAAsB,EAAE;;IAChD,MAAM,UAAU,GAAG,IAAI,mBAAU,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACjD,MAAM,eAAe,GAAG,UAAU,CAAC,0BAA0B,EAAE,CAAC;IAEhE,MAAM,QAAQ,GAAsB,EAAE,CAAC;IACvC,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE;QAC9D,MAAM,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,MAAA,aAAa,CAAC,OAAO,0CAAE,KAAK,EAAE;YAChC,IAAI,UAAU,GAAuB,aAAa,CAAC,OAAO,CAAC,KAAK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,YAAY,gBAKvB;AAEF;;;;GAIG;AACI,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,EAAE;IACrC,OAAO,IAAA,cAAI,EAAC,IAAI,CAAC,CAAC;AACpB,CAAC,CAAC;AAFW,QAAA,MAAM,UAEjB;AAEF;;GAEG;AACH,SAAgB,gBAAgB,CAAC,UAAkB;IACjD,IAAI,IAAA,eAAU,EAAC,UAAU,CAAC,EAAE;QAC1B,IAAA,WAAM,EAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;KACzC;IACD,IAAA,cAAS,EAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3C,sCAAsC;IACtC,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,UAAU,CAAC,CAAC;AACpD,CAAC;AAPD,4CAOC","sourcesContent":["import { readJsonFile, Workspaces, writeJsonFile } from \"@nx/devkit\";\n// eslint-disable-next-line no-restricted-imports\nimport { fileExists, tmpProjPath, uniq } from \"@nx/plugin/testing\";\nimport { ChildProcessWithoutNullStreams, execSync, spawn } from \"child_process\";\nimport { copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, rmSync } from \"fs\";\nimport { tmpdir } from \"os\";\nimport { dirname, isAbsolute, join, sep } from \"path\";\n\n/**\n * The path to the project's dist folder based on the package.json name\n */\nexport interface ProjectDistPath {\n package: string;\n path: string;\n}\n\n/**\n * Returns the path to the project's dist folder based on the package name\n *\n * @returns { ProjectDistPath[] } the path to the project's dist folder based on the package.json name\n */\nconst getProjectDetails = (): ProjectDistPath[] => {\n const workspaces = new Workspaces(process.cwd());\n const workspaceConfig = workspaces.readWorkspaceConfiguration();\n\n const projects: ProjectDistPath[] = [];\n for (const project of Object.entries(workspaceConfig.projects)) {\n const projectConfig = project[1];\n if (projectConfig.targets?.build) {\n let outputPath: string | undefined = projectConfig.targets.build.options.outputPath;\n if (!outputPath && projectConfig.targets.build.outputs && projectConfig.targets.build.outputs[0]) {\n outputPath = projectConfig.targets.build.outputs[0].replace(\"{workspaceRoot}/\", \"\");\n }\n if (outputPath) {\n const packageJsonPath = join(process.cwd(), projectConfig.root, \"package.json\");\n if (fileExists(packageJsonPath)) {\n const packageJson = readJsonFile(packageJsonPath);\n const projectDetails = {\n package: packageJson.name,\n path: outputPath,\n };\n projects.push(projectDetails);\n }\n }\n }\n }\n return projects;\n};\n\nfunction copyFolderSync(source: string, destination: string) {\n // Check if source exists and is a directory\n if (!existsSync(source) || !lstatSync(source).isDirectory()) {\n return;\n }\n\n // Create destination directory if it doesn't exist\n if (!existsSync(destination)) {\n mkdirSync(destination);\n }\n\n // Get all files and directories inside the source directory\n const items = readdirSync(source);\n\n // Iterate over each item and copy it to the destination directory\n items.forEach(item => {\n const itemPath = join(source, item);\n const destinationPath = join(destination, item);\n\n // If the item is a directory, recursively copy it\n if (lstatSync(itemPath).isDirectory()) {\n copyFolderSync(itemPath, destinationPath);\n } else {\n // Otherwise, copy the file\n copyFileSync(itemPath, destinationPath);\n }\n });\n}\n\nconst runNxNewCommand = (nxRoot: string, silent?: boolean) => {\n const projectName = nxRoot.split(sep).pop();\n const nxRootParent = dirname(nxRoot);\n\n const cmd = `npx create-nx-workspace@17.0.3 ${projectName} --appName=e2e --interactive=false --npmScope=e2e --preset=react-monorepo --verbose --nxCloud=false --packageManager=yarn --skipGit --bundler=webpack --style=css --e2eTestRunner=none`;\n\n return execSync(cmd, {\n cwd: nxRootParent,\n ...(silent ? { stdio: [\"ignore\", \"ignore\", \"ignore\"] } : {}),\n });\n};\n\n/**\n * Run a command asynchronously with the option of outputting stdout and stderr.\n *\n * @param command command to run\n * @param rootDir command execution directory\n * @param opts options\n * @param opts.silenceError silence errors logged to console\n * @param opts.waitForProcessToTerminate Wait for the process to terminate before resolving.\n * @param opts.env environment variables to pass to the command\n */\nexport function runCommandAsync(\n command: string,\n rootDir: string,\n opts: { silenceError?: boolean; waitForProcessToTerminate?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n waitForProcessToTerminate: true,\n }\n): Promise<{ process: ChildProcessWithoutNullStreams; stdout: string; stderr: string }> {\n return new Promise((resolve, reject) => {\n const [cmd, ...args] = [...command.split(\" \")];\n const childProcess = spawn(cmd, args, {\n cwd: rootDir,\n env: { ...process.env, ...opts.env },\n shell: true,\n });\n\n let stdout = \"\";\n let stderr = \"\";\n\n childProcess.stdout.on(\"data\", data => {\n stdout += data.toString();\n if (!opts.waitForProcessToTerminate && command.includes(\"--verbose\")) {\n // eslint-disable-next-line no-console\n console.log(data.toString());\n }\n });\n\n childProcess.stderr.on(\"data\", data => {\n stderr += data.toString();\n if (!opts.waitForProcessToTerminate && command.includes(\"--verbose\")) {\n // eslint-disable-next-line no-console\n console.log(data.toString());\n }\n });\n\n childProcess.on(\"close\", code => {\n if (code !== 0 && !opts.silenceError) {\n reject(new Error(stderr));\n } else if (opts.waitForProcessToTerminate) {\n if (command.includes(\"--verbose\") || stderr.length > 0) {\n // eslint-disable-next-line no-console\n console.log(\n `---------------------\\n`,\n `Cwd: ${rootDir}\\n`,\n `Cmd: ${command}\\n`,\n `Stdout:\\n`,\n stdout,\n `\\nStderr:\\n`,\n stderr,\n `\\n---------------------`\n );\n }\n resolve({ process: childProcess, stdout, stderr });\n }\n });\n\n childProcess.on(\"error\", err => {\n if (!opts.silenceError) {\n reject(err);\n }\n });\n\n if (!opts.waitForProcessToTerminate) {\n resolve({ process: childProcess, stdout: \"\", stderr: \"\" });\n }\n });\n}\n\n/**\n * Run a nx command asynchronously inside the given nx workspace directory\n *\n * @param command command to run\n * @param nxRootDir the nx workspace root directory\n * @param opts options\n * @param opts.silenceError silence errors logged to console\n * @param opts.waitForProcessToTerminate Wait for the process to terminate before resolving.\n * @param opts.env environment variables to pass to the command\n */\nexport function runNxCommandAsync(\n command: string,\n nxRootDir: string,\n opts: { silenceError?: boolean; waitForProcessToTerminate?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n waitForProcessToTerminate: true,\n }\n): Promise<{ process: ChildProcessWithoutNullStreams; stdout: string; stderr: string }> {\n const cmd = `${process.platform === \"win32\" ? \"./nx.bat\" : \"nx\"} ${command}`;\n return runCommandAsync(cmd, nxRootDir, opts);\n}\n\n/**\n * Create new Nx workspace\n *\n * @param nxRootDir the nx workspace root directory\n * @param dependencies dependencies to add to the nx repos package.json\n * @param devDependencies devDependencies to add to the nx repos package.json\n */\nconst newNxWorkspace = async (nxRootDir: string, dependencies: string[], devDependencies: string[]) => {\n if (!isAbsolute(nxRootDir)) {\n throw new Error(\"nxRootDir must be absolute path\");\n }\n runNxNewCommand(nxRootDir, true);\n updateWorkspaceLayout(nxRootDir);\n\n // copy dist folder to nxRootDir\n const newDistFolder = join(nxRootDir, \"dist\");\n const managerDistFolder = join(process.cwd(), \"dist\");\n copyFolderSync(managerDistFolder, newDistFolder);\n\n // Patch package.json with own dependencies\n const details = getProjectDetails();\n patchMainPackageJson(nxRootDir, dependencies, details, \"dependencies\");\n patchMainPackageJson(nxRootDir, devDependencies, details, \"devDependencies\");\n\n // Since npm install is not installing local dependencies, we need to run this command\n await runCommandAsync(\"yarn install\", nxRootDir);\n};\n\n/**\n * Create a new nx workspace with the given dependencies and devDependencies.\n * The workspace will be created in the given nxRootDir.\n * If the nxRootDir already exists, it will be deleted first then created.\n * The nxRootDir must be an absolute path.\n * The dependencies and devDependencies will be added to the nx workspace package.json.\n * It is expected that the dist folder of your repo has built the needed packages beforehand.\n * The dist folder will be copied to the nx workspace root directory.\n * The nx workspace will be created with the following options:\n * - preset=react-monorepo\n * - npmScope=e2e\n * - skip-install\n * - interactive=false\n * - nxCloud=false\n * - packageManager=yarn\n *\n * @param dependencies dependencies to add to the nx repos package.json\n * @param devDependencies devDependencies to add to the nx repos package.json\n * @param nxRootDir the nx workspace root directory\n */\nexport const createNxWorkspaceSetup = async (dependencies: string[], devDependencies: string[], nxRootDir: string) => {\n createRootFolder(nxRootDir);\n await newNxWorkspace(nxRootDir, dependencies, devDependencies);\n};\n\n/**\n * Patch the main nx repo package.json with the given dependencies given type\n *\n * @param nxRootDir the nx workspace root directory\n * @param packagesToAdd packages to add\n * @param paths paths to the dist folder of the packages\n * @param type type of dependency to add\n */\nconst patchMainPackageJson = (\n nxRootDir: string,\n packagesToAdd: string[],\n paths: ProjectDistPath[],\n type: \"dependencies\" | \"devDependencies\"\n) => {\n const absPackageJson = join(nxRootDir, \"package.json\");\n const packageJson = readJsonFile(absPackageJson);\n const packageDeps = packageJson?.[type] || {};\n\n const newPackageJson = { ...packageJson };\n\n for (const packageToAdd of packagesToAdd) {\n const path = paths.filter(p => p.package === packageToAdd)[0].path;\n if (path) {\n const absDistPath = `file:${join(nxRootDir, path)}`;\n packageDeps[packageToAdd] = absDistPath;\n }\n }\n newPackageJson[type] = packageDeps;\n writeJsonFile(absPackageJson, newPackageJson);\n};\n\n/**\n * Update the nx.json workspaceLayout to apps/libs format\n * This is needed because the nx.json workspaceLayout is not updated when creating a new nx workspace\n * with the nx cli.\n *\n * @param nxRootPath the nx workspace root directory\n */\nconst updateWorkspaceLayout = (nxRootPath: string) => {\n const nxJsonPath = join(nxRootPath, \"nx.json\");\n const nxJson = readJsonFile(nxJsonPath);\n nxJson.workspaceLayout = {\n appsDir: \"apps\",\n libsDir: \"libs\",\n };\n writeJsonFile(nxJsonPath, nxJson);\n};\n\n/**\n * Creates a unique path to a folder in the tmp directory of the OS or in the tmp directory of this repo.\n *\n * @returns { string } unique path\n */\nexport const uniqNxFolder = (name: string, parentFolder: \"OS_TMP\" | \"THIS_REPO\") => {\n if (parentFolder === \"THIS_REPO\") {\n return join(tmpProjPath(), uniq(name));\n }\n return join(tmpdir(), \"e2e\", uniq(name));\n};\n\n/**\n * Creates a unique name for a project.\n *\n * @returns { string } unique name\n */\nexport const unique = (name: string) => {\n return uniq(name);\n};\n\n/**\n * Creates a new root folder for the end 2 end test.\n */\nexport function createRootFolder(e2eRootDir: string) {\n if (existsSync(e2eRootDir)) {\n rmSync(e2eRootDir, { recursive: true });\n }\n mkdirSync(e2eRootDir, { recursive: true });\n // eslint-disable-next-line no-console\n console.log(\"Using E2E root folder:\", e2eRootDir);\n}\n"]}