-
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use script auto update create-farm-rs template deps (#1454)
* chore:update template version * chore: update code * chore: update code * chore: bump version
- Loading branch information
Showing
25 changed files
with
117 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-farm": patch | ||
--- | ||
|
||
update template deps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
|
||
const templatesDir = path.resolve('crates/create-farm-rs/templates'); | ||
|
||
const packageCorePath = path.resolve('packages/core/package.json'); | ||
const packageCliPath = path.resolve('packages/cli/package.json'); | ||
const packageCoreJson = JSON.parse(fs.readFileSync(packageCorePath, 'utf8')); | ||
const packageCliJson = JSON.parse(fs.readFileSync(packageCliPath, 'utf8')); | ||
const dependenciesToUpdate = { | ||
"@farmfe/core": `^${packageCoreJson.version}`, | ||
"@farmfe/cli": `^${packageCliJson.version}` | ||
}; | ||
|
||
function updatePackageJsonDependencies(dir) { | ||
fs.readdir(dir, (err, files) => { | ||
if (err) { | ||
return console.error(`cannot read directory ${dir}: ${err.message}`); | ||
} | ||
|
||
files.forEach(file => { | ||
const fullPath = path.join(dir, file); | ||
fs.stat(fullPath, (err, stats) => { | ||
if (err) { | ||
return console.error(`cannot get stats of file ${fullPath}: ${err.message}`); | ||
} | ||
|
||
if (stats.isDirectory()) { | ||
updatePackageJsonDependencies(fullPath); | ||
} else if (file === 'package.json') { | ||
fs.readFile(fullPath, 'utf8', (err, data) => { | ||
if (err) { | ||
return console.error(`cannot read file ${fullPath}: ${err.message}`); | ||
} | ||
|
||
let packageJson; | ||
try { | ||
packageJson = JSON.parse(data); | ||
} catch (err) { | ||
return console.error(`resolve JSON file ${fullPath} error: ${err.message}`); | ||
} | ||
|
||
Object.keys(dependenciesToUpdate).forEach(dep => { | ||
if (packageJson.dependencies && packageJson.dependencies[dep]) { | ||
packageJson.dependencies[dep] = dependenciesToUpdate[dep]; | ||
} | ||
if (packageJson.devDependencies && packageJson.devDependencies[dep]) { | ||
packageJson.devDependencies[dep] = dependenciesToUpdate[dep]; | ||
} | ||
}); | ||
|
||
fs.writeFile(fullPath, JSON.stringify(packageJson, null, 2), 'utf8', err => { | ||
if (err) { | ||
return console.error(`cannot write ${fullPath}: ${err.message}`); | ||
} | ||
console.log(`successfully updated file ${fullPath}`); | ||
}); | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
updatePackageJsonDependencies(templatesDir); |