@dungarees/bin-base-app-cli-yargs 0.11.4
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/base-app.d.ts +13 -0
- package/base-app.js +9 -0
- package/behaviors.d.ts +6 -0
- package/behaviors.js +1 -0
- package/get-behaviors.d.ts +5 -0
- package/get-behaviors.js +10 -0
- package/get-delivery.d.ts +8 -0
- package/get-delivery.js +4 -0
- package/main.d.ts +6 -0
- package/main.js +11 -0
- package/main.test.d.ts +1 -0
- package/main.test.js +46 -0
- package/package.json +67 -0
- package/services.d.ts +10 -0
- package/services.js +1 -0
- package/yargs-app.d.ts +3 -0
- package/yargs-app.js +12 -0
- package/yargs-app.test.d.ts +1 -0
- package/yargs-app.test.js +23 -0
package/base-app.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type DungareesBinBehaviors } from './behaviors.ts';
|
|
2
|
+
import { type YargsDelivery } from './get-delivery.ts';
|
|
3
|
+
import { type DungareesBinServices } from './services.ts';
|
|
4
|
+
export type ApplicationConfig = {
|
|
5
|
+
services: DungareesBinServices;
|
|
6
|
+
behaviors: DungareesBinBehaviors;
|
|
7
|
+
delivery: YargsDelivery;
|
|
8
|
+
output: Promise<void>;
|
|
9
|
+
identity: {
|
|
10
|
+
environment: 'prod' | 'test';
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare const baseApplication: any;
|
package/base-app.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getBehaviors } from './get-behaviors.js';
|
|
2
|
+
import { getDelivery } from './get-delivery.js';
|
|
3
|
+
import { main } from './main.js';
|
|
4
|
+
import { createApplication } from '@dungarees/core/application.ts';
|
|
5
|
+
export const baseApplication = createApplication({
|
|
6
|
+
getBehaviors,
|
|
7
|
+
getDelivery,
|
|
8
|
+
main,
|
|
9
|
+
});
|
package/behaviors.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AuditDependenciesBehavior } from '@dungarees/bin-audit-dependencies-domain/behavior.ts';
|
|
2
|
+
import type { PublishLibBehavior } from '@dungarees/bin-publish-lib-domain/behavior.ts';
|
|
3
|
+
export type DungareesBinBehaviors = {
|
|
4
|
+
publishLib: PublishLibBehavior;
|
|
5
|
+
auditDependencies: AuditDependenciesBehavior;
|
|
6
|
+
};
|
package/behaviors.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/get-behaviors.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createAuditDependenciesBehavior } from '@dungarees/bin-audit-dependencies-domain/behavior.ts';
|
|
2
|
+
import { createPublishLibBehavior } from '@dungarees/bin-publish-lib-domain/behavior.ts';
|
|
3
|
+
import { createCliCommands } from '@dungarees/cli-command/service.ts';
|
|
4
|
+
export const getBehaviors = ({ fileSystem, subProcess }) => ({
|
|
5
|
+
publishLib: createPublishLibBehavior({
|
|
6
|
+
fileSystem,
|
|
7
|
+
cliCommands: createCliCommands(subProcess),
|
|
8
|
+
}),
|
|
9
|
+
auditDependencies: createAuditDependenciesBehavior({ fileSystem }),
|
|
10
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DungareesBinBehaviors } from './behaviors.ts';
|
|
2
|
+
import type { YargsPromptApp } from '@dungarees/cli/yargs-prompt-app.ts';
|
|
3
|
+
export type YargsDelivery = {
|
|
4
|
+
app: YargsPromptApp;
|
|
5
|
+
};
|
|
6
|
+
export declare const getDelivery: ({ behaviors, }: {
|
|
7
|
+
behaviors: DungareesBinBehaviors;
|
|
8
|
+
}) => YargsDelivery;
|
package/get-delivery.js
ADDED
package/main.d.ts
ADDED
package/main.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { renderCliToStdio } from '@dungarees/cli/yargs-renderer.ts';
|
|
2
|
+
export const main = async ({ services, delivery, }) => {
|
|
3
|
+
const { argv, ...process } = services.process;
|
|
4
|
+
await renderCliToStdio({
|
|
5
|
+
// argv is the real process.argv, so the node binary and the script path come first.
|
|
6
|
+
argv: argv.slice(2),
|
|
7
|
+
app: delivery.app,
|
|
8
|
+
controls: {},
|
|
9
|
+
process,
|
|
10
|
+
});
|
|
11
|
+
};
|
package/main.test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/main.test.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { getBehaviors } from './get-behaviors.js';
|
|
2
|
+
import { main } from './main.js';
|
|
3
|
+
import { createYargsApp } from './yargs-app.js';
|
|
4
|
+
import { createFakeServices } from '@dungarees/bin-fake-app-cli-yargs/get-services.ts';
|
|
5
|
+
import { PassThrough } from 'node:stream';
|
|
6
|
+
import { expect, test } from 'vitest';
|
|
7
|
+
test('main renders the app to the process it was given', async () => {
|
|
8
|
+
const stdout = new PassThrough();
|
|
9
|
+
const stderr = new PassThrough();
|
|
10
|
+
const exitCodes = [];
|
|
11
|
+
const { services } = createFakeServices({
|
|
12
|
+
files: {
|
|
13
|
+
'/multi-lib/config/version.json': JSON.stringify({ version: '1.0.0' }),
|
|
14
|
+
'/multi-lib/src/lib-1/package.json': JSON.stringify({ name: '@org/lib-1' }),
|
|
15
|
+
'/multi-lib/src/lib-1/file-1.ts': 'export const a = 1\n',
|
|
16
|
+
},
|
|
17
|
+
commands: [
|
|
18
|
+
{
|
|
19
|
+
command: 'npm',
|
|
20
|
+
args: ['view', '@org/lib-1', 'versions', '--json'],
|
|
21
|
+
stdout: '',
|
|
22
|
+
stderror: 'E404 Not found',
|
|
23
|
+
exitCode: 1,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
command: 'npm',
|
|
27
|
+
args: ['publish', '--access', 'public'],
|
|
28
|
+
stdout: 'Published successfully',
|
|
29
|
+
exitCode: 0,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
process: {
|
|
33
|
+
argv: ['node', 'dungarees', 'publish-multi-lib', '/multi-lib'],
|
|
34
|
+
stdout,
|
|
35
|
+
stderr,
|
|
36
|
+
exit: (code) => {
|
|
37
|
+
exitCodes.push(code);
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
const app = createYargsApp(getBehaviors(services));
|
|
42
|
+
await main({ services, delivery: { app } });
|
|
43
|
+
expect(String(stderr.read() ?? '')).toBe('');
|
|
44
|
+
expect(String(stdout.read() ?? '')).toContain('All packages published successfully');
|
|
45
|
+
expect(exitCodes).toEqual([0]);
|
|
46
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dungarees/bin-base-app-cli-yargs",
|
|
3
|
+
"engines": {
|
|
4
|
+
"node": ">=25.0.0"
|
|
5
|
+
},
|
|
6
|
+
"scripts": {
|
|
7
|
+
"type-check": "tsc --noEmit"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@dungarees/bin-audit-dependencies-cli-yargs": "*",
|
|
12
|
+
"@dungarees/bin-audit-dependencies-domain": "*",
|
|
13
|
+
"@dungarees/bin-publish-lib-cli-yargs": "*",
|
|
14
|
+
"@dungarees/bin-publish-lib-domain": "*",
|
|
15
|
+
"@dungarees/cli": "*",
|
|
16
|
+
"@dungarees/cli-command": "*",
|
|
17
|
+
"@dungarees/core": "*",
|
|
18
|
+
"@dungarees/fs": "*",
|
|
19
|
+
"@dungarees/sub-process": "*"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@dungarees/bin-fake-app-cli-yargs": "*",
|
|
23
|
+
"typescript": "^5.9.3",
|
|
24
|
+
"vitest": "^3.0.2"
|
|
25
|
+
},
|
|
26
|
+
"author": "info@productkind.com",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"version": "0.11.4",
|
|
29
|
+
"exports": {
|
|
30
|
+
"./base-app.ts": {
|
|
31
|
+
"import": "./base-app.js",
|
|
32
|
+
"types": "./base-app.d.ts"
|
|
33
|
+
},
|
|
34
|
+
"./behaviors.ts": {
|
|
35
|
+
"import": "./behaviors.js",
|
|
36
|
+
"types": "./behaviors.d.ts"
|
|
37
|
+
},
|
|
38
|
+
"./get-behaviors.ts": {
|
|
39
|
+
"import": "./get-behaviors.js",
|
|
40
|
+
"types": "./get-behaviors.d.ts"
|
|
41
|
+
},
|
|
42
|
+
"./get-delivery.ts": {
|
|
43
|
+
"import": "./get-delivery.js",
|
|
44
|
+
"types": "./get-delivery.d.ts"
|
|
45
|
+
},
|
|
46
|
+
"./main.test.ts": {
|
|
47
|
+
"import": "./main.test.js",
|
|
48
|
+
"types": "./main.test.d.ts"
|
|
49
|
+
},
|
|
50
|
+
"./main.ts": {
|
|
51
|
+
"import": "./main.js",
|
|
52
|
+
"types": "./main.d.ts"
|
|
53
|
+
},
|
|
54
|
+
"./services.ts": {
|
|
55
|
+
"import": "./services.js",
|
|
56
|
+
"types": "./services.d.ts"
|
|
57
|
+
},
|
|
58
|
+
"./yargs-app.test.ts": {
|
|
59
|
+
"import": "./yargs-app.test.js",
|
|
60
|
+
"types": "./yargs-app.test.d.ts"
|
|
61
|
+
},
|
|
62
|
+
"./yargs-app.ts": {
|
|
63
|
+
"import": "./yargs-app.js",
|
|
64
|
+
"types": "./yargs-app.d.ts"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
package/services.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RendererProcess } from '@dungarees/cli/yargs-renderer.ts';
|
|
2
|
+
import type { FileSystemService } from '@dungarees/fs/service.ts';
|
|
3
|
+
import type { SubProcessService } from '@dungarees/sub-process/type.ts';
|
|
4
|
+
export type DungareesBinServices = {
|
|
5
|
+
fileSystem: FileSystemService;
|
|
6
|
+
subProcess: SubProcessService;
|
|
7
|
+
process: {
|
|
8
|
+
argv: string[];
|
|
9
|
+
} & RendererProcess;
|
|
10
|
+
};
|
package/services.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/yargs-app.d.ts
ADDED
package/yargs-app.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { auditDependenciesFeature } from '@dungarees/bin-audit-dependencies-cli-yargs/feature.ts';
|
|
2
|
+
import { publishLibFeature } from '@dungarees/bin-publish-lib-cli-yargs/feature.ts';
|
|
3
|
+
import { combineFeatures } from '@dungarees/cli/feature.ts';
|
|
4
|
+
import { createYargsPromptApp } from '@dungarees/cli/yargs-prompt-app.ts';
|
|
5
|
+
export const createYargsApp = (behaviors) => createYargsPromptApp({
|
|
6
|
+
name: 'dungarees',
|
|
7
|
+
...combineFeatures(publishLibFeature({ publishLib: behaviors.publishLib }), auditDependenciesFeature({ auditDependencies: behaviors.auditDependencies })),
|
|
8
|
+
route: (yargs) => yargs
|
|
9
|
+
.demandCommand(1, 'You need at least one command before moving on')
|
|
10
|
+
.strict()
|
|
11
|
+
.version(false),
|
|
12
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createTestApp } from '@dungarees/bin-fake-app-cli-yargs/test-app.ts';
|
|
2
|
+
import { renderCli } from '@dungarees/cli/test-renderer.ts';
|
|
3
|
+
import { expect, test } from 'vitest';
|
|
4
|
+
test('running with no command reports the error on stderr and exits 1', async () => {
|
|
5
|
+
const { app } = createTestApp();
|
|
6
|
+
const { terminal } = renderCli(app, 'dungarees');
|
|
7
|
+
expect(await terminal.step()).toEqual([
|
|
8
|
+
{
|
|
9
|
+
type: 'stderr',
|
|
10
|
+
message: 'You need at least one command before moving on',
|
|
11
|
+
level: 'error',
|
|
12
|
+
},
|
|
13
|
+
{ type: 'exit', code: 1 },
|
|
14
|
+
]);
|
|
15
|
+
});
|
|
16
|
+
test('running an unknown flag reports the error on stderr and exits 1', async () => {
|
|
17
|
+
const { app } = createTestApp();
|
|
18
|
+
const { terminal } = renderCli(app, 'dungarees publish-multi-lib --nope');
|
|
19
|
+
const [error, exit] = await terminal.step();
|
|
20
|
+
expect(error).toMatchObject({ type: 'stderr', level: 'error' });
|
|
21
|
+
expect(error).toHaveProperty('message', expect.stringContaining('Unknown argument'));
|
|
22
|
+
expect(exit).toEqual({ type: 'exit', code: 1 });
|
|
23
|
+
});
|