Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"pub-only": "npm publish --access=public",
"pub-next-only": "npm publish --access=public --tag=next",
"wpm": "ts-node ./src/commands/index.ts",
"test": "NODE_ENV=test mocha src/**/**/*.spec.ts --timeout 999999 --require ts-node/register/transpile-only",
"test": "NODE_ENV=test mocha src/**/*.spec.ts --timeout 999999 --require ts-node/register/transpile-only",
"start:docs": "docgeni serve --port 4500",
"build:docs": "docgeni build --prod",
"build:docs-gh-pages": "docgeni build --prod --base-href=/pkg-manager/"
Expand Down
135 changes: 72 additions & 63 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,76 @@
* found in the LICENSE file at https://github.com/worktile/pkg-manager/blob/master/LICENSE
*/

import { hideBin } from "yargs/helpers";
import yargs from "yargs/yargs";
import { defaults } from "../defaults";
import { releaseCommand } from "./release";
import { publishCommand } from "./publish";
import { getConfiguration } from "../configuration";
import { gitPublishCommand } from "./git-publish";
import { hideBin } from 'yargs/helpers';
import yargs from 'yargs/yargs';
import { defaults } from '../defaults';
import { releaseCommand } from './release';
import { publishCommand } from './publish';
import { getConfiguration } from '../configuration';
import { gitPublishCommand } from './git-publish';

const argv = yargs(hideBin(process.argv))
.scriptName("wpm")
.usage("Usage: $0 <release|publish> [options]")
.option("default-branch", {
alias: "b",
choices: ["master", "develop"],
desc: `Repository's default or base branch, create release based on specify branch`,
default: defaults.defaultBranch,
global: true,
})
.option("allow-branch", {
desc: `A whitelist of globs that match git branches where wpm release is enabled.`,
default: defaults.allowBranch,
array: true,
global: true,
})
.option("dry-run", {
boolean: true,
desc: `See the commands that running wt-release would run`,
default: defaults.dryRun,
global: true,
})
.option("force", {
alias: "f",
boolean: true,
desc: `Ignore uncommitted changes checks (e.g. for publish)`,
default: defaults.force,
global: true,
})
.option("issue-url-format", {
default: defaults.issueUrlFormat,
string: true,
desc: `A URL representing the issue format (allowing a different URL format to be * swapped in for Github, Gitlab, Bitbucket, etc)`,
})
.option("hooks", {
default: defaults.hooks,
desc: `Provide hooks to execute for lifecycle events (prerelease, pretag, etc.)`,
})
.option("tag-prefix", {
alias: "t",
describe: "Set a custom prefix for the git tag to be created",
type: "string",
default: defaults.tagPrefix,
})
.command(releaseCommand)
.command(publishCommand)
.command(gitPublishCommand)
.demandCommand(1, "must provide a valid command")
.detectLocale(false)
.wrap(120)
.version()
.showHelpOnFail(false)
.pkgConf("wpm")
.config(getConfiguration())
.help()
.argv;
const args = hideBin(process.argv);

const { config: configPath } = yargs(args).option('config', { alias: 'c', type: 'string' }).parseSync();

const argv = yargs(args)
.scriptName('wpm')
.usage('Usage: $0 <release|publish> [options]')
.option('default-branch', {
alias: 'b',
choices: ['master', 'develop'],
desc: `Repository's default or base branch, create release based on specify branch`,
default: defaults.defaultBranch,
global: true
})
.option('allow-branch', {
desc: `A whitelist of globs that match git branches where wpm release is enabled.`,
default: defaults.allowBranch,
array: true,
global: true
})
.option('dry-run', {
boolean: true,
desc: `See the commands that running wt-release would run`,
default: defaults.dryRun,
global: true
})
.option('force', {
alias: 'f',
boolean: true,
desc: `Ignore uncommitted changes checks (e.g. for publish)`,
default: defaults.force,
global: true
})
.option('issue-url-format', {
default: defaults.issueUrlFormat,
string: true,
desc: `A URL representing the issue format (allowing a different URL format to be * swapped in for Github, Gitlab, Bitbucket, etc)`
})
.option('hooks', {
default: defaults.hooks,
desc: `Provide hooks to execute for lifecycle events (prerelease, pretag, etc.)`
})
.option('tag-prefix', {
alias: 't',
describe: 'Set a custom prefix for the git tag to be created',
type: 'string',
default: defaults.tagPrefix
})
.option('config', {
alias: 'c',
type: 'string',
desc: 'Path to a wpm configuration file (e.g. .wpmrc.ts)',
global: true
})
.command(releaseCommand)
.command(publishCommand)
.command(gitPublishCommand)
.demandCommand(1, 'must provide a valid command')
.detectLocale(false)
.wrap(120)
.version()
.showHelpOnFail(false)
.pkgConf('wpm')
.config(getConfiguration(undefined, configPath))
.help().argv;
17 changes: 9 additions & 8 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ const searchPlaces = [
`${moduleName}.config.js`
];

export const getConfiguration = function(options?: OptionsSync) {
export const getConfiguration = function (options?: OptionsSync, configPath?: string) {
const exploreSync = cosmiconfigSync(moduleName, options);
const result = exploreSync.search();
const result = configPath ? exploreSync.load(configPath) : exploreSync.search();

if (result && !result.isEmpty) {
if (!result.config || typeof result.config !== 'object') {
throw Error(
`[wpm] Invalid configuration in ${searchPlaces.join(',')} provided. Expected an object but found ${typeof result.config}.`
);
const source = configPath ?? result.filepath ?? searchPlaces.join(',');
throw Error(`[wpm] Invalid configuration in ${source} provided. Expected an object but found ${typeof result.config}.`);
}
return result.config;
} else {
// don't throw error when rc file has not exists.
return {};
}
if (configPath) {
throw Error(`[wpm] Invalid or empty configuration in ${configPath}.`);
}
// don't throw error when rc file has not exists.
return {};
};
12 changes: 5 additions & 7 deletions src/test/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ describe('#pm-configuration', () => {
expect(config.allowBranch).deep.equals(['master', 'v0.*']);
});

// it('should get correct wtpmrc file', () => {
// const config = getConfiguration({
// stopDir: path.resolve(__dirname, './')
// });
// console.log(path.resolve(__dirname, './'));
// console.log(config);
// });
it('should load configuration from a specified config file', () => {
const configPath = path.resolve(__dirname, './fixtures/custom.wpmrc.js');
const config = getConfiguration(undefined, configPath);
expect(config.allowBranch).deep.equals(['custom-branch']);
});
});
3 changes: 3 additions & 0 deletions src/test/fixtures/custom.wpmrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
allowBranch: ['custom-branch']
};