Skip to content
This repository was archived by the owner on Sep 14, 2021. It is now read-only.

Commit b9f039b

Browse files
committed
@dr-js/node@0.3.0-dev.3
notable change: - break: drop `TaskAction` module and `TaskRunner` feature to allow later to add improved version - ci: run on all 3 platform & test `nodejs@14` - add: `module/TerminalColor` from `@dr-js/dev` - add: `module/Software/npm` from `@dr-js/dev` - use `createCommandWrap` for `module/Software/7z|git|tar` to allow reset command - package update
1 parent 5f8c492 commit b9f039b

25 files changed

Lines changed: 368 additions & 668 deletions

.github/workflows/ci-test.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ on: [ push ]
55
jobs:
66
build:
77
strategy:
8+
fail-fast: false # allow all test to run to the end
89
matrix:
9-
os: [ ubuntu-latest ] # [ ubuntu-latest, windows-latest, macos-latest ]
10-
node-version: [ 12.x, 13.x ]
10+
os: [ ubuntu-latest, windows-latest, macos-latest ]
11+
node-version: [ 12.x, 14.x ]
1112

1213
runs-on: ${{ matrix.os }}
1314

1415
steps:
16+
- name: Reset Git config # fix win32 CI cause `something to commit` test error: https://github.com/actions/checkout/issues/135#issuecomment-602171132
17+
run: |
18+
git config --global core.autocrlf false
19+
git config --global core.eol lf
20+
1521
- name: Setup Git repo
1622
uses: actions/checkout@v2 # https://github.com/actions/checkout
1723

@@ -26,8 +32,10 @@ jobs:
2632
echo "node: $(node -v)"
2733
echo "npm: $(npm -v)"
2834
29-
- name: Install 7zip
30-
run: sudo apt-get -y install p7zip-full
35+
- name: Patch `7z`
36+
run: node -e "process.exitCode = Number(os.platform() === 'darwin')" || brew install p7zip
37+
# linux supported: https://github.com/actions/virtual-environments/blob/ubuntu18/20200415.3/images/linux/scripts/installers/7-zip.sh
38+
# win32 supported: https://github.com/actions/virtual-environments/blob/win19/20200416.1/images/win/scripts/Installers/Install-7zip.ps1
3139

3240
- run: npm ci
3341

SPEC.md

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,24 @@
3232
- `configureServerPack`
3333
+ 📄 [source/module/ServerStatus.js](source/module/ServerStatus.js)
3434
- `getCommonServerStatus`
35-
+ 📄 [source/module/TaskAction.js](source/module/TaskAction.js)
36-
- `TASK_ACTION_TYPE`, `createTaskAction`
35+
+ 📄 [source/module/TerminalColor.js](source/module/TerminalColor.js)
36+
- `configureTerminalColor`, `shouldSupportColor`
3737
+ 📄 [source/module/TokenCache.js](source/module/TokenCache.js)
3838
- `DEFAULT_TOKEN_KEY`, `configureTokenCache`
3939
+ 📄 [source/module/PathAction/base.js](source/module/PathAction/base.js)
4040
- `PATH_ACTION_MAP`, `PATH_ACTION_TYPE`, `createPathActionTask`
4141
+ 📄 [source/module/PathAction/extraCompress.js](source/module/PathAction/extraCompress.js)
4242
- `PATH_ACTION_MAP`, `PATH_ACTION_TYPE`
4343
+ 📄 [source/module/Software/7z.js](source/module/Software/7z.js)
44-
- `compressConfig`, `compressFileConfig`, `detect`, `extractConfig`
44+
- `compressConfig`, `compressFileConfig`, `compressTgzAsync`, `detect`, `extractConfig`, `extractTgzAsync`, `getCommand`, `setCommand`
4545
+ 📄 [source/module/Software/function.js](source/module/Software/function.js)
46-
- `createDetect`
46+
- `createCommandWrap`, `createDetect`
4747
+ 📄 [source/module/Software/git.js](source/module/Software/git.js)
48-
- `detect`, `getGitBranch`, `getGitCommitHash`
48+
- `detect`, `getCommand`, `getGitBranch`, `getGitCommitHash`, `setCommand`
49+
+ 📄 [source/module/Software/npm.js](source/module/Software/npm.js)
50+
- `findUpPackageRoot`, `fromGlobalNodeModules`, `fromNpmNodeModules`, `getPathNpm`, `getPathNpmExecutable`, `getPathNpmGlobalRoot`, `parsePackageNameAndVersion`
4951
+ 📄 [source/module/Software/tar.js](source/module/Software/tar.js)
50-
- `compressConfig`, `detect`, `extractConfig`
52+
- `compressConfig`, `detect`, `extractConfig`, `getCommand`, `setCommand`
5153
+ 📄 [source/module/Stat/StatCollect.js](source/module/Stat/StatCollect.js)
5254
- `configureStatCollect`
5355
+ 📄 [source/module/Stat/StatReport.js](source/module/Stat/StatReport.js)
@@ -100,18 +102,6 @@
100102
- `configureFeaturePack`
101103
+ 📄 [source/server/feature/StatReport/option.js](source/server/feature/StatReport/option.js)
102104
- `StatReportFormatConfig`, `getStatReportOption`
103-
+ 📄 [source/server/feature/TaskRunner/configureFeaturePack.js](source/server/feature/TaskRunner/configureFeaturePack.js)
104-
- `configureFeaturePack`
105-
+ 📄 [source/server/feature/TaskRunner/option.js](source/server/feature/TaskRunner/option.js)
106-
- `TaskRunnerFormatConfig`, `getTaskRunnerOption`
107-
+ 📄 [source/server/feature/TaskRunner/permission.js](source/server/feature/TaskRunner/permission.js)
108-
- `CREATE_PERMISSION_CHECK_MAP`, `PERMISSION_TASK_RUNNER_TASK_ACTION`, `PERMISSION_TYPE`
109-
+ 📄 [source/server/feature/TaskRunner/responder.js](source/server/feature/TaskRunner/responder.js)
110-
- `createResponderTaskAction`
111-
+ 📄 [source/server/feature/TaskRunner/HTML/main.js](source/server/feature/TaskRunner/HTML/main.js)
112-
- `getHTML`
113-
+ 📄 [source/server/feature/TaskRunner/HTML/taskList.js](source/server/feature/TaskRunner/HTML/taskList.js)
114-
- `initTaskList`, `taskListStyle`
115105
+ 📄 [source/server/feature/TokenCache/option.js](source/server/feature/TokenCache/option.js)
116106
- `TokenCacheFormatConfig`, `getTokenCacheOption`
117107
+ 📄 [source/server/feature/TokenCache/responder.js](source/server/feature/TokenCache/responder.js)
@@ -228,7 +218,6 @@
228218
> --stat-collect-url [ARGUMENT=1]
229219
> --stat-collect-interval [ARGUMENT=1]
230220
> --stat-report-process-tag [ARGUMENT=1]
231-
> --task-runner-root-path [ARGUMENT=1]
232221
> ENV Usage:
233222
> "
234223
> #!/usr/bin/env bash
@@ -291,7 +280,6 @@
291280
> export DR_NODE_STAT_COLLECT_URL="[ARGUMENT=1]"
292281
> export DR_NODE_STAT_COLLECT_INTERVAL="[ARGUMENT=1]"
293282
> export DR_NODE_STAT_REPORT_PROCESS_TAG="[ARGUMENT=1]"
294-
> export DR_NODE_TASK_RUNNER_ROOT_PATH="[ARGUMENT=1]"
295283
> "
296284
> CONFIG Usage:
297285
> {
@@ -354,6 +342,5 @@
354342
> "statCollectUrl": [ "[ARGUMENT=1]" ],
355343
> "statCollectInterval": [ "[ARGUMENT=1]" ],
356344
> "statReportProcessTag": [ "[ARGUMENT=1]" ],
357-
> "taskRunnerRootPath": [ "[ARGUMENT=1]" ],
358345
> }
359346
> ```

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@dr-js/node",
4-
"version": "0.3.0-dev.2",
4+
"version": "0.3.0-dev.3",
55
"description": "A collection of strange functions, for node",
66
"author": "dr-js",
77
"license": "MIT",
@@ -23,7 +23,7 @@
2323
"build-library-dev": "dr-dev --EE BABEL_ENV=dev -E -- npm run build-library -- --watch",
2424
"build-module": "dr-dev --EE BABEL_ENV=module -E -- babel ./source --out-dir ./output-gitignore/module",
2525
"// test ========================": "",
26-
"test-dev": "dr-dev --EE BABEL_ENV=dev -E -- dr-dev --TR @babel/register --TT 999999 -T source/module/PingRace.test.js",
26+
"test-dev": "dr-dev --EE BABEL_ENV=dev -E -- dr-dev --TR @babel/register -T source/module/Software/npm.test.js",
2727
"test-source": "dr-dev --TR @babel/register -T source/ --TFS .test.js",
2828
"test-output-library": "dr-dev -T output-gitignore/library/ --TFS .test.js",
2929
"test-output-module": "dr-dev --TR @babel/register -T output-gitignore/module/ --TFS .test.js",
@@ -38,7 +38,7 @@
3838
"npm": ">=6.12"
3939
},
4040
"dependencies": {
41-
"@dr-js/core": "^0.3.0 || ^0.3.0-dev.6"
41+
"@dr-js/core": "^0.3.0 || ^0.3.0-dev.8"
4242
},
4343
"devDependencies": {
4444
"@dr-js/dev": "0.3.0-dev.6",

script/testServer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ const TEXT_SERVER_CONFIG = JSON.stringify({
4141
permissionFile: './server-permission.config.js',
4242
authFile: FILE_AUTH_KEY,
4343
explorerRootPath: './path-upload',
44-
explorerUploadMergePath: './path-upload.merge',
45-
taskRunnerRootPath: './task-runner'
44+
explorerUploadMergePath: './path-upload.merge'
4645
})
4746

4847
const FILE_CLIENT_PATH_ACTION_CONFIG = fromTemp('client-path-action.config.json')

source-bin/runServer.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { getPermissionOption, PermissionFormatConfig } from '@dr-js/node/module/
1717
import { getExplorerOption, ExplorerFormatConfig } from '@dr-js/node/module/server/feature/Explorer/option'
1818
import { getStatCollectOption, StatCollectFormatConfig } from '@dr-js/node/module/server/feature/StatCollect/option'
1919
import { getStatReportOption, StatReportFormatConfig } from '@dr-js/node/module/server/feature/StatReport/option'
20-
import { getTaskRunnerOption, TaskRunnerFormatConfig } from '@dr-js/node/module/server/feature/TaskRunner/option'
2120

2221
import { configureSampleServer } from './sampleServer'
2322

@@ -36,8 +35,7 @@ const SampleServerFormatConfig = getServerPackFormatConfig([
3635

3736
ExplorerFormatConfig,
3837
StatCollectFormatConfig,
39-
StatReportFormatConfig,
40-
TaskRunnerFormatConfig
38+
StatReportFormatConfig
4139
])
4240

4341
const runSampleServer = async (optionData) => startServer({
@@ -52,8 +50,7 @@ const runSampleServer = async (optionData) => startServer({
5250
...getPermissionOption(optionData),
5351
...getExplorerOption(optionData),
5452
...getStatCollectOption(optionData),
55-
...getStatReportOption(optionData),
56-
...getTaskRunnerOption(optionData)
53+
...getStatReportOption(optionData)
5754
})
5855

5956
const startServer = async (serverOption, featureOption) => {

source-bin/sampleServer.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { configureFeaturePack as configureFeaturePackPermission } from '@dr-js/n
88
import { configureFeaturePack as configureFeaturePackExplorer } from '@dr-js/node/module/server/feature/Explorer/configureFeaturePack'
99
import { configureFeaturePack as configureFeaturePackStatCollect } from '@dr-js/node/module/server/feature/StatCollect/configureFeaturePack'
1010
import { configureFeaturePack as configureFeaturePackStatReport } from '@dr-js/node/module/server/feature/StatReport/configureFeaturePack'
11-
import { configureFeaturePack as configureFeaturePackTaskRunner } from '@dr-js/node/module/server/feature/TaskRunner/configureFeaturePack'
1211

1312
const configureSampleServer = async ({
1413
serverPack: { server, option }, logger, routePrefix = '',
@@ -27,9 +26,7 @@ const configureSampleServer = async ({
2726
// stat collect
2827
statCollectPath, statCollectUrl, statCollectInterval,
2928
// stat report
30-
statReportProcessTag,
31-
// task-runner
32-
taskRunnerRootPath
29+
statReportProcessTag
3330
}) => {
3431
const URL_AUTH_CHECK = '/auth'
3532

@@ -61,16 +58,10 @@ const configureSampleServer = async ({
6158
statReportProcessTag
6259
})
6360

64-
const featureTaskRunner = taskRunnerRootPath && await configureFeaturePackTaskRunner({
65-
logger, routePrefix, featureAuth, featurePermission,
66-
taskRunnerRootPath
67-
})
68-
6961
const redirectUrl = featureExplorer ? featureExplorer.URL_HTML
7062
: featureStatCollect ? featureStatCollect.URL_HTML
7163
: featureStatReport ? featureStatReport.URL_HTML
72-
: featureTaskRunner ? featureTaskRunner.URL_HTML
73-
: ''
64+
: ''
7465

7566
const responderLogEnd = createResponderLogEnd({ log: logger.add })
7667

@@ -79,7 +70,6 @@ const configureSampleServer = async ({
7970
...(featureExplorer ? featureExplorer.routeList : []),
8071
...(featureStatCollect ? featureStatCollect.routeList : []),
8172
...(featureStatReport ? featureStatReport.routeList : []),
82-
...(featureTaskRunner ? featureTaskRunner.routeList : []),
8373
[ '/', 'GET', isDebugRoute ? createResponderRouteListHTML({ getRouteMap: () => routeMap })
8474
: redirectUrl ? (store) => responderEndWithRedirect(store, { redirectUrl })
8575
: (store) => responderEndWithStatusCode(store, { statusCode: 400 })
@@ -102,8 +92,7 @@ const configureSampleServer = async ({
10292
featureAuth,
10393
featureExplorer,
10494
featureStatCollect,
105-
featureStatReport,
106-
featureTaskRunner
95+
featureStatReport
10796
}
10897
}
10998

source/module/RunDetached.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const runDetached = async ({ command, argList, option, logFile }) => {
66
const logFd = await openAsync(logFile, 'a')
77
const subProcess = spawn(command, argList, {
88
stdio: [ 'ignore', logFd, logFd ], // TODO: NOTE: should test for https://github.com/joyent/libuv/issues/923
9-
detached: true, windowsHide: true, // to allow server restart and find the process again
9+
detached: true, // to allow server restart and find the process again
1010
...option
1111
})
1212
subProcess.on('error', (error) => { __DEV__ && console.warn('[ERROR][runDetached] config:', { command, argList, option, logFile }, 'error:', error) })

source/module/RunDetached.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const TEST_DETACHED_PROCESS_FUNC = (TEST_LOG_FILE) => {
2323
const subProcess = spawn(command, argList, {
2424
...option,
2525
stdio: [ 'ignore', stdoutFd, stdoutFd ], // TODO: NOTE: check: https://github.com/joyent/libuv/issues/923
26-
detached: true, windowsHide: true // to allow server restart and find the process again
26+
detached: true // to allow server restart and find the process again
2727
})
2828
subProcess.on('error', (error) => { console.warn('[ERROR][startDetachedProcess] config:', { command, argList, option }, 'error:', error) })
2929
subProcess.unref()

source/module/Software/7z.js

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
import { resolve } from 'path'
2+
import { createGzip, createGunzip } from 'zlib'
3+
import { setupStreamPipe, waitStreamStopAsync } from '@dr-js/core/module/node/data/Stream'
4+
import { createReadStream, createWriteStream } from '@dr-js/core/module/node/file/function'
5+
import { run } from '@dr-js/core/module/node/system/Run'
26

3-
import { createDetect } from './function'
7+
import { createCommandWrap, createDetect } from './function'
48

59
// NOTE: require 7z@>=16.00 for `-bs` switch
610

7-
const command = '7z'
11+
const { getCommand, setCommand } = createCommandWrap('7z')
812

913
// $ 7z
1014
// 7-Zip 18.06 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2018-12-30
1115
const detect = createDetect( // test for: `-bs{o|e|p}{0|1|2} : set output stream for output/error/progress line`
1216
'-bs{o|e|p}{0|1|2}',
1317
'expect "7z" in PATH with "-bs{o|e|p}{0|1|2}" support',
14-
command
18+
getCommand
1519
)
1620

1721
const compressConfig = (sourceDirectory, outputFile) => ({
18-
command,
22+
command: getCommand(),
1923
argList: [
2024
'a', resolve(outputFile), // can ends with `.7z` or `.zip`
2125
resolve(sourceDirectory, '*'),
@@ -24,7 +28,7 @@ const compressConfig = (sourceDirectory, outputFile) => ({
2428
})
2529

2630
const compressFileConfig = (sourceFile, outputFile) => ({
27-
command,
31+
command: getCommand(),
2832
argList: [
2933
'a', resolve(outputFile), // can ends with `.7z` or `.zip`
3034
resolve(sourceFile),
@@ -33,18 +37,54 @@ const compressFileConfig = (sourceFile, outputFile) => ({
3337
})
3438

3539
const extractConfig = (sourceFile, outputPath) => ({
36-
command,
40+
command: getCommand(),
3741
argList: [
3842
'x', resolve(sourceFile),
3943
`-o${resolve(outputPath)}`,
40-
'-y', // for overwrite existing
44+
'-aoa', // for overwrite existing
4145
'-bso0', '-bsp0' // mute extra output
4246
]
4347
})
4448

49+
// require manual setup piping: https://stackoverflow.com/questions/1359793/programmatically-extract-tar-gz-in-a-single-step-on-windows-with-7-zip/14699663#14699663
50+
const compressTgzAsync = async (sourceDirectory, outputFile) => { // for `.tgz` or `.tar.gz`
51+
const outputStream = createWriteStream(resolve(outputFile))
52+
const { promise, subProcess } = run({
53+
command: getCommand(),
54+
argList: [
55+
'a', 'placeholder-name',
56+
resolve(sourceDirectory, '*'),
57+
'-ttar', '-so' // mark archive type and output to stdout
58+
]
59+
})
60+
await Promise.all([
61+
waitStreamStopAsync(setupStreamPipe(subProcess.stdout, createGzip(), outputStream)),
62+
promise
63+
])
64+
}
65+
66+
const extractTgzAsync = async (sourceFile, outputPath) => { // for `.tgz` or `.tar.gz`
67+
const inputStream = createReadStream(resolve(sourceFile))
68+
const { promise, subProcess } = run({
69+
command: getCommand(),
70+
argList: [
71+
'x',
72+
`-o${resolve(outputPath)}`,
73+
'-aoa', // for overwrite existing
74+
'-ttar', '-si' // mark archive type and input from stdin
75+
]
76+
})
77+
await Promise.all([
78+
waitStreamStopAsync(setupStreamPipe(inputStream, createGunzip(), subProcess.stdin)),
79+
promise
80+
])
81+
}
82+
4583
export {
46-
detect,
84+
getCommand, setCommand, detect,
4785

4886
compressConfig, compressFileConfig,
49-
extractConfig
87+
extractConfig,
88+
89+
compressTgzAsync, extractTgzAsync
5090
}

0 commit comments

Comments
 (0)