@graphcommerce/cli 9.0.0-canary.107 → 9.0.0-canary.108
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 +2 -0
- package/dist/bin/is-monorepo.js +29 -12
- package/package.json +9 -9
- package/src/bin/is-monorepo.ts +61 -17
package/CHANGELOG.md
CHANGED
package/dist/bin/is-monorepo.js
CHANGED
|
@@ -1,26 +1,43 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { isMonorepo } from '@graphcommerce/next-config';
|
|
3
|
-
import { detect } from 'detect-package-manager';
|
|
4
2
|
import { spawn } from 'node:child_process';
|
|
3
|
+
import 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { findParentPath } from '@graphcommerce/next-config';
|
|
6
|
+
import { detect } from 'detect-package-manager';
|
|
5
7
|
|
|
8
|
+
const debug = process.env.DEBUG === "1";
|
|
9
|
+
const log = (message) => debug && console.log(`is-monorepo: ${message}`);
|
|
10
|
+
const logError = (message) => console.error(`is-monorepo: ${message}`);
|
|
6
11
|
async function main() {
|
|
7
|
-
const
|
|
8
|
-
const command =
|
|
12
|
+
const parentPath = findParentPath(process.cwd());
|
|
13
|
+
const command = parentPath ? process.argv.slice(2)[0] : process.argv.slice(2)[1];
|
|
14
|
+
if (!command) {
|
|
15
|
+
logError("No command provided");
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
9
18
|
let packageManager = "yarn";
|
|
10
19
|
try {
|
|
11
|
-
packageManager = await detect({ cwd:
|
|
20
|
+
packageManager = await detect({ cwd: "." });
|
|
12
21
|
} catch {
|
|
13
|
-
|
|
22
|
+
log("Could not detect package manager, defaulting to yarn");
|
|
14
23
|
}
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
24
|
+
const relativePath = parentPath ? `cd ${path.relative(process.cwd(), parentPath)}/` : "cd .";
|
|
25
|
+
const commandArray = command.split(" ").map(
|
|
26
|
+
(arg) => arg.replace("[pkgrun]", `${packageManager}${packageManager === "npm" ? " run" : ""}`)
|
|
27
|
+
);
|
|
28
|
+
log(`Command: ${commandArray.join(" ")}`);
|
|
29
|
+
const finalCommand = `${relativePath} && ${commandArray.join(" ")}`;
|
|
30
|
+
log(`Executing: ${finalCommand}`);
|
|
31
|
+
const childProcess = spawn(finalCommand, [], { shell: true, stdio: "inherit" });
|
|
19
32
|
childProcess.on("exit", (code) => {
|
|
20
33
|
process.exit(code ?? 0);
|
|
21
34
|
});
|
|
22
35
|
}
|
|
23
|
-
main().catch((
|
|
24
|
-
|
|
36
|
+
main().catch((err) => {
|
|
37
|
+
if (err instanceof Error) {
|
|
38
|
+
logError(err.message);
|
|
39
|
+
} else {
|
|
40
|
+
logError("An unknown error occurred");
|
|
41
|
+
}
|
|
25
42
|
process.exit(1);
|
|
26
43
|
});
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/cli",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "9.0.0-canary.
|
|
5
|
+
"version": "9.0.0-canary.108",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "pkgroll --watch",
|
|
8
8
|
"build": "pkgroll",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"cosmiconfig": "^8.3.6",
|
|
32
32
|
"detect-package-manager": "^3.0.2",
|
|
33
33
|
"dotenv": "16.4.5",
|
|
34
|
-
"graphql": "^16.
|
|
35
|
-
"graphql-codegen-typescript-validation-schema": "^0.
|
|
34
|
+
"graphql": "^16.9.0",
|
|
35
|
+
"graphql-codegen-typescript-validation-schema": "^0.17.0",
|
|
36
36
|
"graphql-tag": "^2.12.6",
|
|
37
37
|
"rimraf": "^5.0.10",
|
|
38
38
|
"tslib": "^2.7.0",
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
"yaml": "2.5.1"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@graphcommerce/eslint-config-pwa": "^9.0.0-canary.
|
|
44
|
-
"@graphcommerce/graphql-mesh": "^9.0.0-canary.
|
|
45
|
-
"@graphcommerce/hygraph-cli": "^9.0.0-canary.
|
|
46
|
-
"@graphcommerce/next-config": "^9.0.0-canary.
|
|
47
|
-
"@graphcommerce/prettier-config-pwa": "^9.0.0-canary.
|
|
48
|
-
"@graphcommerce/typescript-config-pwa": "^9.0.0-canary.
|
|
43
|
+
"@graphcommerce/eslint-config-pwa": "^9.0.0-canary.108",
|
|
44
|
+
"@graphcommerce/graphql-mesh": "^9.0.0-canary.108",
|
|
45
|
+
"@graphcommerce/hygraph-cli": "^9.0.0-canary.108",
|
|
46
|
+
"@graphcommerce/next-config": "^9.0.0-canary.108",
|
|
47
|
+
"@graphcommerce/prettier-config-pwa": "^9.0.0-canary.108",
|
|
48
|
+
"@graphcommerce/typescript-config-pwa": "^9.0.0-canary.108",
|
|
49
49
|
"react": "^18.2.0"
|
|
50
50
|
},
|
|
51
51
|
"sideEffects": false,
|
package/src/bin/is-monorepo.ts
CHANGED
|
@@ -1,44 +1,88 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { isMonorepo } from '@graphcommerce/next-config'
|
|
3
|
-
import { detect } from 'detect-package-manager'
|
|
4
2
|
import type { ChildProcess } from 'node:child_process'
|
|
5
3
|
import { spawn } from 'node:child_process'
|
|
4
|
+
import fs from 'node:fs'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
import { findParentPath, isMonorepo } from '@graphcommerce/next-config'
|
|
7
|
+
import { detect } from 'detect-package-manager'
|
|
8
|
+
|
|
9
|
+
const debug = process.env.DEBUG === '1'
|
|
10
|
+
// eslint-disable-next-line no-console
|
|
11
|
+
const log = (message: string) => debug && console.log(`is-monorepo: ${message}`)
|
|
12
|
+
const logError = (message: string) => console.error(`is-monorepo: ${message}`)
|
|
13
|
+
|
|
14
|
+
/** Find the nearest parent directory containing a @graphcommerce/* package */
|
|
15
|
+
function findRootDir(startDir: string): string | null {
|
|
16
|
+
// Start from the parent directory to find a parent @graphcommerce package
|
|
17
|
+
let currentDir = path.dirname(startDir)
|
|
18
|
+
log(`Looking for parent packages starting from: ${currentDir}`)
|
|
19
|
+
|
|
20
|
+
while (currentDir !== path.parse(currentDir).root) {
|
|
21
|
+
try {
|
|
22
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(currentDir, 'package.json'), 'utf8'))
|
|
23
|
+
if (packageJson.name.startsWith('@graphcommerce/')) {
|
|
24
|
+
log(`Found root directory at: ${currentDir}`)
|
|
25
|
+
return currentDir
|
|
26
|
+
}
|
|
27
|
+
} catch {
|
|
28
|
+
// Continue if package.json doesn't exist or can't be parsed
|
|
29
|
+
}
|
|
30
|
+
currentDir = path.dirname(currentDir)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
6
35
|
|
|
7
36
|
/**
|
|
8
|
-
* Executes a command
|
|
37
|
+
* Executes a command depending if we're running in a monorepo or not. Usage: is-monorepo '[pkgrun]
|
|
38
|
+
* run my-script' '[pkgrun] run my-other-script'
|
|
9
39
|
*
|
|
10
|
-
*
|
|
40
|
+
* The [pkgrun] placeholder will be replaced with the detected package manager:
|
|
11
41
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* will replace `[pkgrun]` with `npm run`.
|
|
42
|
+
* - Yarn -> 'yarn'
|
|
43
|
+
* - Npm -> 'npm run'
|
|
15
44
|
*/
|
|
16
45
|
async function main() {
|
|
17
|
-
const isMono = isMonorepo()
|
|
18
|
-
const
|
|
46
|
+
// const isMono = isMonorepo()
|
|
47
|
+
const parentPath = findParentPath(process.cwd())
|
|
48
|
+
|
|
49
|
+
const command = parentPath ? process.argv.slice(2)[0] : process.argv.slice(2)[1]
|
|
50
|
+
|
|
51
|
+
if (!command) {
|
|
52
|
+
logError('No command provided')
|
|
53
|
+
process.exit(1)
|
|
54
|
+
}
|
|
19
55
|
|
|
20
56
|
let packageManager = 'yarn'
|
|
21
57
|
try {
|
|
22
|
-
packageManager = await detect({ cwd:
|
|
58
|
+
packageManager = await detect({ cwd: '.' })
|
|
23
59
|
} catch {
|
|
24
|
-
|
|
60
|
+
log('Could not detect package manager, defaulting to yarn')
|
|
25
61
|
}
|
|
26
62
|
|
|
63
|
+
const relativePath = parentPath ? `cd ${path.relative(process.cwd(), parentPath)}/` : 'cd .'
|
|
27
64
|
const commandArray = command
|
|
28
65
|
.split(' ')
|
|
29
|
-
.map((arg) =>
|
|
66
|
+
.map((arg) =>
|
|
67
|
+
arg.replace('[pkgrun]', `${packageManager}${packageManager === 'npm' ? ' run' : ''}`),
|
|
68
|
+
)
|
|
69
|
+
log(`Command: ${commandArray.join(' ')}`)
|
|
30
70
|
|
|
31
|
-
|
|
71
|
+
const finalCommand = `${relativePath} && ${commandArray.join(' ')}`
|
|
72
|
+
log(`Executing: ${finalCommand}`)
|
|
32
73
|
|
|
33
|
-
const
|
|
34
|
-
const childProcess: ChildProcess = spawn(cmd, args, { shell: true, stdio: 'inherit' })
|
|
74
|
+
const childProcess: ChildProcess = spawn(finalCommand, [], { shell: true, stdio: 'inherit' })
|
|
35
75
|
|
|
36
76
|
childProcess.on('exit', (code) => {
|
|
37
77
|
process.exit(code ?? 0)
|
|
38
78
|
})
|
|
39
79
|
}
|
|
40
80
|
|
|
41
|
-
main().catch((
|
|
42
|
-
|
|
81
|
+
main().catch((err: unknown) => {
|
|
82
|
+
if (err instanceof Error) {
|
|
83
|
+
logError(err.message)
|
|
84
|
+
} else {
|
|
85
|
+
logError('An unknown error occurred')
|
|
86
|
+
}
|
|
43
87
|
process.exit(1)
|
|
44
88
|
})
|