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

Commit ba5807f

Browse files
committed
@dr-js/node@0.3.0-dev.4
notable change: - dev-break: drop `shouldSupportColor()` from 'module/TerminalColor' - dev-fix: `compressTgzAsync|extractTgzAsync` option - add: `module/TerminalStatusBar` - sort compress test script - package update
1 parent b9f039b commit ba5807f

13 files changed

Lines changed: 296 additions & 96 deletions

File tree

.github/workflows/ci-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
echo "node: $(node -v)"
3333
echo "npm: $(npm -v)"
3434
35-
- name: Patch `7z`
35+
- name: Patch `7z` on darwin
3636
run: node -e "process.exitCode = Number(os.platform() === 'darwin')" || brew install p7zip
3737
# linux supported: https://github.com/actions/virtual-environments/blob/ubuntu18/20200415.3/images/linux/scripts/installers/7-zip.sh
3838
# win32 supported: https://github.com/actions/virtual-environments/blob/win19/20200416.1/images/win/scripts/Installers/Install-7zip.ps1

SPEC.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
+ 📄 [source/module/ServerStatus.js](source/module/ServerStatus.js)
3434
- `getCommonServerStatus`
3535
+ 📄 [source/module/TerminalColor.js](source/module/TerminalColor.js)
36-
- `configureTerminalColor`, `shouldSupportColor`
36+
- `configureTerminalColor`
37+
+ 📄 [source/module/TerminalStatusBar.js](source/module/TerminalStatusBar.js)
38+
- `createStatusBar`
3739
+ 📄 [source/module/TokenCache.js](source/module/TokenCache.js)
3840
- `DEFAULT_TOKEN_KEY`, `configureTokenCache`
3941
+ 📄 [source/module/PathAction/base.js](source/module/PathAction/base.js)

package-lock.json

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

package.json

Lines changed: 9 additions & 8 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.3",
4+
"version": "0.3.0-dev.4",
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 -T source/module/Software/npm.test.js",
26+
"test-dev": "dr-dev --EE BABEL_ENV=dev -E -- dr-dev --TR @babel/register -T source/module/Software/7z.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",
@@ -34,14 +34,15 @@
3434
"prepack": "echo \"Error: pack with script-*\" && exit 1"
3535
},
3636
"engines": {
37-
"node": ">=12.13",
38-
"npm": ">=6.12"
37+
"node": ">=12.16",
38+
"npm": ">=6.14"
3939
},
4040
"dependencies": {
41-
"@dr-js/core": "^0.3.0 || ^0.3.0-dev.8"
41+
"@dr-js/core": "^0.3.0 || ^0.3.0-dev.9"
4242
},
4343
"devDependencies": {
44-
"@dr-js/dev": "0.3.0-dev.6",
45-
"@dr-js/dev-babel": "0.3.0-dev.6"
46-
}
44+
"@dr-js/dev": "0.3.0-dev.8",
45+
"@dr-js/dev-babel": "0.3.0-dev.8"
46+
},
47+
"sideEffects": false
4748
}

source/module/Software/7z.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ const compressTgzAsync = async (sourceDirectory, outputFile) => { // for `.tgz`
5555
'a', 'placeholder-name',
5656
resolve(sourceDirectory, '*'),
5757
'-ttar', '-so' // mark archive type and output to stdout
58-
]
58+
],
59+
option: { stdio: [ 'ignore', 'pipe', 'ignore' ] }
5960
})
6061
await Promise.all([
6162
waitStreamStopAsync(setupStreamPipe(subProcess.stdout, createGzip(), outputStream)),
@@ -72,7 +73,8 @@ const extractTgzAsync = async (sourceFile, outputPath) => { // for `.tgz` or `.t
7273
`-o${resolve(outputPath)}`,
7374
'-aoa', // for overwrite existing
7475
'-ttar', '-si' // mark archive type and input from stdin
75-
]
76+
],
77+
option: { stdio: [ 'pipe', 'ignore', 'ignore' ] }
7678
})
7779
await Promise.all([
7880
waitStreamStopAsync(setupStreamPipe(inputStream, createGunzip(), subProcess.stdin)),

source/module/Software/7z.test.js

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,72 @@
1-
import { detect } from './7z'
1+
import { resolve, basename } from 'path'
2+
import { createDirectory } from '@dr-js/core/module/node/file/Directory'
3+
import { run } from '@dr-js/core/module/node/system/Run'
24

3-
const { describe, it } = global
5+
import {
6+
fromRoot, setupRoot, clearRoot,
7+
SOURCE_FILE, SOURCE_DIRECTORY,
8+
verifyOutputFile, verifyOutputDirectory
9+
} from './compress.test/function'
10+
11+
import {
12+
detect,
13+
14+
compressConfig, compressFileConfig,
15+
extractConfig,
16+
17+
compressTgzAsync, extractTgzAsync
18+
} from './7z'
19+
20+
const { describe, it, before, after, info = console.log } = global
21+
22+
const TEST_TEMP = fromRoot(`test-${basename(__filename)}`)
23+
const fromTemp = (...args) => resolve(TEST_TEMP, ...args)
24+
25+
before('prepare', setupRoot)
26+
after('clear', clearRoot)
427

528
describe('Node.Module.Software.7z', () => {
629
it('detect()', detect)
30+
31+
it('compressConfig() & extractConfig()', async () => {
32+
info('compressConfig')
33+
await Promise.all([
34+
run(compressConfig(SOURCE_DIRECTORY, fromTemp('compressConfig/test.7z'))).promise,
35+
run(compressConfig(SOURCE_DIRECTORY, fromTemp('compressConfig/test.zip'))).promise
36+
])
37+
info('extractConfig')
38+
await Promise.all([
39+
run(extractConfig(fromTemp('compressConfig/test.7z'), fromTemp('extractConfig/test.7z-extract/'))).promise,
40+
run(extractConfig(fromTemp('compressConfig/test.zip'), fromTemp('extractConfig/test.zip-extract/'))).promise
41+
])
42+
info('verifyOutputDirectory')
43+
await verifyOutputDirectory(fromTemp('extractConfig/test.7z-extract/'))
44+
await verifyOutputDirectory(fromTemp('extractConfig/test.zip-extract/'))
45+
})
46+
47+
it('compressFileConfig()', async () => {
48+
info('compressFileConfig')
49+
await Promise.all([
50+
run(compressFileConfig(SOURCE_FILE, fromTemp('compressFileConfig/test-file.7z'))).promise,
51+
run(compressFileConfig(SOURCE_FILE, fromTemp('compressFileConfig/test-file.zip'))).promise
52+
])
53+
info('extractConfig')
54+
await Promise.all([
55+
run(extractConfig(fromTemp('compressFileConfig/test-file.7z'), fromTemp('extractConfig/test-file.7z-extract'))).promise,
56+
run(extractConfig(fromTemp('compressFileConfig/test-file.zip'), fromTemp('extractConfig/test-file.zip-extract'))).promise
57+
])
58+
info('verifyOutputFile')
59+
await verifyOutputFile(fromTemp('extractConfig/test-file.7z-extract', basename(SOURCE_FILE)))
60+
await verifyOutputFile(fromTemp('extractConfig/test-file.zip-extract', basename(SOURCE_FILE)))
61+
})
62+
63+
it('compressTgzAsync() & extractTgzAsync()', async () => {
64+
info('compressTgzAsync')
65+
await createDirectory(fromTemp('compressTgzAsync/'))
66+
await compressTgzAsync(SOURCE_DIRECTORY, fromTemp('compressTgzAsync/test.tgz'))
67+
info('extractTgzAsync')
68+
await extractTgzAsync(fromTemp('compressTgzAsync/test.tgz'), fromTemp('extractTgzAsync/test.tgz-extract/'))
69+
info('verifyOutputDirectory')
70+
await verifyOutputDirectory(fromTemp('extractTgzAsync/test.tgz-extract/'))
71+
})
772
})
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { resolve, relative } from 'path'
2+
import { strictEqual, stringifyEqual } from '@dr-js/core/module/common/verify'
3+
import { readFileAsync, writeFileAsync } from '@dr-js/core/module/node/file/function'
4+
import { PATH_TYPE, toPosixPath } from '@dr-js/core/module/node/file/Path'
5+
import { createDirectory, getDirectoryInfoTree } from '@dr-js/core/module/node/file/Directory'
6+
import { modifyDelete } from '@dr-js/core/module/node/file/Modify'
7+
import { resetDirectory } from '@dr-js/dev/module/node/file'
8+
9+
const TEST_ROOT = resolve(__dirname, 'test-root-gitignore/')
10+
const fromRoot = (...args) => resolve(TEST_ROOT, ...args)
11+
12+
const SOURCE_FILE = fromRoot('source-file')
13+
const SOURCE_DIRECTORY = fromRoot('source-directory/')
14+
15+
const EXPECT_FILE_CONTENT = 'console.log([ { 1: 2 } ])\n'.repeat(64)
16+
const EXPECT_INFO_LIST = [
17+
[ '', [ { 'name': '1', 'type': 'Directory', 'size': null }, { 'name': 'file-empty', 'type': 'File', 'size': 0 }, { 'name': 'file.js', 'type': 'File', 'size': Buffer.byteLength(EXPECT_FILE_CONTENT) } ] ],
18+
[ '1', [ { 'name': '2', 'type': 'Directory', 'size': null } ] ],
19+
[ '1/2', [ { 'name': '3', 'type': 'Directory', 'size': null } ] ],
20+
[ '1/2/3', [ { 'name': '4', 'type': 'Directory', 'size': null } ] ],
21+
[ '1/2/3/4', [ { 'name': '5', 'type': 'Directory', 'size': null } ] ],
22+
[ '1/2/3/4/5', [] ]
23+
]
24+
25+
const setupRoot = async () => {
26+
await resetDirectory(SOURCE_DIRECTORY)
27+
28+
await writeFileAsync(SOURCE_FILE, EXPECT_FILE_CONTENT)
29+
30+
await createDirectory(fromRoot(SOURCE_DIRECTORY, '1/2/3/4/5'))
31+
await writeFileAsync(fromRoot(SOURCE_DIRECTORY, 'file-empty'), '')
32+
await writeFileAsync(fromRoot(SOURCE_DIRECTORY, 'file.js'), EXPECT_FILE_CONTENT)
33+
}
34+
35+
const clearRoot = async () => {
36+
await modifyDelete(TEST_ROOT)
37+
}
38+
39+
const verifyOutputFile = async (path) => {
40+
strictEqual(String(await readFileAsync(path)), EXPECT_FILE_CONTENT)
41+
}
42+
43+
const verifyOutputDirectory = async (path) => {
44+
const infoTree = await getDirectoryInfoTree(path)
45+
const infoList = Object.entries(infoTree.subInfoListMap).map(([ key, subInfoList ]) => [ toPosixPath(relative(path, key)), subInfoList.map(({ name, type, stat }) => ({ name, type, size: type === PATH_TYPE.Directory ? null : stat.size })) ])
46+
// console.log('verifyOutputDirectory', infoList.map((v) => JSON.stringify(v)))
47+
// console.log('EXPECT_INFO_LIST', EXPECT_INFO_LIST.map((v) => JSON.stringify(v)))
48+
stringifyEqual(infoList, EXPECT_INFO_LIST)
49+
}
50+
51+
export {
52+
fromRoot, setupRoot, clearRoot,
53+
SOURCE_FILE, SOURCE_DIRECTORY,
54+
verifyOutputFile, verifyOutputDirectory
55+
}

source/module/Software/tar.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@ const compressConfig = (sourceDirectory, outputFile) => ({
1717
argList: [
1818
'-zcf', resolve(outputFile), // should ends with `.tgz`
1919
'-C', resolve(sourceDirectory),
20-
'.'
20+
'.' // TODO: NOTE: the result tar will have a `./` as root folder, but this will get resolved and disappear after extract
2121
]
2222
})
2323

2424
const extractConfig = (sourceFile, outputPath) => ({
2525
command: getCommand(),
2626
argList: [
27-
'--strip-components', '1',
28-
'-xf', sourceFile, // use '-xf' for both gzip/xz, check: https://unix.stackexchange.com/questions/253596/tar-extraction-also-automatically-decompresses
29-
'-C', outputPath
27+
'-xf', resolve(sourceFile), // use '-xf' for both gzip/xz, check: https://unix.stackexchange.com/questions/253596/tar-extraction-also-automatically-decompresses
28+
'-C', resolve(outputPath)
3029
]
3130
})
3231

0 commit comments

Comments
 (0)