From eb2bebe7e5b3b1359775ba16709279028bc9b74d Mon Sep 17 00:00:00 2001 From: lens0021 Date: Sun, 23 Mar 2025 20:43:33 +0900 Subject: [PATCH 1/2] feat: add strategy for MediaWiki Skin --- src/factory.ts | 2 + src/strategies/mediawiki-skin.ts | 72 +++++++++++++++++++++++++ src/updaters/php/mediawiki-skin-json.ts | 58 ++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 src/strategies/mediawiki-skin.ts create mode 100644 src/updaters/php/mediawiki-skin-json.ts diff --git a/src/factory.ts b/src/factory.ts index ae6f1bf8d..8a417a83d 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -31,6 +31,7 @@ import {JavaYoshi} from './strategies/java-yoshi'; import {JavaYoshiMonoRepo} from './strategies/java-yoshi-mono-repo'; import {KRMBlueprint} from './strategies/krm-blueprint'; import {Maven} from './strategies/maven'; +import {MediaWikiSkin} from './strategies/mediawiki-skin'; import {Node} from './strategies/node'; import {OCaml} from './strategies/ocaml'; import {PHP} from './strategies/php'; @@ -72,6 +73,7 @@ const releasers: Record = { 'go-yoshi': options => new GoYoshi(options), java: options => new Java(options), maven: options => new Maven(options), + 'mediawiki-skin': options => new MediaWikiSkin(options), 'java-yoshi': options => new JavaYoshi(options), 'java-yoshi-mono-repo': options => new JavaYoshiMonoRepo(options), 'java-backport': options => diff --git a/src/strategies/mediawiki-skin.ts b/src/strategies/mediawiki-skin.ts new file mode 100644 index 000000000..35fe5e11f --- /dev/null +++ b/src/strategies/mediawiki-skin.ts @@ -0,0 +1,72 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generic +import {Changelog} from '../updaters/changelog'; +// MediaWiki Skin Specific. +import {MediaWikiSkinJson} from '../updaters/php/mediawiki-skin-json'; +import {BaseStrategy, BuildUpdatesOptions, BaseStrategyOptions} from './base'; +import {DefaultUpdater} from '../updaters/default'; +import {Update} from '../update'; +import {VersionsMap} from '../version'; + +const CHANGELOG_SECTIONS = [ + {type: 'feat', section: 'Features'}, + {type: 'fix', section: 'Bug Fixes'}, + {type: 'perf', section: 'Performance Improvements'}, + {type: 'revert', section: 'Reverts'}, + {type: 'chore', section: 'Miscellaneous Chores'}, + {type: 'docs', section: 'Documentation', hidden: true}, + {type: 'style', section: 'Styles', hidden: true}, + {type: 'refactor', section: 'Code Refactoring', hidden: true}, + {type: 'test', section: 'Tests', hidden: true}, + {type: 'build', section: 'Build System', hidden: true}, + {type: 'ci', section: 'Continuous Integration', hidden: true}, +]; + +export class MediaWikiSkin extends BaseStrategy { + constructor(options: BaseStrategyOptions) { + options.changelogSections = options.changelogSections ?? CHANGELOG_SECTIONS; + super(options); + } + + protected async buildUpdates( + options: BuildUpdatesOptions + ): Promise { + const updates: Update[] = []; + const version = options.newVersion; + const versionsMap: VersionsMap = new Map(); + + updates.push({ + path: this.addPath(this.changelogPath), + createIfMissing: true, + updater: new Changelog({ + version, + changelogEntry: options.changelogEntry, + }), + }); + + // update composer.json + updates.push({ + path: this.addPath('skin.json'), + createIfMissing: false, + updater: new MediaWikiSkinJson({ + version, + versionsMap, + }), + }); + + return updates; + } +} diff --git a/src/updaters/php/mediawiki-skin-json.ts b/src/updaters/php/mediawiki-skin-json.ts new file mode 100644 index 000000000..36e784d0a --- /dev/null +++ b/src/updaters/php/mediawiki-skin-json.ts @@ -0,0 +1,58 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import {logger as defaultLogger, Logger} from '../../util/logger'; +import {jsonStringify} from '../../util/json-stringify'; +import {DefaultUpdater} from '../default'; + +/** + * Updates a skin.json + */ +export class MediaWikiSkinJson extends DefaultUpdater { + /** + * Given initial file contents, return updated contents. + * @param {string} content The initial content + * @returns {string} The updated content + */ + updateContent(content: string, logger: Logger = defaultLogger): string { + if (!this.version && (!this.versionsMap || this.versionsMap.size === 0)) { + logger.info('no updates necessary'); + return content; + } + const parsed = JSON.parse(content); + if (parsed['version']) { + const fromVersion: string = parsed['version']; + const toVersion = this.version.toString() || '1.0.0'; + parsed['version'] = toVersion; + logger.info(`updating "version" from ${fromVersion} to ${toVersion}`); + } + if (this.versionsMap) { + for (const [key, version] of this.versionsMap.entries()) { + const toVersion = version.toString() || '1.0.0'; + let fromVersion: string | undefined; + if (parsed.replace) { + fromVersion = parsed.replace[key]; + parsed.replace[key] = toVersion; + } + if (parsed[key]) { + fromVersion ??= parsed[key]; + parsed[key] = toVersion; + } + + logger.info(`updating ${key} from ${fromVersion} to ${toVersion}`); + } + } + return jsonStringify(parsed, content); + } +} From e1381ff19fd64a9a370e4dbdbef8618717c032c8 Mon Sep 17 00:00:00 2001 From: lens0021 Date: Wed, 23 Apr 2025 22:04:20 +0900 Subject: [PATCH 2/2] feat: add strategy for MediaWiki Extension --- src/factory.ts | 1 + src/strategies/mediawiki-extension.ts | 72 +++++++++++++++++++ src/strategies/mediawiki-skin.ts | 4 +- ...in-json.ts => mediawiki-extension-json.ts} | 4 +- 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 src/strategies/mediawiki-extension.ts rename src/updaters/php/{mediawiki-skin-json.ts => mediawiki-extension-json.ts} (95%) diff --git a/src/factory.ts b/src/factory.ts index 8a417a83d..d7f7eab38 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -32,6 +32,7 @@ import {JavaYoshiMonoRepo} from './strategies/java-yoshi-mono-repo'; import {KRMBlueprint} from './strategies/krm-blueprint'; import {Maven} from './strategies/maven'; import {MediaWikiSkin} from './strategies/mediawiki-skin'; +import {MediaWikiExtension} from './strategies/mediawiki-extension'; import {Node} from './strategies/node'; import {OCaml} from './strategies/ocaml'; import {PHP} from './strategies/php'; diff --git a/src/strategies/mediawiki-extension.ts b/src/strategies/mediawiki-extension.ts new file mode 100644 index 000000000..e0b5a4f9b --- /dev/null +++ b/src/strategies/mediawiki-extension.ts @@ -0,0 +1,72 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generic +import {Changelog} from '../updaters/changelog'; +// MediaWiki Extension Specific. +import {MediaWikiExtensionJson} from '../updaters/php/mediawiki-extension-json'; +import {BaseStrategy, BuildUpdatesOptions, BaseStrategyOptions} from './base'; +import {DefaultUpdater} from '../updaters/default'; +import {Update} from '../update'; +import {VersionsMap} from '../version'; + +const CHANGELOG_SECTIONS = [ + {type: 'feat', section: 'Features'}, + {type: 'fix', section: 'Bug Fixes'}, + {type: 'perf', section: 'Performance Improvements'}, + {type: 'revert', section: 'Reverts'}, + {type: 'chore', section: 'Miscellaneous Chores'}, + {type: 'docs', section: 'Documentation', hidden: true}, + {type: 'style', section: 'Styles', hidden: true}, + {type: 'refactor', section: 'Code Refactoring', hidden: true}, + {type: 'test', section: 'Tests', hidden: true}, + {type: 'build', section: 'Build System', hidden: true}, + {type: 'ci', section: 'Continuous Integration', hidden: true}, +]; + +export class MediaWikiExtension extends BaseStrategy { + constructor(options: BaseStrategyOptions) { + options.changelogSections = options.changelogSections ?? CHANGELOG_SECTIONS; + super(options); + } + + protected async buildUpdates( + options: BuildUpdatesOptions + ): Promise { + const updates: Update[] = []; + const version = options.newVersion; + const versionsMap: VersionsMap = new Map(); + + updates.push({ + path: this.addPath(this.changelogPath), + createIfMissing: true, + updater: new Changelog({ + version, + changelogEntry: options.changelogEntry, + }), + }); + + // update composer.json + updates.push({ + path: this.addPath('extension.json'), + createIfMissing: false, + updater: new MediaWikiExtensionJson({ + version, + versionsMap, + }), + }); + + return updates; + } +} diff --git a/src/strategies/mediawiki-skin.ts b/src/strategies/mediawiki-skin.ts index 35fe5e11f..18797fba9 100644 --- a/src/strategies/mediawiki-skin.ts +++ b/src/strategies/mediawiki-skin.ts @@ -15,7 +15,7 @@ // Generic import {Changelog} from '../updaters/changelog'; // MediaWiki Skin Specific. -import {MediaWikiSkinJson} from '../updaters/php/mediawiki-skin-json'; +import {MediaWikiExtensionJson} from '../updaters/php/mediawiki-extension-json'; import {BaseStrategy, BuildUpdatesOptions, BaseStrategyOptions} from './base'; import {DefaultUpdater} from '../updaters/default'; import {Update} from '../update'; @@ -61,7 +61,7 @@ export class MediaWikiSkin extends BaseStrategy { updates.push({ path: this.addPath('skin.json'), createIfMissing: false, - updater: new MediaWikiSkinJson({ + updater: new MediaWikiExtensionJson({ version, versionsMap, }), diff --git a/src/updaters/php/mediawiki-skin-json.ts b/src/updaters/php/mediawiki-extension-json.ts similarity index 95% rename from src/updaters/php/mediawiki-skin-json.ts rename to src/updaters/php/mediawiki-extension-json.ts index 36e784d0a..21fdef772 100644 --- a/src/updaters/php/mediawiki-skin-json.ts +++ b/src/updaters/php/mediawiki-extension-json.ts @@ -17,9 +17,9 @@ import {jsonStringify} from '../../util/json-stringify'; import {DefaultUpdater} from '../default'; /** - * Updates a skin.json + * Updates a extension.json */ -export class MediaWikiSkinJson extends DefaultUpdater { +export class MediaWikiExtensionJson extends DefaultUpdater { /** * Given initial file contents, return updated contents. * @param {string} content The initial content