Skip to content

Commit f5964c5

Browse files
authored
feat: Expand CLI commands (#200)
1 parent fe6146a commit f5964c5

File tree

24 files changed

+410
-196
lines changed

24 files changed

+410
-196
lines changed

.changeset/blue-shirts-hammer.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"secco": patch
3+
---
4+
5+
Various small bug fixes:
6+
7+
- When `dist/` was in the `files` array of `package.json` it didn't correctly copy over files inside the `dist` directory
8+
- When `--scan-once` and `--force-verdaccio` were used together a warning was thrown about an ungraceful exit. For this codepath any cleanup tasks are run before exiting now. The warning won't show.
9+
- The `init` command ran the whole main function while it should only run the Enquirer prompt. This is fixed now.

.changeset/fast-rats-look.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
"secco": minor
3+
---
4+
5+
The CLI got more functionality!
6+
7+
- Add `-s` alias for `--scan-once` and `-f` for `--force-verdaccio`
8+
- Add `--source` and `--yes` flag for `secco init`, making it possible to run the init command in non-interactive mode
9+
10+
For example, this command will create a `.seccorc` file with the given source path:
11+
12+
```bash
13+
secco init --source=/absolute/path --yes
14+
```
15+
16+
If you don't provide the `--yes` flag you'll need to confirm the prompt.

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,21 @@ Here's an overview of all available commands and flags:
6666
Usage: secco <command>
6767

6868
Commands:
69-
secco init Initialize a new .seccorc file
69+
secco Scan destination and copy files from source [default]
7070
secco packages [packageNames...] Specify list of packages you want to link
71+
secco init Initialize a new .seccorc file
7172

7273
Options:
73-
--help Show help
74-
--version Show version number
75-
--scan-once Scan source once and do not start file watching
76-
--force-verdaccio Disable file copying/watching and force usage of Verdaccio
77-
--verbose Output verbose logging
74+
--help Show help [boolean]
75+
--version Show version number [boolean]
76+
-s, --scan-once Scan source once and do not start file watching [boolean] [default: false]
77+
-f, --force-verdaccio Disable file copying/watching and force usage of Verdaccio [boolean] [default: false]
78+
--verbose Output verbose logging [boolean] [default: false]
7879

7980
Examples:
80-
secco Scan destination and copy files from source
81-
secco packages ars aurea Copy specified packages from source to destination
81+
secco Scan destination and copy files from source
82+
secco packages ars aurea Copy specified packages from source to destination
83+
secco init --source=/absolute/path --yes Create a .seccorc file in the current dir with the provided source path without any prompts
8284
```
8385

8486
## Documentation

docs/src/content/docs/guide/learn-secco.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ Ensure that the installation was successful by running `secco --help`. You shoul
6464
Usage: secco <command>
6565

6666
Commands:
67-
secco init Initialize a new .seccorc file
67+
secco Scan destination and copy files from source [default]
6868
secco packages [packageNames...] Specify list of packages you want to link
69+
secco init Initialize a new .seccorc file
6970
```
7071

7172
## How to use secco

docs/src/content/docs/reference/commands.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ sidebar:
99

1010
Run this command inside your destination folder. You'll be asked questions about your source folder and at the end of the questionnaire a new `.seccorc` config file will be created.
1111

12+
By default, the `secco init` command is an interactive prompt. However, if you want to use it in non-interactive environments you can provide both `--source` and `--yes` flags.
13+
14+
```shell
15+
secco init --source=/absolute-path/to/directory --yes
16+
```
17+
18+
**Optional flags:**
19+
20+
- `--source`: Absolute path to the source directory
21+
- `--yes`: Skip confirmation prompts
22+
1223
## `secco`
1324

1425
`secco` will scan your destination's `package.json` file and compare it with the available packages inside your source. It'll then copy over all changes into your destination's `node_modules` folder. Additionally, a watch task is started to continue copying over changes. Packages that have [`"private": true`](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#private) set will be ignored.

docs/src/content/docs/reference/flags.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,34 @@ sidebar:
55
order: 99999
66
---
77

8-
These are the flags that you can use with any command.
8+
These are the flags that you can use throughout the CLI. If not noted otherwise, you can use them with every command.
99

1010
## `--help`
1111

12-
Shows the help menu of `secco`
12+
Shows the help menu of `secco`. You can also show help menus of subcommands, e.g. `secco packages --help`.
1313

1414
## `--version`
1515

16-
Displays the current version of `secco`
16+
Displays the current version of `secco`.
17+
18+
## `--verbose`
19+
20+
Output additional debug logs and more information.
1721

1822
## `--scan-once`
1923

24+
- **Alias:** `-s`
25+
26+
- **Commands:** `secco`, `secco packages`
27+
2028
By default `secco` starts a watch script to listen for changes. If you want to disable this behavior, use `--scan-once`. This way `secco` will do an initial scan, copy the changes, and then quit.
2129

2230
This is useful for CI environments as you can e.g. set up automated test sites with latest code changes. See the [CI guide](/guide/continuous-integration/) for more information.
2331

2432
## `--force-verdaccio`
2533

26-
Disable the copying of files into `node_modules` and always use Verdaccio. This is helpful for ensuring in e.g. End-To-End test environments that the package installation is correct.
34+
- **Alias:** `-f`
2735

28-
## `--verbose`
36+
- **Commands:** `secco`, `secco packages`
2937

30-
Output additional debug logs and more information.
38+
Disable the copying of files into `node_modules` and always use Verdaccio. This is helpful for ensuring in e.g. End-To-End test environments that the package installation is correct.

integration/__tests__/commands.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { SeccoCLI } from '../../helpers/invoke-cli'
2+
3+
describe('--help', () => {
4+
it('should display usage overview', () => {
5+
const [exitCode, logs] = SeccoCLI().invoke(['--help'])
6+
7+
logs.should.contain('Usage:')
8+
logs.should.contain('Options:')
9+
logs.should.contain('Examples:')
10+
expect(exitCode).toBe(0)
11+
})
12+
})
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import path from 'node:path'
2+
import { fileExists } from 'verdaccio/build/lib/utils'
3+
import { createTempDir, fileContainsText } from '../../helpers/files'
4+
import { SeccoCLI } from '../../helpers/invoke-cli'
5+
6+
const initQuestion = 'What is the absolute path to your source?'
7+
const warning = '.seccorc file already exists in this directory'
8+
9+
describe('init', () => {
10+
it('should work in directory without .seccorc file', () => {
11+
const [exitCode, logs] = SeccoCLI().setFixture('empty').invoke(['init'])
12+
13+
logs.should.contain(initQuestion)
14+
logs.should.not.contain(warning)
15+
expect(exitCode).toBe(0)
16+
})
17+
it('should warn in directory with .seccorc file', () => {
18+
const [exitCode, logs] = SeccoCLI().setFixture('existing-config-file').invoke(['init'])
19+
20+
logs.should.contain(initQuestion)
21+
logs.should.contain(warning)
22+
expect(exitCode).toBe(0)
23+
})
24+
it('should create config file after providing valid input', async () => {
25+
const [testDir, cleanup] = await createTempDir('init-command')
26+
const input = '/some/absolute/path/to/source'
27+
28+
try {
29+
const [exitCode, logs] = SeccoCLI().setEnv({ TEST: undefined, VITEST: undefined, VITEST_MODE: undefined, VITEST_WORKER_ID: undefined, VITEST_POOL_ID: undefined }).setCwd(testDir).invoke(['init', '--source', input, '--yes'])
30+
31+
logs.should.contain('Successfully created .seccorc')
32+
expect(exitCode).toBe(0)
33+
34+
const file = await fileExists(path.join(testDir, '.seccorc'))
35+
expect(file).toBe(true)
36+
const contents = await fileContainsText(path.join(testDir, '.seccorc'), input)
37+
expect(contents).toBe(true)
38+
}
39+
finally {
40+
await cleanup()
41+
}
42+
})
43+
it('should error on invalid input', () => {
44+
const [exitCode, logs] = SeccoCLI().setFixture('empty').invoke(['init', '--source', 'relative-path', '--yes'])
45+
46+
logs.should.contain('You need to provide an absolute path for the --source flag.')
47+
expect(exitCode).toBe(1)
48+
})
49+
})
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
describe.todo('packages', () => {
2+
})

0 commit comments

Comments
 (0)