lscripts 1.2.0 → 1.3.0
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/lscripts.js +28 -8
- package/package.json +1 -1
package/lscripts.js
CHANGED
|
@@ -6,12 +6,34 @@ import fs from 'fs'
|
|
|
6
6
|
import { exit } from 'process'
|
|
7
7
|
import { spawn } from 'child_process'
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (fs.existsSync(
|
|
13
|
-
return null
|
|
14
|
-
}
|
|
9
|
+
const rootDir = '/'
|
|
10
|
+
|
|
11
|
+
const findPackageJsonInWorkingDirOrParent = (currentDir = './') => {
|
|
12
|
+
if (fs.existsSync(`${currentDir}package.json`)) return fs.readFileSync(`${currentDir}package.json`)
|
|
13
|
+
if (fs.realpathSync(currentDir) === rootDir) return null
|
|
14
|
+
return findPackageJsonInWorkingDirOrParent(`${currentDir}../`)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const getScriptsFromPackageJson = (packageJson) =>
|
|
18
|
+
Object.entries(JSON.parse(packageJson).scripts)
|
|
19
|
+
|
|
20
|
+
const getPackageManagerEngine = (currentDir = './') => {
|
|
21
|
+
if (fs.existsSync(`${currentDir}package-lock.json`)) return 'npm'
|
|
22
|
+
if (fs.existsSync(`${currentDir}yarn.lock`)) return 'yarn'
|
|
23
|
+
if (fs.existsSync(`${currentDir}pnpm-lock.yaml`)) return 'pnpm'
|
|
24
|
+
if (fs.realpathSync(currentDir) === rootDir) return null
|
|
25
|
+
return getPackageManagerEngine((`${currentDir}../`))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const packageJson = findPackageJsonInWorkingDirOrParent()
|
|
29
|
+
|
|
30
|
+
if (!packageJson) {
|
|
31
|
+
console.log('No package.json was found in current directory or parent directories.')
|
|
32
|
+
console.log('Make sure you are in a NodeJS project before running lscripts.')
|
|
33
|
+
exit(1)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const scripts = getScriptsFromPackageJson(packageJson)
|
|
15
37
|
|
|
16
38
|
const runner = getPackageManagerEngine()
|
|
17
39
|
|
|
@@ -22,8 +44,6 @@ if (!runner) {
|
|
|
22
44
|
exit(1)
|
|
23
45
|
}
|
|
24
46
|
|
|
25
|
-
const scripts = Object.entries(JSON.parse(fs.readFileSync('./package.json')).scripts)
|
|
26
|
-
|
|
27
47
|
const regex = /^(.+) - /
|
|
28
48
|
|
|
29
49
|
const source = async (_, input) => {
|
package/package.json
CHANGED