Skip to content

Commit

Permalink
feat!: 更改為從原始檔內取得版本資訊
Browse files Browse the repository at this point in the history
  • Loading branch information
bluelovers committed Jul 25, 2022
1 parent 71a7ac7 commit f0b1b2c
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 20 deletions.
62 changes: 62 additions & 0 deletions lib/build/get-source-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { readFile } from 'fs-extra';
import { __file_plugin_dev_meta_xml, __file_plugin_src_meta_xml } from '../const';
import { PluginXml } from '../util/xml/plugin-xml';
import { _getVersionDownloadByVersion } from '../util/version-map';
import { readFileSync } from 'fs';

function _handleInput(useSrc: boolean)
{
useSrc = !!useSrc;

const file = useSrc ? __file_plugin_src_meta_xml : __file_plugin_dev_meta_xml;

return {
useSrc,
file,
}
}

export function _getSourceInfoCore(input: {
useSrc: boolean,
file: string,
content: Buffer | string,
})
{
const pluginMeta = new PluginXml(input.content);

return {
useSrc: !!input.useSrc,
file: input.file,
pluginMeta,
getDownloadURL()
{
return _getVersionDownloadByVersion(pluginMeta.version)
},
}
}

export function getSourceInfoSync(useSrc?: boolean)
{
const input = _handleInput(useSrc);

const content = readFileSync(input.file);

return _getSourceInfoCore({
...input,
content,
})
}

export function getSourceInfo(useSrc?: boolean)
{
const input = _handleInput(useSrc);

return readFile(input.file)
.then(content =>
{
return _getSourceInfoCore({
...input,
content,
})
})
}
10 changes: 10 additions & 0 deletions lib/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,13 @@ export const enum EnumVersion
{
latest = 'latest',
}

/**
* plugin-dev-raw/zh/META-INF/plugin.xml
*/
export const __file_plugin_dev_meta_xml = join(__plugin_dev_raw_dir, 'zh', 'META-INF/plugin.xml');

/**
* original-plugin-raw/zh/META-INF/plugin.xml
*/
export const __file_plugin_src_meta_xml = join(__plugin_downloaded_dir_unzip, 'zh', 'META-INF/plugin.xml');
9 changes: 5 additions & 4 deletions scripts/ci-postpublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { outputFile, outputJSON, readJSON } from 'fs-extra';
import { __file_publish_tags_json } from '../lib/const';
import { array_unique_overwrite } from 'array-hyper-unique';
import { LF } from 'crlf-normalize';
import { getSourceInfoSync } from '../lib/build/get-source-info';

export default Bluebird.resolve((process.env as any).GITHUB_SHA as string)
.then((from) =>
Expand Down Expand Up @@ -127,15 +128,15 @@ export default Bluebird.resolve((process.env as any).GITHUB_SHA as string)
type: 'independent',
});

const { __plugin_zh_cn_version } = await import('../lib/const/link-of-zh-cn');
const __pluginVersion = getSourceInfoSync().pluginMeta.version;

await readJSON(__file_publish_tags_json)
.catch(e => [])
.then((tags: string[]) =>
{
if (!tags.includes(__plugin_zh_cn_version))
if (!tags.includes(__pluginVersion))
{
tags.push(__plugin_zh_cn_version);
tags.push(__pluginVersion);
}
return array_unique_overwrite(tags)
})
Expand All @@ -151,7 +152,7 @@ export default Bluebird.resolve((process.env as any).GITHUB_SHA as string)
await lazyCommitFiles([
'./CHANGELOG.md',
'./lib/const/publish-tags.json',
], `build(changelog): update CHANGELOG ( ${__plugin_zh_cn_version} )`);
], `build(changelog): update CHANGELOG ( ${__pluginVersion} )`);
}
else
{
Expand Down
13 changes: 7 additions & 6 deletions scripts/git/build-commit.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { lazyCommitFiles } from '../../lib/git/commit';
import { _lazyImportWithDelay } from '../../lib/util/import';
import Bluebird from 'bluebird';
import { getSourceInfoSync } from '../../lib/build/get-source-info';

export default Bluebird.mapSeries([
'./commit-version-map',
'./commit-link-of-zh-cn',
] as const, lazyImport)
.then(async () =>
{
const { __plugin_zh_cn_version } = await import('../../lib/const/link-of-zh-cn');
const __pluginVersion = getSourceInfoSync().pluginMeta.version;

await lazyCommitFiles([
'./original-plugin',
'./original-plugin-raw',
], `build(original): update original source ( ${__plugin_zh_cn_version} )`, {
], `build(original): update original source ( ${__pluginVersion} )`, {
addFlags: ['--all'],
}).catch(() => void 0);

Expand All @@ -25,27 +26,27 @@ export default Bluebird.mapSeries([

await lazyCommitFiles([
'./lib/const/link-of-zh-cn.ts',
], `build(cache): update version info cache ( ${__plugin_zh_cn_version} )`, {
], `build(cache): update version info cache ( ${__pluginVersion} )`, {
addFlags: ['--all'],
}).catch(() => void 0);

await lazyCommitFiles([
'./test/__snapshots__',
], `build(test): update snapshots ( ${__plugin_zh_cn_version} )`, {
], `build(test): update snapshots ( ${__pluginVersion} )`, {
addFlags: ['--all'],
}).catch(() => void 0);

await lazyCommitFiles([
'./plugin-dev-raw',
], `build(release): update dev build files ( ${__plugin_zh_cn_version} )`, {
], `build(release): update dev build files ( ${__pluginVersion} )`, {
addFlags: ['--all'],
}).catch(() => void 0);

const list = [
'./plugin-dev-out',
] as const;

return lazyCommitFiles(list, `build(release): update build ( ${__plugin_zh_cn_version} )`, {
return lazyCommitFiles(list, `build(release): update build ( ${__pluginVersion} )`, {
addFlags: ['--all'],
})
})
Expand Down
7 changes: 3 additions & 4 deletions scripts/update-git-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { opts } from '../lib/git/_config';
import { getGitLogs } from '../lib/git/git-logs';
import { join } from 'upath2';
import { updatePluginTag, updateRepoTag } from '../lib/git/git-tag';
import { getSourceInfoSync } from '../lib/build/get-source-info';

export default Bluebird.resolve()
.then(() =>
Expand All @@ -15,7 +16,7 @@ export default Bluebird.resolve()
})
.then(async (logs) =>
{
const { __plugin_zh_cn_series, __plugin_zh_cn_version } = await import('../lib/const/link-of-zh-cn');
const __pluginVersion = getSourceInfoSync().pluginMeta.version;

const commit = logs[0];

Expand All @@ -30,11 +31,9 @@ export default Bluebird.resolve()
{
console.info(`更新 git tag`);

const { name, version } = await import(join(__root, 'package.json'));

await updateRepoTag();

return updatePluginTag(__plugin_zh_cn_version)
return updatePluginTag(__pluginVersion)
}

console.warn(`略過本次 git tag 更新`)
Expand Down
9 changes: 3 additions & 6 deletions scripts/update-meta.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { join } from 'upath2';
import { __plugin_dev_raw_dir } from '../lib/const';
import { __file_plugin_dev_meta_xml } from '../lib/const';
import { outputFile, readFile } from 'fs-extra';
import Bluebird from 'bluebird';
import { updateMeta } from '../lib/meta';

const fullpath_new = join(__plugin_dev_raw_dir, 'zh', 'META-INF/plugin.xml');

export default Bluebird.resolve(readFile(fullpath_new))
export default Bluebird.resolve(readFile(__file_plugin_dev_meta_xml))
.then(buf => updateMeta(buf.toString()))
.then(content_new => outputFile(fullpath_new, content_new))
.then(content_new => outputFile(__file_plugin_dev_meta_xml, content_new))
;

0 comments on commit f0b1b2c

Please sign in to comment.