-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: plugin pack command for 2 #916
base: main
Are you sure you want to change the base?
Conversation
9c9a9f2
to
a8e6a7d
Compare
0882ade
to
d56df1f
Compare
41f2bc3
to
5ec52a6
Compare
c2d994a
to
32cafad
Compare
2eb54d1
to
7529e19
Compare
62f1587
to
3312a0f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"node-rsa": "^1.1.1", | ||
"stream-buffers": "^3.0.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stream-buffers
は Node.js 標準の Utility Consumers に置き換えが案内されていたので置き換えた。
https://www.npmjs.com/package/stream-buffers
@@ -112,13 +110,9 @@ | |||
"chokidar": "^4.0.1", | |||
"csv-parse": "^4.16.3", | |||
"csv-stringify": "5.6.5", | |||
"debug": "^4.3.7", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debug
はcli-kintoneのlogger.debug|trace
に置き換えた。
"https-proxy-agent": "^7.0.5", | ||
"iconv-lite": "^0.6.3", | ||
"mkdirp": "^3.0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fs.promises.mkdir(data, {recursive: true})
に置き換え
@@ -112,13 +110,9 @@ | |||
"chokidar": "^4.0.1", | |||
"csv-parse": "^4.16.3", | |||
"csv-stringify": "5.6.5", | |||
"debug": "^4.3.7", | |||
"execa": "^9.4.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用していたテストを消した。
export { PublicKey } from "./public-key"; | ||
export type { PublicKeyInterface } from "./public-key"; | ||
export { PrivateKey } from "./private-key"; | ||
export type { PrivateKeyInterface } from "./private-key"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PublicKey と PrivateKey は変わることは当面なさそうだしInterfaceを切らなくても良さそう。
(アルゴリズムなどが変わるタイミングでIFを切れば良さそう)
|
||
const debug = _debug("packer"); | ||
|
||
const packer = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packerの処理はPluginZip.build()
に移動した。
import packer from "./index"; | ||
import { createContentsZip } from "./create-contents-zip"; | ||
|
||
export const packPluginFromManifest = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
こちらもPluginZip.build()
に集約
@@ -0,0 +1,29 @@ | |||
--- | |||
sidebar_position: 1400 | |||
draft: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
draft: true
なのでローカルビルドでした表示されない
* @param stability "experimental" or "deprecated" | ||
* @param message additional information | ||
*/ | ||
export const setStability = <T = {}, U = {}>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/kintone/cli-kintone/pull/915/files#r1815855917 の対応
setStability(cmd, stability, msg)
関数を追加した。
ヘルプメッセージにStabilityが表示され、実行時に警告が出るようになる。
どこかのflagsにstabilityの情報を集約して、それに連動して表示が変わるようにしたかったが、yargsの仕組み上難しそうだった。
コマンドの生成を全てラップするヘルパー関数を置けば実現できるが、既存のレコード系のコマンドにも影響が出るので今回は個別のコマンドをラップする方式にした。
src/plugin/packer/cli.ts
Outdated
const cli = (pluginDir: string, options_?: Options) => { | ||
// TODO: Reduce statements in this func | ||
// eslint-disable-next-line max-statements | ||
export const run = async (pluginDir: string, options_?: Options) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
既存のレコード系のコマンドと合わせて関数名を run
にした。
ref. https://github.com/kintone/cli-kintone/pull/915/files#r1815859115
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pack.tsにしました!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tasshi-me
いくつかコメントしました!
定義がわかりやすくて処理が追いやすかったです!
* Validate Manifest | ||
* @param driver If set, also validate file existence and file size. | ||
*/ | ||
validate(driver?: DriverInterface): Promise<ValidationResult>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shabaraba
これも悩んでいた部分ですね!
ManifestがDriverに依存しなくても成立する概念なので、Driverをプロパティに含めていませんでした!
直近は、
・マニフェストを読み込む場所
・マニフェストからファイルの実在を検証する場所
は一緒なので、プロパティに入れてしまっても問題ないと思います。
一方で、今後Driverを使い分けるケースとしては、以下のようなケースを想定しています。
・ZIPファイルやHTTPをソースとして受け付けてローカルにプラグインを生成するパターン
・Webエディタのようなオンメモリ→ZIPファイルを生成するパターン
・Web版plugin-packerのように入力ZIPファイルからプラグインZIPファイルを生成するパターン
(ZipFileDriverは1つのZIPファイル内のファイル構造を表現しているので、入力・出力で2つのZIPファイルを扱う場合はDriverは2つ必要になります)
自分の考えなのですが、
・ManifestInterface.validate()
はManifestの形式的な妥当性だけを検証する
・Driverを使ったファイルの実在確認はContents.validate()
を作成する
・ContentsはDriverに依存する(コンストラクタインジェクションする)
とすると見通しが良くなりそうです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(なんだかんだ言ってメインの利用ケースはLocalFSなので、デフォルト引数をLocalFSにしておいても良さそう)
src/plugin/core/contents/zip.ts
Outdated
/** | ||
* Create a zipped contents using stream. Can be faster than createContentsZip above. | ||
*/ | ||
export const _createContentsZipStream = async ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Streamを使ったほうが速度的にもメモリ使用量的にも良さそうなんですけど、まだあまりちゃんと検証していないので置き換えずに置いているような状態です!
一旦はExportしない状態にしました!
/** | ||
* Create plugin.zip from contents.zip | ||
*/ | ||
public static async buildFromContentsZip( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build
/generate
/create
が散らばっているんですが、
一旦全てgenerate
/generateFrom
に統一しました。
以下の方針で用語調整しました。
build
:複数の何かを組み合わせて何かにする系
generate
: 新規に何かを生成する系(privateKeyなど)
createは上記2つに比べて、汎用で、かつCreativeなニュアンスも出そうなので、今回はなくしました
この辺りの単語選びはライブラリごとでも違うので悩ましい、、、
(fs.createReadableStream, crypto.generateKey など)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zip.ts
の切り出しも行いました!
src/plugin/packer/cli.ts
Outdated
const cli = (pluginDir: string, options_?: Options) => { | ||
// TODO: Reduce statements in this func | ||
// eslint-disable-next-line max-statements | ||
export const run = async (pluginDir: string, options_?: Options) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/plugin/packer/cli.ts
Outdated
// 5. generate new ppk if not specified | ||
const ppkFile = options.ppk; | ||
let privateKey: PrivateKey; | ||
if (ppkFile) { | ||
logger.debug(`loading an existing key: ${ppkFile}`); | ||
const ppk = await fs.readFile(ppkFile, "utf8"); | ||
privateKey = PrivateKey.importKey(ppk); | ||
} else { | ||
logger.debug("generating a new key"); | ||
privateKey = PrivateKey.generateKey(); | ||
} | ||
|
||
/** | ||
* Load JSON file without caching | ||
*/ | ||
const loadJson = (jsonPath: string) => { | ||
const content = fs.readFileSync(jsonPath, "utf8"); | ||
return JSON.parse(content); | ||
}; | ||
const id = privateKey.uuid(); | ||
logger.debug(`id: ${id}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あざます!
処理順番を調整しました。
- 入力のバリデーション
- マニフェストの読み込み
- マニフェストの検証
- 出力ディレクトリの用意
- 秘密鍵の読み込み、指定されていない場合は生成
- プラグインのパッケージング
- watchモードの起動(指定されている場合)
- プラグインの書き出し
39db43e
to
95110a4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
レビュー対応
Why
Support plugin manifest v2.
What
plugin info
commandHow to test
Manual test example:
Checklist
pnpm lint
andpnpm test
on the root directory.