@travetto/repo 3.0.0-rc.10
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.
- package/README.md +9 -0
- package/package.json +37 -0
- package/support/bin/npm.ts +48 -0
- package/support/cli.repo_publish.ts +44 -0
- package/support/cli.repo_version.ts +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<!-- This file was generated by @travetto/doc and should not be modified directly -->
|
|
2
|
+
<!-- Please modify https://github.com/travetto/travetto/tree/main/module/repo/DOC.ts and execute "npx trv doc" to rebuild -->
|
|
3
|
+
# Repo
|
|
4
|
+
## Monorepo utilities
|
|
5
|
+
|
|
6
|
+
**Install: @travetto/repo**
|
|
7
|
+
```bash
|
|
8
|
+
npm install @travetto/repo
|
|
9
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@travetto/repo",
|
|
3
|
+
"version": "3.0.0-rc.10",
|
|
4
|
+
"description": "Monorepo utilities",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"travetto",
|
|
7
|
+
"typescript",
|
|
8
|
+
"monorepo"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://travetto.io",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": {
|
|
13
|
+
"email": "travetto.framework@gmail.com",
|
|
14
|
+
"name": "Travetto Framework"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"support"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"url": "https://github.com/travetto/travetto.git",
|
|
21
|
+
"directory": "module/repo"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@travetto/cli": "^3.0.0-rc.10"
|
|
25
|
+
},
|
|
26
|
+
"peerDependenciesMeta": {
|
|
27
|
+
"@travetto/cli": {
|
|
28
|
+
"optional": true
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"travetto": {
|
|
32
|
+
"displayName": "Repo"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ExecUtil, ExecutionOptions, ExecutionState, ExecutionResult } from '@travetto/base';
|
|
2
|
+
import { IndexedModule } from '@travetto/manifest';
|
|
3
|
+
|
|
4
|
+
export type SemverLevel = 'minor' | 'patch' | 'major' | 'prerelease';
|
|
5
|
+
|
|
6
|
+
export class Npm {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Is a module already published
|
|
10
|
+
*/
|
|
11
|
+
static isPublished(mod: IndexedModule, opts: ExecutionOptions): ExecutionState {
|
|
12
|
+
return ExecUtil.spawn('npm', ['show', `${mod.name}@${mod.version}`, 'version', '--json'], opts);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Validate published result
|
|
17
|
+
*/
|
|
18
|
+
static validatePublishedResult(mod: IndexedModule, result: ExecutionResult): boolean {
|
|
19
|
+
if (!result.valid && !result.stderr.includes('E404')) {
|
|
20
|
+
throw new Error(result.stderr);
|
|
21
|
+
}
|
|
22
|
+
const item: (string[] | string) = result.stdout ? JSON.parse(result.stdout) : [];
|
|
23
|
+
const found = Array.isArray(item) ? item.pop() : item;
|
|
24
|
+
return !!found && found === mod.version;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Setting the version
|
|
29
|
+
*/
|
|
30
|
+
static async version(modules: IndexedModule[], level: SemverLevel, preid?: string): Promise<void> {
|
|
31
|
+
const mods = modules.flatMap(m => ['-w', m.sourceFolder]);
|
|
32
|
+
await ExecUtil.spawn('npm',
|
|
33
|
+
['version', level, ...(preid ? ['--preid', preid] : []), ...mods],
|
|
34
|
+
{ stdio: 'inherit' }
|
|
35
|
+
).result;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Publish a module
|
|
40
|
+
*/
|
|
41
|
+
static publish(mod: IndexedModule, dryRun: boolean | undefined, opts: ExecutionOptions): ExecutionState {
|
|
42
|
+
const versionTag = mod.version.replace(/^.*-(rc|alpha|beta|next)[.]\d+/, (a, b) => b) || 'latest';
|
|
43
|
+
return ExecUtil.spawn('npm',
|
|
44
|
+
['publish', ...(dryRun ? ['--dry-run'] : []), '--tag', versionTag, '--access', 'public'],
|
|
45
|
+
opts
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { CliCommand, CliModuleUtil, OptionConfig } from '@travetto/cli';
|
|
2
|
+
import { Npm } from './bin/npm';
|
|
3
|
+
|
|
4
|
+
type Options = {
|
|
5
|
+
dryRun: OptionConfig<boolean>;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* `npx trv repo:publish`
|
|
10
|
+
*
|
|
11
|
+
* Publish all pending modules
|
|
12
|
+
*/
|
|
13
|
+
export class RepoPublishCommand extends CliCommand<Options> {
|
|
14
|
+
|
|
15
|
+
name = 'repo:publish';
|
|
16
|
+
|
|
17
|
+
getOptions(): Options {
|
|
18
|
+
return {
|
|
19
|
+
dryRun: this.boolOption({ desc: 'Dry Run?', def: true })
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async action(...args: unknown[]): Promise<void> {
|
|
24
|
+
const published = await CliModuleUtil.execOnModules('all', (mod, opts) => Npm.isPublished(mod, opts), {
|
|
25
|
+
filter: mod => !!mod.local && !mod.internal,
|
|
26
|
+
progressMessage: (mod) => `Checking published [%idx/%total] -- ${mod?.name}`,
|
|
27
|
+
showStderr: false,
|
|
28
|
+
transformResult: Npm.validatePublishedResult,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (this.cmd.dryRun) {
|
|
32
|
+
console.log('Unpublished modules', [...published.entries()].filter(x => !x[1]).map(([mod]) => mod.sourceFolder));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
await CliModuleUtil.execOnModules(
|
|
36
|
+
'all', (mod, opts) => Npm.publish(mod, this.cmd.dryRun, opts),
|
|
37
|
+
{
|
|
38
|
+
progressMessage: (mod) => `Published [%idx/%total] -- ${mod?.name}`,
|
|
39
|
+
showStdout: false,
|
|
40
|
+
filter: mod => published.get(mod) === false
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { CliCommand, CliScmUtil, OptionConfig } from '@travetto/cli';
|
|
2
|
+
import { CliModuleUtil } from '@travetto/cli/src/module';
|
|
3
|
+
|
|
4
|
+
import { Npm, SemverLevel } from './bin/npm';
|
|
5
|
+
|
|
6
|
+
type VersionOptions = {
|
|
7
|
+
changed: OptionConfig<boolean>;
|
|
8
|
+
force: OptionConfig<boolean>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* `npx trv repo:version`
|
|
13
|
+
*
|
|
14
|
+
* Version all all changed dependencies
|
|
15
|
+
*/
|
|
16
|
+
export class RepoVersionCommand extends CliCommand<VersionOptions> {
|
|
17
|
+
|
|
18
|
+
name = 'repo:version';
|
|
19
|
+
|
|
20
|
+
getArgs(): string {
|
|
21
|
+
return '<level> [prefix]';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getOptions(): VersionOptions {
|
|
25
|
+
return {
|
|
26
|
+
changed: this.boolOption({ desc: 'Only version changed modules', def: true }),
|
|
27
|
+
force: this.boolOption({ desc: 'Force operation, even in a dirty workspace', def: false })
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async action(level: SemverLevel, prefix?: string): Promise<void> {
|
|
32
|
+
if (!this.cmd.force && await CliScmUtil.isWorkspaceDirty()) {
|
|
33
|
+
console.error!('Cannot update versions with uncommitted changes');
|
|
34
|
+
return this.exit(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const allModules = await CliModuleUtil.findModules(this.cmd.changed ? 'changed' : 'all');
|
|
38
|
+
|
|
39
|
+
const modules = allModules.filter(x => !x.internal);
|
|
40
|
+
|
|
41
|
+
// Do we have valid changes?
|
|
42
|
+
if (!modules.length) {
|
|
43
|
+
console.error!('No modules available for versioning');
|
|
44
|
+
return this.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
await Npm.version(modules, level, prefix);
|
|
48
|
+
|
|
49
|
+
await CliModuleUtil.synchronizeModuleVersions();
|
|
50
|
+
|
|
51
|
+
console.log!(await CliScmUtil.createCommit(`Publish ${modules.map(x => x.name).join(',')}`));
|
|
52
|
+
}
|
|
53
|
+
}
|