Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(up): hlx up defaults to local repo #1149

Merged
merged 6 commits into from
Sep 12, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -254,11 +254,19 @@ start a git server that emulates GitHub repositories for a local git repository.
have a _content_ or _static_ url that matches the `origin` of emulated repository are internally reconfigured
to use the local git server instead.

For the simple case, where only one repository is used for code, content and static just do:
`--local-repo .` is the implicit default. For the simple case, where only one repository is used for code, content and static just do:

```
$ hlx up --local-repo
```
$ hlx up
```

which is equivalent to `hlx up --local-repo .`.

If you want to explicitly always fetch from GitHub, i.e. ignore the local checkout in the current working directory (or any other checkout specified with `--local-repo`), use `--no-local-repo`:

```
$ hlx up --no-local-repo
```

#### Multi Strain Example

13 changes: 10 additions & 3 deletions src/up.js
Original file line number Diff line number Diff line change
@@ -47,10 +47,10 @@ module.exports = function up() {
})
.option('local-repo', {
alias: 'localRepo',
describe: 'Emulates a GitHub repository for the specified git repository.',
describe: 'Emulates a GitHub repository for the specified local git repository.',
type: 'string',
array: true,
default: [],
default: '.',
})
// allow for comma separated values
.coerce('localRepo', (value) => value.reduce((acc, curr) => {
@@ -63,6 +63,13 @@ module.exports = function up() {
}
return acc;
}, []))
.option('no-local-repo', {
// negation of the local-repo option (resets local-repo default)
// see https://github.com/yargs/yargs/blob/master/docs/tricks.md#negating-boolean-arguments
alias: 'noLocalRepo',
describe: 'Ignore local checkout, always fetch from GitHub',
type: 'boolean',
})
.option('save-config', {
alias: 'saveConfig',
describe: 'Saves the default config.',
@@ -74,7 +81,7 @@ module.exports = function up() {
type: 'int',
default: 3000,
})
.group(['port', 'open', 'host', 'local-repo'], 'Server options')
.group(['port', 'open', 'host', 'local-repo', 'no-local-repo'], 'Server options')
.help();
},
handler: async (argv) => {
16 changes: 12 additions & 4 deletions test/testUpCli.js
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ describe('hlx up', () => {
sinon.assert.calledWith(mockUp.withTargetDir, '.hlx/build');
sinon.assert.calledWith(mockUp.withFiles, ['src/**/*.htl', 'src/**/*.js', 'src/**/*.jsx', 'cgi-bin/**/*.js']);
sinon.assert.calledWith(mockUp.withOverrideHost, undefined);
sinon.assert.calledWith(mockUp.withLocalRepo, []);
sinon.assert.calledWith(mockUp.withLocalRepo, ['.']);
sinon.assert.calledOnce(mockUp.run);
});

@@ -171,7 +171,15 @@ describe('hlx up', () => {
it('hlx up with local repo defaults to .', () => {
new CLI()
.withCommandExecutor('up', mockUp)
.run(['up', '--local-repo', '.']);
.run(['up', '--local-repo']);
sinon.assert.calledWith(mockUp.withLocalRepo, ['.']);
sinon.assert.calledOnce(mockUp.run);
});

it('hlx up defaults to local repo .', () => {
new CLI()
.withCommandExecutor('up', mockUp)
.run(['up']);
sinon.assert.calledWith(mockUp.withLocalRepo, ['.']);
sinon.assert.calledOnce(mockUp.run);
});
@@ -204,8 +212,8 @@ describe('hlx up', () => {
it('hlx up can specify 1 local repo', () => {
new CLI()
.withCommandExecutor('up', mockUp)
.run(['up', '--local-repo', '.']);
sinon.assert.calledWith(mockUp.withLocalRepo, ['.']);
.run(['up', '--local-repo', 'foo']);
sinon.assert.calledWith(mockUp.withLocalRepo, ['foo']);
sinon.assert.calledOnce(mockUp.run);
});