Shion のもくログ(旧: Shion の技術メモ)

使った技術のメモや、うまくいかなかった事とかを綴ります

PR

2022/04/02 ~ 2022/04/08 のもくもく日記

もくもく 前回までは

(該当ブログが見当たりません) をご覧ください。

今回の目標

  • レシピの整備

途中経過

その1

tsconfig は見たことあるけど、 恥ずかしながら jsconfig もあるとは知らんかったw

その2

昨年度、何を掲げたか忘れてしまったけど、とりあえず今年度はこんなことを頑張りたいかもw

  • iOS と触れる時間を増やす
  • 実装レシピ、メモ周りの整備を進める

……自作ブログ、いつリニューアル出来るんやろ。自分でも不思議w

その3

Yeoman のGenerator クラスのコントリビュートポイント?はこれ見て手入力していく感じがいいかも 👀

override 的なあれできれば良かったのだけど……

https://yeoman.github.io/generator/Generator.html

Yeoman のGenerator 内のメソッドががが……って言っていたの、ここに理由書いてあるやん 👀

Every method added to the prototype is run once the generator is called–and usually in sequence.

https://yeoman.io/authoring/

Yeoman の自作Generator はとりあえずこんな仕上がりに

あとはこの辺りをやりたいかも

  • generator-vscode のような複数テンプレートの取り扱い
  • ラッピング
  • ラッピングの配布

……てかテンプレートそのものも整備せんとw

https://github.com/tshion/generator-mkstarter

やらないことを書きそびれたorz

  • lint やformatter の整備  → 自分専用?な感じの用途なので、今回は軽めに書けるようにしたいかも
  • TypeScript 化  → 試したけどさっぱり分からんかった

Yeoman の自作Generator で実際にファイルコピーしているところ、オプションの process でコピー内容の操作、processDestinationPath で出力先パスを変えられたw

async writing() {
    const appName = this._answers.appName;
    const packages = this._answers.packageId.split('.');
    const replaceExts = [`.gradle`, `.java`, `.kt`, `.pro`, `.xml`];

    const distPath = this.destinationPath(appName);
    this.fs.copy(this.templatePath(''), distPath, {
        globOptions: { dot: true },
        process: (contents, targetPath) => {
            const targetExt = path.extname(targetPath);
            if (!replaceExts.some((ext) => targetExt === ext)) {
                return contents;
            }

            return contents
                .toString()
                .replace(/com\.github\.mkstarter/g, `${this._answers.packageId}`)
                .replace(/mkstarter/g, `${appName}`);
        },
        processDestinationPath: (targetPath) => {
            const keyword = `java`;
            if (!targetPath.includes(keyword)) {
                return targetPath;
            }

            const targetDirName = path.dirname(targetPath);
            const targetFileName = path.basename(targetPath);
            return path.join(
                targetDirName.substring(0, targetDirName.indexOf(keyword)),
                keyword,
                ...packages,
                targetFileName
            );
        },
    });
}

選択肢を出すのは、prompt でtype 'list' なものを設定すれば行けたw

https://github.com/microsoft/vscode-generator-code/blob/main/generators/app/index.js#L115-L121

その4

chalk 5.x だとesm だからcommonjs じゃ使えない……という文脈を見て、やっぱJavaScript 何も分からんとなっている今日この頃w

https://stackoverflow.com/questions/70309135/chalk-error-err-require-esm-require-of-es-module/70425265#70425265

その5

予算の都合で、MacBook なキーボード配置のものを買えていないのだけど、最近iOS? の配置に判定されることが多くて、実装しにくいorz

ちなみにこんな感じw

  • : <- Shift + ;
  • " <- Shift + :
  • ( <- Shift + 9
  • ) <- Shift + 0

今回の進捗

※関連SNS
PR