textlint-rule / textlint-rule-preset-google

[WIP] Google Developer Documentation Style Guide for textlint.
https://developers.google.com/style/
MIT License
14 stars 3 forks source link

refactor(packages): Move to @textlint-rule/* #17

Closed azu closed 7 years ago

azu commented 7 years ago
// MIT © 2017 azu
"use strict";
const fs = require("fs");
const path = require("path");
const currentPackage = process
    .cwd()
    .split("/")
    .pop();
const shortName = currentPackage.replace("textlint-rule-", "");
const updatePkg = pkg => {
    const dependencies = Object.assign({}, pkg.dependencies);
    if (dependencies["textlint-report-helper-for-google-preset"]) {
        delete dependencies["textlint-report-helper-for-google-preset"];
        dependencies["@textlint-rule/textlint-report-helper-for-google-preset"] = "^1.0.0";
    }
    return Object.assign({}, pkg, {
        dependencies: dependencies
    });
};

// package
const pkgPath = path.join(process.cwd(), "package.json");
const originalPkg = require(pkgPath);
const newPkg = updatePkg(originalPkg);
fs.writeFileSync(pkgPath, JSON.stringify(newPkg, null, 2), "utf-8");
const srcPath = path.join(process.cwd(), `src/${currentPackage}.js`);
if (!fs.existsSync(srcPath)) {
    return;
}
const srcContent = fs.readFileSync(srcPath, "utf-8");
const updateSrcContent = srcContent.replace(
    new RegExp('"textlint-report-helper-for-google-preset"', "g"),
    `"@textlint-rule/textlint-report-helper-for-google-preset"`
);
fs.writeFileSync(srcPath, updateSrcContent, "utf-8");

yarn run lerna exec node /index.js

fix #16