Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
lxyl-vue
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李苏
lxyl-vue
Commits
e8cdb4a4
Commit
e8cdb4a4
authored
Aug 16, 2024
by
李苏
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
服务器编译脚本
parent
57197373
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
0 deletions
+72
-0
changePath.js
changePath.js
+57
-0
revertPath.js
revertPath.js
+15
-0
No files found.
changePath.js
0 → 100644
View file @
e8cdb4a4
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
// JSON文件路径
const
filePath
=
path
.
join
(
__dirname
,
'package.json'
);
const
destFile
=
path
.
join
(
__dirname
,
'package_bac.json'
);
// 复制文件的函数
function
copyFile
(
src
,
dest
,
callback
)
{
const
readStream
=
fs
.
createReadStream
(
src
);
const
writeStream
=
fs
.
createWriteStream
(
dest
);
// 监听错误事件
readStream
.
on
(
'error'
,
(
err
)
=>
{
fs
.
unlink
(
dest
,
()
=>
{
if
(
callback
)
callback
(
err
);
});
});
// 监听完成事件
writeStream
.
on
(
'finish'
,
callback
);
// 管道读取流到写入流
readStream
.
pipe
(
writeStream
);
}
copyFile
(
filePath
,
destFile
,
(
err
)
=>
{
if
(
err
)
{
return
console
.
error
(
err
);
}
console
.
log
(
'文件复制并重命名成功'
);
console
.
log
(
'开始调整json'
);
fs
.
readFile
(
filePath
,
'utf8'
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
err
);
return
;
}
try
{
// 将字符串转换为JSON对象
const
jsonData
=
JSON
.
parse
(
data
);
jsonData
.
dependencies
.
common
=
"file:../frontpackage"
fs
.
writeFile
(
filePath
,
JSON
.
stringify
(
jsonData
,
null
,
2
)
,
'utf8'
,
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
err
);
return
;
}
console
.
log
(
'package.json文件已修改'
);
});
}
catch
(
e
)
{
console
.
error
(
'解析JSON时出错:'
,
e
);
}
});
});
revertPath.js
0 → 100644
View file @
e8cdb4a4
const
fs
=
require
(
'fs'
);
// 源文件路径
const
oldPath
=
'./package_bac.json'
;
// 新文件路径
const
newPath
=
'./package.json'
;
fs
.
unlink
(
newPath
,
(
err
)
=>
{
if
(
err
)
throw
err
;
console
.
log
(
'文件已被删除'
);
fs
.
rename
(
oldPath
,
newPath
,
(
err
)
=>
{
if
(
err
)
throw
err
;
console
.
log
(
'文件重命名成功'
);
});
});
// 使用fs.rename()重命名文件
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment