First upload version 0.0.1
This commit is contained in:
0
node_modules/chmodrp/.gitkeep
generated
vendored
Normal file
0
node_modules/chmodrp/.gitkeep
generated
vendored
Normal file
117
node_modules/chmodrp/index.cjs
generated
vendored
Normal file
117
node_modules/chmodrp/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var fs = require('node:fs');
|
||||
var path = require('node:path');
|
||||
|
||||
function _interopNamespace(e) {
|
||||
if (e && e.__esModule) return e;
|
||||
var n = Object.create(null);
|
||||
if (e) {
|
||||
Object.keys(e).forEach(function (k) {
|
||||
if (k !== 'default') {
|
||||
var d = Object.getOwnPropertyDescriptor(e, k);
|
||||
Object.defineProperty(n, k, d.get ? d : {
|
||||
enumerable: true,
|
||||
get: function () { return e[k]; }
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
n["default"] = e;
|
||||
return Object.freeze(n);
|
||||
}
|
||||
|
||||
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
||||
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
||||
|
||||
// If a party has r, add x
|
||||
// so that dirs are listable
|
||||
const dirMode = (mode) => {
|
||||
mode = Number(mode);
|
||||
if (mode & 0o400)
|
||||
mode |= 0o100;
|
||||
if (mode & 0o40)
|
||||
mode |= 0o10;
|
||||
if (mode & 0o4)
|
||||
mode |= 0o1;
|
||||
return mode;
|
||||
};
|
||||
async function chmodrKid(entryPath, child, mode) {
|
||||
if (typeof child === 'string') {
|
||||
const stats = (await fs__namespace.promises.lstat(path__namespace.resolve(entryPath, child)));
|
||||
stats.name = child;
|
||||
await chmodrKid(entryPath, stats, mode);
|
||||
return;
|
||||
}
|
||||
if (child.isDirectory()) {
|
||||
await chmodr(path__namespace.resolve(entryPath, child.name), mode);
|
||||
await fs__namespace.promises.chmod(path__namespace.resolve(entryPath, child.name), dirMode(mode));
|
||||
}
|
||||
else {
|
||||
await fs__namespace.promises.chmod(path__namespace.resolve(entryPath, child.name), mode);
|
||||
}
|
||||
}
|
||||
function chmodrKidSync(entryPath, child, mode) {
|
||||
if (typeof child === 'string') {
|
||||
const stats = fs__namespace.lstatSync(path__namespace.resolve(entryPath, child));
|
||||
stats.name = child;
|
||||
child = stats;
|
||||
}
|
||||
if (child.isDirectory()) {
|
||||
chmodrSync(path__namespace.resolve(entryPath, child.name), mode);
|
||||
fs__namespace.chmodSync(path__namespace.resolve(entryPath, child.name), dirMode(mode));
|
||||
}
|
||||
else {
|
||||
fs__namespace.chmodSync(path__namespace.resolve(entryPath, child.name), mode);
|
||||
}
|
||||
}
|
||||
async function chmodr(entryPath, mode) {
|
||||
try {
|
||||
const children = await fs__namespace.promises.readdir(entryPath, {
|
||||
withFileTypes: true,
|
||||
});
|
||||
if (children.length === 0) {
|
||||
await fs__namespace.promises.chmod(entryPath, dirMode(mode));
|
||||
return;
|
||||
}
|
||||
await Promise.all(children.map(async (child) => {
|
||||
await chmodrKid(entryPath, child, mode);
|
||||
await fs__namespace.promises.chmod(entryPath, dirMode(mode));
|
||||
}));
|
||||
}
|
||||
catch (error) {
|
||||
const err = error;
|
||||
if (err.code === 'ENOTDIR') {
|
||||
await fs__namespace.promises.chmod(entryPath, mode);
|
||||
}
|
||||
// any error other than ENOTDIR means it's not readable, or
|
||||
// doesn't exist. Give up.
|
||||
else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
function chmodrSync(entryPath, mode) {
|
||||
let children;
|
||||
try {
|
||||
children = fs__namespace.readdirSync(entryPath, { withFileTypes: true });
|
||||
for (const child of children) {
|
||||
chmodrKidSync(entryPath, child, mode);
|
||||
}
|
||||
fs__namespace.chmodSync(entryPath, dirMode(mode));
|
||||
}
|
||||
catch (error) {
|
||||
const err = error;
|
||||
if (err.code === 'ENOTDIR') {
|
||||
fs__namespace.chmodSync(entryPath, mode);
|
||||
}
|
||||
else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.chmodr = chmodr;
|
||||
exports.chmodrSync = chmodrSync;
|
||||
1
node_modules/chmodrp/index.d.ts
generated
vendored
Normal file
1
node_modules/chmodrp/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export { chmodr, chmodrSync } from './utils/chmodr.js';
|
||||
1
node_modules/chmodrp/index.js
generated
vendored
Normal file
1
node_modules/chmodrp/index.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export { chmodr, chmodrSync } from './utils/chmodr.js';
|
||||
9
node_modules/chmodrp/license
generated
vendored
Normal file
9
node_modules/chmodrp/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Leon Si <contact@leonzalion.com> (https://leonzalion.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
46
node_modules/chmodrp/package.json
generated
vendored
Normal file
46
node_modules/chmodrp/package.json
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "chmodrp",
|
||||
"version": "1.0.2",
|
||||
"description": "`chmod -R` with the Promise API",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/leonzalion/chmodrp.git"
|
||||
},
|
||||
"homepage": "https://github.com/leonzalion/chmodrp#readme",
|
||||
"author": {
|
||||
"name": "Leon Si",
|
||||
"email": "contact@leonzalion.com",
|
||||
"url": "https://leonzalion.com"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"import": "./index.js",
|
||||
"require": "./index.cjs"
|
||||
},
|
||||
"devDependencies": {
|
||||
"desm": "^1.2.0",
|
||||
"execa": "^6.1.0",
|
||||
"lion-system": "^1.3.27",
|
||||
"vitest": "^0.12.3"
|
||||
},
|
||||
"publishConfig": {
|
||||
"directory": "dist"
|
||||
},
|
||||
"keywords": [
|
||||
"chmod",
|
||||
"chmodr",
|
||||
"recursive",
|
||||
"promise",
|
||||
"fs"
|
||||
],
|
||||
"scripts": {
|
||||
"release": "lionp",
|
||||
"build": "node-ts ./scripts/build.ts",
|
||||
"start": "node-ts ./src/index.ts",
|
||||
"test": "vitest run",
|
||||
"lint": "eslint --cache --fix .",
|
||||
"prettier": "prettier --write .",
|
||||
"typecheck": "tsc --noEmit"
|
||||
}
|
||||
}
|
||||
47
node_modules/chmodrp/readme.md
generated
vendored
Normal file
47
node_modules/chmodrp/readme.md
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
# chmodrp
|
||||
|
||||
[](https://npmjs.com/package/chmodrp)
|
||||
|
||||
A port of [isaacs's chmodr](https://github.com/isaacs/chmodr) but using the Promise API.\
|
||||
Has the same effect as the command line command: `chmod -R`.
|
||||
|
||||
## Install
|
||||
|
||||
```shell
|
||||
npm install chmodrp
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### chmodr(path, mode)
|
||||
|
||||
Returns: `Promise<void>`
|
||||
|
||||
Takes the same arguments as [`fs.promises.chmod()`](https://nodejs.org/api/fs.html#fspromiseschmodpath-mode)
|
||||
|
||||
#### path
|
||||
|
||||
Type: `string`
|
||||
|
||||
The path of the file to recursively `chmod`.
|
||||
|
||||
#### mode
|
||||
|
||||
Type: `number`
|
||||
|
||||
The file mode to `chmod` the files with.
|
||||
|
||||
### chmodrSync(path, mode)
|
||||
|
||||
Returns: `void`
|
||||
|
||||
Does the same thing as `chmodr(path, mode)` but synchronously.
|
||||
|
||||
## Usage
|
||||
|
||||
```typescript
|
||||
import { chmodr, chmodrSync } from 'chmodrp';
|
||||
|
||||
await chmodr('/var/www/my/test/folder', 0o777);
|
||||
chmodrSync('/var/www/my/test/folder2', 0o777);
|
||||
```
|
||||
4
node_modules/chmodrp/utils/chmodr.d.ts
generated
vendored
Normal file
4
node_modules/chmodrp/utils/chmodr.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
/// <reference types="node" />
|
||||
import * as fs from 'node:fs';
|
||||
export declare function chmodr(entryPath: string, mode: fs.Mode): Promise<void>;
|
||||
export declare function chmodrSync(entryPath: string, mode: fs.Mode): void;
|
||||
88
node_modules/chmodrp/utils/chmodr.js
generated
vendored
Normal file
88
node_modules/chmodrp/utils/chmodr.js
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
// If a party has r, add x
|
||||
// so that dirs are listable
|
||||
const dirMode = (mode) => {
|
||||
mode = Number(mode);
|
||||
if (mode & 0o400)
|
||||
mode |= 0o100;
|
||||
if (mode & 0o40)
|
||||
mode |= 0o10;
|
||||
if (mode & 0o4)
|
||||
mode |= 0o1;
|
||||
return mode;
|
||||
};
|
||||
async function chmodrKid(entryPath, child, mode) {
|
||||
if (typeof child === 'string') {
|
||||
const stats = (await fs.promises.lstat(path.resolve(entryPath, child)));
|
||||
stats.name = child;
|
||||
await chmodrKid(entryPath, stats, mode);
|
||||
return;
|
||||
}
|
||||
if (child.isDirectory()) {
|
||||
await chmodr(path.resolve(entryPath, child.name), mode);
|
||||
await fs.promises.chmod(path.resolve(entryPath, child.name), dirMode(mode));
|
||||
}
|
||||
else {
|
||||
await fs.promises.chmod(path.resolve(entryPath, child.name), mode);
|
||||
}
|
||||
}
|
||||
function chmodrKidSync(entryPath, child, mode) {
|
||||
if (typeof child === 'string') {
|
||||
const stats = fs.lstatSync(path.resolve(entryPath, child));
|
||||
stats.name = child;
|
||||
child = stats;
|
||||
}
|
||||
if (child.isDirectory()) {
|
||||
chmodrSync(path.resolve(entryPath, child.name), mode);
|
||||
fs.chmodSync(path.resolve(entryPath, child.name), dirMode(mode));
|
||||
}
|
||||
else {
|
||||
fs.chmodSync(path.resolve(entryPath, child.name), mode);
|
||||
}
|
||||
}
|
||||
export async function chmodr(entryPath, mode) {
|
||||
try {
|
||||
const children = await fs.promises.readdir(entryPath, {
|
||||
withFileTypes: true,
|
||||
});
|
||||
if (children.length === 0) {
|
||||
await fs.promises.chmod(entryPath, dirMode(mode));
|
||||
return;
|
||||
}
|
||||
await Promise.all(children.map(async (child) => {
|
||||
await chmodrKid(entryPath, child, mode);
|
||||
await fs.promises.chmod(entryPath, dirMode(mode));
|
||||
}));
|
||||
}
|
||||
catch (error) {
|
||||
const err = error;
|
||||
if (err.code === 'ENOTDIR') {
|
||||
await fs.promises.chmod(entryPath, mode);
|
||||
}
|
||||
// any error other than ENOTDIR means it's not readable, or
|
||||
// doesn't exist. Give up.
|
||||
else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
export function chmodrSync(entryPath, mode) {
|
||||
let children;
|
||||
try {
|
||||
children = fs.readdirSync(entryPath, { withFileTypes: true });
|
||||
for (const child of children) {
|
||||
chmodrKidSync(entryPath, child, mode);
|
||||
}
|
||||
fs.chmodSync(entryPath, dirMode(mode));
|
||||
}
|
||||
catch (error) {
|
||||
const err = error;
|
||||
if (err.code === 'ENOTDIR') {
|
||||
fs.chmodSync(entryPath, mode);
|
||||
}
|
||||
else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user