@icebreakers/monorepo 0.2.7 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ # Contributing
2
+
3
+ TODO
@@ -0,0 +1,14 @@
1
+ import path from 'pathe'
2
+ import { rimraf } from 'rimraf'
3
+
4
+ const dirs = [
5
+ 'packages/monorepo',
6
+ 'packages/foo',
7
+ // 'apps/cli',
8
+ // 'apps/website',
9
+ 'apps',
10
+ ]
11
+
12
+ await rimraf(dirs.map((x) => {
13
+ return path.resolve(import.meta.dirname, '..', x)
14
+ }))
@@ -0,0 +1,18 @@
1
+ import process from 'node:process'
2
+ import path from 'pathe'
3
+ import { GitClient } from './git'
4
+ import { getWorkspacePackages } from './utils'
5
+
6
+ export async function createContext(cwd = process.cwd()) {
7
+ const git = new GitClient()
8
+ const workspaceFilepath = path.resolve(import.meta.dirname, '../pnpm-workspace.yaml')
9
+ const projects = await getWorkspacePackages(cwd)
10
+ return {
11
+ cwd,
12
+ git,
13
+ workspaceFilepath,
14
+ projects,
15
+ }
16
+ }
17
+
18
+ export type Context = Awaited<ReturnType<typeof createContext>>
@@ -0,0 +1,56 @@
1
+ import get from 'get-value'
2
+ import gitUrlParse from 'git-url-parse'
3
+ import { simpleGit } from 'simple-git'
4
+ import type { ConfigValues, SimpleGit, SimpleGitOptions } from 'simple-git'
5
+
6
+ export class GitClient {
7
+ private client: SimpleGit
8
+ #config: ConfigValues | undefined
9
+ constructor(options: Partial<SimpleGitOptions> = {}) {
10
+ this.client = simpleGit(options)
11
+ }
12
+
13
+ listConfig() {
14
+ return this.client.listConfig()
15
+ }
16
+
17
+ async init() {
18
+ const listConfig = await this.listConfig()
19
+ this.#config = listConfig.all
20
+ return this.#config
21
+ }
22
+
23
+ async getConfig() {
24
+ if (this.#config) {
25
+ return this.#config
26
+ }
27
+ else {
28
+ return await this.init()
29
+ }
30
+ }
31
+
32
+ async getGitUrl() {
33
+ const config = await this.getConfig()
34
+ const x = get(config, 'remote.origin.url')
35
+ if (x) {
36
+ return gitUrlParse(x)
37
+ }
38
+ }
39
+
40
+ async getRepoName() {
41
+ const url = await this.getGitUrl()
42
+ if (url) {
43
+ return `${url.owner}/${url.name}`
44
+ }
45
+ }
46
+
47
+ async getUser() {
48
+ const config = await this.getConfig()
49
+ const name: string = get(config, 'user.name')
50
+ const email: string = get(config, 'user.email')
51
+ return {
52
+ name,
53
+ email,
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,8 @@
1
+ import { createContext } from './context'
2
+ import setPkgJson from './setPkgJson'
3
+ import setReadme from './setReadme'
4
+
5
+ const ctx = await createContext()
6
+
7
+ await setPkgJson(ctx)
8
+ await setReadme(ctx)
@@ -0,0 +1,49 @@
1
+ import fs from 'fs-extra'
2
+ import path from 'pathe'
3
+ import set from 'set-value'
4
+ import type { PackageJson } from 'pkg-types'
5
+ import type { Context } from './context'
6
+
7
+ const scripts = {
8
+ 'script:init': 'tsx scripts/init.ts',
9
+ 'script:sync': 'tsx scripts/sync.ts',
10
+ 'script:clean': 'tsx scripts/clean.ts',
11
+ }
12
+
13
+ const scriptsEntries = Object.entries(scripts)
14
+
15
+ export default async function (ctx: Context) {
16
+ const { git, projects, cwd, workspaceFilepath } = ctx
17
+ const gitUrl = await git.getGitUrl()
18
+ const gitUser = await git.getUser()
19
+ if (gitUrl && await fs.exists(workspaceFilepath)) {
20
+ for (const project of projects) {
21
+ const pkgJson = project.manifest
22
+ const directory = path.relative(cwd, project.rootDir)
23
+ set(pkgJson, 'bugs.url', `https://github.com/${gitUrl.full_name}/issues`)
24
+ const repository: PackageJson['repository'] = {
25
+ type: 'git',
26
+ url: `git+https://github.com/${gitUrl.full_name}.git`,
27
+ }
28
+ if (directory) {
29
+ repository.directory = directory
30
+ }
31
+ else {
32
+ for (const [k, v] of scriptsEntries) {
33
+ set(pkgJson, `scripts.${k}`, v)
34
+ }
35
+ }
36
+ set(pkgJson, 'repository', repository)
37
+ if (gitUser) {
38
+ set(pkgJson, 'author', `${gitUser.name} <${gitUser.email}>`)
39
+ }
40
+
41
+ // "maintainers": [
42
+ // "xxx <xxx@gmail.com> (url)",
43
+ // ],
44
+ await fs.writeJSON(project.pkgJsonPath, pkgJson, {
45
+ spaces: 2,
46
+ })
47
+ }
48
+ }
49
+ }
@@ -0,0 +1,53 @@
1
+ import fs from 'fs-extra'
2
+ import path from 'pathe'
3
+ import type { Context } from './context'
4
+
5
+ async function getRows(ctx: Context) {
6
+ const { projects, git, cwd } = ctx
7
+ const gitUrl = await git.getGitUrl()
8
+ const gitUser = await git.getUser()
9
+ const rows: string[] = []
10
+ if (gitUrl) {
11
+ rows.push(`# ${gitUrl.name}\n`)
12
+ }
13
+ rows.push('## Projects\n')
14
+ for (const project of projects) {
15
+ const p = path.relative(cwd, project.rootDirRealPath)
16
+ p && rows.push(`- [${project.manifest.name}](${p}) ${project.manifest.description ? `- ${project.manifest.description}` : ''}`)
17
+ }
18
+ // ## Documentation
19
+ // ## Communication
20
+ if (gitUrl) {
21
+ // ## Contributing
22
+ rows.push('\n## Contributing\n')
23
+ rows.push('Contributions Welcome! You can contribute in the following ways.')
24
+ rows.push('')
25
+ rows.push('- Create an Issue - Propose a new feature. Report a bug.')
26
+ rows.push('- Pull Request - Fix a bug and typo. Refactor the code.')
27
+ rows.push('- Create third-party middleware - Instruct below.')
28
+ rows.push('- Share - Share your thoughts on the Blog, X, and others.')
29
+ rows.push(`- Make your application - Please try to use ${gitUrl.name}.`)
30
+ rows.push('')
31
+ rows.push('For more details, see [CONTRIBUTING.md](CONTRIBUTING.md).')
32
+ // ## Contributors
33
+ rows.push('\n## Contributors\n')
34
+ rows.push(`Thanks to [all contributors](https://github.com/${gitUrl.full_name}/graphs/contributors)!`)
35
+ }
36
+
37
+ // ## Authors
38
+
39
+ rows.push('\n## Authors\n')
40
+ rows.push(`${gitUser.name} <${gitUser.email}>`)
41
+
42
+ // ## License
43
+
44
+ rows.push('\n## License\n')
45
+ rows.push('Distributed under the MIT License. See [LICENSE](LICENSE) for more information.')
46
+
47
+ return rows
48
+ }
49
+
50
+ export default async function (ctx: Context) {
51
+ const rows = await getRows(ctx)
52
+ await fs.writeFile(path.resolve(ctx.cwd, 'README.md'), `${rows.join('\n')}\n`)
53
+ }
@@ -0,0 +1,15 @@
1
+ import process from 'node:process'
2
+ import { execa } from 'execa'
3
+ import { getWorkspacePackages } from './utils'
4
+
5
+ const cwd = process.cwd()
6
+
7
+ const packages = await getWorkspacePackages(cwd)
8
+
9
+ for (const project of packages) {
10
+ if (project.manifest.name) {
11
+ await execa({
12
+ stdout: ['pipe', 'inherit'],
13
+ })`cnpm sync ${project.manifest.name}`
14
+ }
15
+ }
@@ -0,0 +1,21 @@
1
+ import { findWorkspacePackages } from '@pnpm/workspace.find-packages'
2
+ import path from 'pathe'
3
+
4
+ export async function getWorkspacePackages(cwd: string) {
5
+ const packages = await findWorkspacePackages(cwd)
6
+ return (
7
+ await Promise.allSettled(packages.map(async (project) => {
8
+ const pkgJsonPath = path.resolve(project.rootDir, 'package.json')
9
+ return {
10
+ ...project,
11
+ pkgJsonPath,
12
+ }
13
+ }))
14
+ )
15
+ .filter((x) => {
16
+ return x.status === 'fulfilled'
17
+ })
18
+ .map((x) => {
19
+ return x.value
20
+ })
21
+ }
@@ -399,8 +399,9 @@ function getTargets(raw) {
399
399
  "vitest.workspace.ts",
400
400
  // #region docker
401
401
  "Dockerfile",
402
- ".dockerignore"
402
+ ".dockerignore",
403
403
  // #endregion
404
+ "scripts"
404
405
  ];
405
406
  if (!raw) {
406
407
  list.push(".github", "LICENSE", "renovate.json", "SECURITY.md", "CODE_OF_CONDUCT.md", "CONTRIBUTING.md", "netlify.toml");
@@ -447,6 +448,12 @@ async function main(opts) {
447
448
  })
448
449
  });
449
450
  }
451
+ const removeDirs = ["scripts"];
452
+ for (const dir of removeDirs) {
453
+ if (targets.includes(dir)) {
454
+ await fs.remove(path.resolve(absOutDir, dir));
455
+ }
456
+ }
450
457
  const regexpArr = targets.map((x) => {
451
458
  return new RegExp(`^${escapeStringRegexp(x)}`);
452
459
  });
package/dist/cli.cjs CHANGED
@@ -316,7 +316,7 @@ var import_commander = require("commander");
316
316
 
317
317
  // package.json
318
318
  var name = "@icebreakers/monorepo";
319
- var version = "0.2.7";
319
+ var version = "0.3.1";
320
320
 
321
321
  // src/lib.ts
322
322
  init_cjs_shims();
@@ -411,8 +411,9 @@ function getTargets(raw) {
411
411
  "vitest.workspace.ts",
412
412
  // #region docker
413
413
  "Dockerfile",
414
- ".dockerignore"
414
+ ".dockerignore",
415
415
  // #endregion
416
+ "scripts"
416
417
  ];
417
418
  if (!raw) {
418
419
  list.push(".github", "LICENSE", "renovate.json", "SECURITY.md", "CODE_OF_CONDUCT.md", "CONTRIBUTING.md", "netlify.toml");
@@ -459,6 +460,12 @@ async function main(opts) {
459
460
  })
460
461
  });
461
462
  }
463
+ const removeDirs = ["scripts"];
464
+ for (const dir of removeDirs) {
465
+ if (targets.includes(dir)) {
466
+ await import_fs_extra.default.remove(import_pathe.default.resolve(absOutDir, dir));
467
+ }
468
+ }
462
469
  const regexpArr = targets.map((x) => {
463
470
  return new RegExp(`^${escapeStringRegexp(x)}`);
464
471
  });
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  init_esm_shims,
3
3
  logger,
4
4
  main
5
- } from "./chunk-IWVKXXSC.js";
5
+ } from "./chunk-HFEJOR7C.js";
6
6
 
7
7
  // src/cli.ts
8
8
  init_esm_shims();
@@ -13,7 +13,7 @@ import { program } from "commander";
13
13
 
14
14
  // package.json
15
15
  var name = "@icebreakers/monorepo";
16
- var version = "0.2.7";
16
+ var version = "0.3.1";
17
17
 
18
18
  // src/program.ts
19
19
  program.name(name).version(version);
package/dist/index.cjs CHANGED
@@ -413,8 +413,9 @@ function getTargets(raw) {
413
413
  "vitest.workspace.ts",
414
414
  // #region docker
415
415
  "Dockerfile",
416
- ".dockerignore"
416
+ ".dockerignore",
417
417
  // #endregion
418
+ "scripts"
418
419
  ];
419
420
  if (!raw) {
420
421
  list.push(".github", "LICENSE", "renovate.json", "SECURITY.md", "CODE_OF_CONDUCT.md", "CONTRIBUTING.md", "netlify.toml");
@@ -461,6 +462,12 @@ async function main(opts) {
461
462
  })
462
463
  });
463
464
  }
465
+ const removeDirs = ["scripts"];
466
+ for (const dir of removeDirs) {
467
+ if (targets.includes(dir)) {
468
+ await import_fs_extra.default.remove(import_pathe.default.resolve(absOutDir, dir));
469
+ }
470
+ }
464
471
  const regexpArr = targets.map((x) => {
465
472
  return new RegExp(`^${escapeStringRegexp(x)}`);
466
473
  });
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  main
3
- } from "./chunk-IWVKXXSC.js";
3
+ } from "./chunk-HFEJOR7C.js";
4
4
  export {
5
5
  main
6
6
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@icebreakers/monorepo",
3
3
  "type": "module",
4
- "version": "0.2.7",
4
+ "version": "0.3.1",
5
5
  "description": "icebreaker's monorepo config generator",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",