Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc98ff10

Browse files
GeeWizWowantongolub
authored andcommitted
feat: added declarative config support
1 parent4b20da7 commitc98ff10

File tree

4 files changed

+78
-48
lines changed

4 files changed

+78
-48
lines changed

‎bin/cli.js‎

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -35,47 +35,6 @@ const cli = meow(
3535
constargvStart=process.argv.includes("--") ?process.argv.indexOf("--")+1 :2;
3636
returnprocess.argv.slice(argvStart);
3737
},
38-
flags:{
39-
sequentialInit:{
40-
type:"boolean",
41-
},
42-
sequentialPrepare:{
43-
type:"boolean",
44-
default:true,
45-
},
46-
firstParent:{
47-
type:"boolean",
48-
},
49-
debug:{
50-
type:"boolean",
51-
},
52-
"deps.bump":{
53-
type:"string",
54-
default:"override",
55-
},
56-
"deps.release":{
57-
type:"string",
58-
default:"patch",
59-
},
60-
"deps.prefix":{
61-
type:"string",
62-
default:"",
63-
},
64-
ignorePrivate:{
65-
type:"boolean",
66-
default:true,
67-
},
68-
ignorePackages:{
69-
type:"string",
70-
},
71-
tagFormat:{
72-
type:"string",
73-
default:"${name}@${version}",
74-
},
75-
dryRun:{
76-
type:"boolean",
77-
},
78-
},
7938
}
8039
);
8140

‎bin/runner.js‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import{createRequire}from"module";
22

3-
exportdefaultasync(flags)=>{
3+
exportdefaultasync(cliFlags)=>{
44
constrequire=createRequire(import.meta.url);
55

6-
if(flags.debug){
7-
require("debug").enable("msr:*");
8-
}
9-
106
// Imports.
117
constgetPackagePaths=(awaitimport("../lib/getPackagePaths.js")).default;
8+
constgetConfigMultiSemrel=(awaitimport("../lib/getConfigMultiSemrel.js")).default;
129
constmultiSemanticRelease=(awaitimport("../lib/multiSemanticRelease.js")).default;
1310
constmultisemrelPkgJson=require("../package.json");
1411
constsemrelPkgJson=require("semantic-release/package.json");
@@ -18,6 +15,12 @@ export default async (flags) => {
1815

1916
// Catch errors.
2017
try{
18+
constflags=awaitgetConfigMultiSemrel(cwd,cliFlags);
19+
20+
if(flags.debug){
21+
require("debug").enable("msr:*");
22+
}
23+
2124
console.log(`multi-semantic-release version:${multisemrelPkgJson.version}`);
2225
console.log(`semantic-release version:${semrelPkgJson.version}`);
2326
console.log(`flags:${JSON.stringify(flags,null,2)}`);
@@ -34,7 +37,7 @@ export default async (flags) => {
3437
},
3538
(error)=>{
3639
// Log out errors.
37-
console.error(`[multi-semantic-release111]:`,error);
40+
console.error(`[multi-semantic-release]:`,error);
3841
process.exit(1);
3942
}
4043
);

‎lib/getConfigMultiSemrel.js‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import{cosmiconfig}from"cosmiconfig";
2+
import{defaultasresolveFrom}from"resolve-from";
3+
import{pickBy,isNil,castArray}from"lodash-es";
4+
5+
constCONFIG_NAME="multi-release";
6+
constCONFIG_FILES=[
7+
"package.json",
8+
`.${CONFIG_NAME}rc`,
9+
`.${CONFIG_NAME}rc.json`,
10+
`.${CONFIG_NAME}rc.yaml`,
11+
`.${CONFIG_NAME}rc.yml`,
12+
`.${CONFIG_NAME}rc.js`,
13+
`.${CONFIG_NAME}rc.cjs`,
14+
`${CONFIG_NAME}.config.js`,
15+
`${CONFIG_NAME}.config.cjs`,
16+
];
17+
18+
/**
19+
* Get the multi semantic release configuration options for a given directory.
20+
*
21+
*@param {string} cwd The directory to search.
22+
*@param {Object} cliOptions cli supplied options.
23+
*@returns {Object} The found configuration option
24+
*
25+
*@internal
26+
*/
27+
exportdefaultasyncfunctiongetConfig(cwd,cliOptions){
28+
const{ config}=(awaitcosmiconfig(CONFIG_NAME,{searchPlaces:CONFIG_FILES}).search(cwd))||{};
29+
const{extends:extendPaths, ...rest}={ ...config, ...cliOptions};
30+
31+
letoptions=rest;
32+
33+
if(extendPaths){
34+
// If `extends` is defined, load and merge each shareable config with `options`
35+
options={
36+
...castArray(extendPaths).reduce((result,extendPath)=>{
37+
constextendsOptions=require(resolveFrom.silent(__dirname,extendPath)||
38+
resolveFrom(cwd,extendPath));
39+
return{ ...result, ...extendsOptions};
40+
},{}),
41+
...options,
42+
};
43+
}
44+
45+
// Set default options values if not defined yet
46+
options={
47+
sequentialInit:false,
48+
sequentialPrepare:true,
49+
firstParent:false,
50+
debug:false,
51+
ignorePrivate:true,
52+
ignorePackages:"",
53+
tagFormat:"${name}@${version}",
54+
dryRun:false,
55+
// Remove `null` and `undefined` options so they can be replaced with default ones
56+
...pickBy(options,(option)=>!isNil(option)),
57+
// Treat nested objects differently as otherwise we'll loose undefined keys
58+
deps:{
59+
bump:"override",
60+
release:"patch",
61+
prefix:"",
62+
...pickBy(options.deps,(option)=>!isNil(option)),
63+
},
64+
};
65+
66+
returnoptions;
67+
}

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,15 @@
6868
"lodash-es":"^4.17.21",
6969
"meow":"^10.1.2",
7070
"promise-events":"^0.2.4",
71+
"resolve-from":"^5.0.0",
7172
"semantic-release":"^19.0.2",
7273
"semver":"^7.3.7",
7374
"signale":"^1.4.0",
7475
"stream-buffers":"^3.0.2"
7576
},
7677
"devDependencies": {
77-
"@jest/globals":"^28.1.0",
7878
"@commitlint/config-conventional":"^17.0.0",
79+
"@jest/globals":"^28.1.0",
7980
"@semantic-release/changelog":"^6.0.1",
8081
"@semantic-release/git":"^10.0.1",
8182
"@semantic-release/github":"^8.0.4",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp