generated from react18-tools/turborepo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scope.js
51 lines (45 loc) · 2.18 KB
/
scope.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* eslint-disable -- no need - external file */
"use strict";
const fs = require("node:fs");
const path = require("node:path");
const owner = "mayank1513";
const repo = "fork-me";
const pkgPath = path.resolve(process.cwd(), "lib", repo, "package.json");
const packageJson = require(pkgPath);
const ref = packageJson.name;
if (!ref.startsWith(`@${owner}`)) {
/** Update lib package.json */
packageJson.name = `@${owner}/${packageJson.name}`;
fs.writeFileSync(pkgPath, JSON.stringify(packageJson, null, 2));
/** Update README */
const readMePath = path.resolve(process.cwd(), "README.md");
let readMe = fs.readFileSync(readMePath, { encoding: "utf8" });
const tmp = "!---!";
const tmp2 = "2---2";
readMe = readMe.replace(new RegExp(`${owner}/${ref}`, "g"), tmp);
readMe = readMe.replace(new RegExp(`github.io/${ref}`, "g"), tmp2);
readMe = readMe.replace(new RegExp(ref, "g"), packageJson.name);
readMe = readMe.replace(new RegExp(tmp, "g"), `${owner}/${ref}`);
readMe = readMe.replace(new RegExp(tmp2, "g"), `github.io/${ref}`);
fs.writeFileSync(readMePath, readMe);
/** Update examples */
const examplesPath = path.resolve(process.cwd(), "examples");
fs.readdirSync(examplesPath).forEach(dir => {
const examplePkgPath = path.resolve(examplesPath, dir, "package.json");
let examplePkg = require(examplePkgPath);
delete examplePkg.dependencies[repo];
examplePkg.dependencies[`@${owner}/${repo}`] = "workspace:*";
fs.writeFileSync(examplePkgPath, JSON.stringify(examplePkg, null, 2));
});
/** Update shared-ui package.json */
const sharedPkgPath = path.resolve(process.cwd(), "packages", "shared-ui", "package.json");
let sharedUIPkg = require(sharedPkgPath);
delete sharedUIPkg.devDependencies[repo];
sharedUIPkg.devDependencies[`@${owner}/${repo}`] = "workspace:*";
fs.writeFileSync(sharedPkgPath, JSON.stringify(sharedUIPkg, null, 2));
/** Update Remix server config */
const remixConfigPath = path.resolve(examplesPath, "remix", "remix.config.js");
let remixConfig = fs.readFileSync(remixConfigPath, { encoding: "utf8" });
remixConfig = remixConfig.replace(new RegExp(ref, "g"), packageJson.name);
fs.writeFileSync(remixConfigPath, remixConfig);
}