endef 1.0.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/bin/main.js ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ // ECMAScript module loader
3
+ _import = require('esm')(module /*, options*/)
4
+
5
+ const { run: start } = _import('../src/run')
6
+
7
+ start(process.argv)
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "endef",
3
+ "version": "1.0.0",
4
+ "description": "Encrypt or Decrypt Files Test",
5
+ "bin": {
6
+ "endef": "bin/main.js"
7
+ },
8
+ "scripts": {
9
+ "prettier": "prettier --write \"**/*.{js,jsx,ts,json,vue,css,less,scss,md,html}\""
10
+ },
11
+ "files": [
12
+ "bin",
13
+ "src"
14
+ ],
15
+ "license": "MIT",
16
+ "dependencies": {
17
+ "esm": "^3.2.25"
18
+ },
19
+ "devDependencies": {
20
+ "prettier": "^2.8.8"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public",
24
+ "registry": "https://registry.npmjs.org/"
25
+ }
26
+ }
package/src/de.js ADDED
@@ -0,0 +1,13 @@
1
+ import { spawn } from 'child_process'
2
+ import { resolve } from 'path'
3
+
4
+ export const deSrc = resolve(__dirname)
5
+ export const curDir = process.cwd()
6
+
7
+ export default function () {
8
+ spawn(`bash`, [`${deSrc}\/de.sh ${curDir}`], {
9
+ cwd: curDir,
10
+ stdio: 'inherit',
11
+ shell: process.platform === 'win32'
12
+ })
13
+ }
package/src/de.sh ADDED
@@ -0,0 +1,34 @@
1
+ #!/bin/bash
2
+
3
+ DIR=$1
4
+
5
+ remove_suffix() {
6
+ local directory=$1
7
+
8
+ # 遍历目录下的文件和子目录
9
+ for item in "$directory"/*; do
10
+ if [ -f "$item" ]; then # 文件
11
+ # 获取文件名和目录路径
12
+ filename=$(basename "$item")
13
+ dir=$(dirname "$item")
14
+
15
+ # 移除后缀
16
+ new_filename=${filename%%._$_foobar*}
17
+
18
+ # 构建新的文件路径
19
+ new_file="$dir/$new_filename"
20
+
21
+ # 重命名文件
22
+ mv "$item" "$new_file"
23
+
24
+ echo "File renamed: $new_file"
25
+ elif [ -d "$item" ]; then # 子目录
26
+ # 递归处理子目录
27
+ remove_suffix "$item"
28
+ fi
29
+ done
30
+ }
31
+
32
+ directory="$DIR" # 替换为你的目录路径
33
+
34
+ remove_suffix "$directory"
package/src/en.js ADDED
@@ -0,0 +1,60 @@
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+
4
+ export default function processFiles(directory) {
5
+ fs.readdir(directory, (err, files) => {
6
+ if (err) {
7
+ console.error('Error reading directory:', err)
8
+ return
9
+ }
10
+
11
+ files.forEach(file => {
12
+ const filePath = path.join(directory, file)
13
+
14
+ fs.stat(filePath, (err, stats) => {
15
+ if (err) {
16
+ console.error('Error stating file:', err)
17
+ return
18
+ }
19
+
20
+ if (stats.isDirectory()) {
21
+ processFiles(filePath) // 递归处理子目录
22
+ } else {
23
+ // 处理文件
24
+ fs.readFile(filePath, 'utf8', (err, data) => {
25
+ if (err) {
26
+ console.error('Error reading file:', err)
27
+ return
28
+ }
29
+
30
+ const tempFilePath = filePath + '._$_foobar'
31
+
32
+ // 写入临时文件
33
+ fs.writeFile(tempFilePath, data, 'utf8', err => {
34
+ if (err) {
35
+ console.error('Error writing temp file:', err)
36
+ return
37
+ }
38
+
39
+ console.log('Temp file written:', tempFilePath)
40
+
41
+ // 删除原文件
42
+ fs.unlink(filePath, err => {
43
+ if (err) {
44
+ console.error('Error deleting temp file:', err)
45
+ } else {
46
+ // console.log('Temp file deleted:', filePath);
47
+ /*fs.rename(tempFilePath, filePath, (err) => {
48
+ if(!err) {
49
+ console.log(newName + ' 已重命名!')
50
+ }
51
+ })*/
52
+ }
53
+ })
54
+ })
55
+ })
56
+ }
57
+ })
58
+ })
59
+ })
60
+ }
package/src/run.js ADDED
@@ -0,0 +1,12 @@
1
+ import enF from './en'
2
+ import deF from './de'
3
+
4
+ export async function run(args) {
5
+ if (args[2] === 'en') {
6
+ enF(process.cwd())
7
+ }
8
+
9
+ if (args[2] === 'de') {
10
+ deF()
11
+ }
12
+ }