From 9b52929280af098d2ad1492134b9c926830b4f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20=C5=BDilinskas?= Date: Wed, 12 Jul 2017 15:56:06 +0300 Subject: [PATCH 1/4] Fixed double submitting. --- packages/react-forms-dom/src/components/submit.tsx | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/react-forms-dom/src/components/submit.tsx b/packages/react-forms-dom/src/components/submit.tsx index 48751ec..d44822b 100644 --- a/packages/react-forms-dom/src/components/submit.tsx +++ b/packages/react-forms-dom/src/components/submit.tsx @@ -12,8 +12,6 @@ import { import { HTMLElementProps } from "../contracts/field"; export interface SubmitProps extends BaseFormButtonProps, HTMLElementProps { - fieldIds?: string[]; - ref?: React.Ref; } @@ -23,11 +21,9 @@ export class Submit extends BaseFormButton = event => { - // If Button is outside of Form context, initiate form submit. - if (this.props.formId !== null) { - this.FormStore.InitiateFormSubmit(); - } + protected OnClick: React.MouseEventHandler = event => { + event.preventDefault(); + this.FormStore.InitiateFormSubmit(); if (this.props.onClick != null) { event.persist(); @@ -41,7 +37,7 @@ export class Submit extends BaseFormButton {this.props.children} From 479b2962a32ff9177c364dac425ed8a21ed4a6ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20=C5=BDilinskas?= Date: Wed, 12 Jul 2017 16:08:14 +0300 Subject: [PATCH 2/4] Moved rush-tools-new to rush-tools. --- package.json | 13 +- tools/rush-tools-new.ts | 276 -------------------------------- tools/rush-tools.ts | 337 ++++++++++++++++++++++++++++------------ 3 files changed, 245 insertions(+), 381 deletions(-) delete mode 100644 tools/rush-tools-new.ts diff --git a/package.json b/package.json index 8ce8fa5..21c2a6d 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,9 @@ "private": true, "scripts": { "generate": "rush generate", - "tools-build": "npm run rush-tools -- run gulp-build -e @simplr/mvdir", - "source-build": "npm run rush-tools -- run build -e @simplr/mvdir", - "test": "npm run rush-tools -- run test -e @simplr/mvdir", + "tools-build": "npm run rush-tools -- run -s gulp-build -e @simplr/mvdir", + "source-build": "npm run rush-tools -- run -s build -e @simplr/mvdir", + "test": "npm run rush-tools -- run -s test -e @simplr/mvdir", "publish": "npm run rush-tools -- publish --access public", "rush-tools": "ts-node ./tools/rush-tools.ts" }, @@ -13,16 +13,13 @@ "@microsoft/rush": "^3.0.11", "@microsoft/rush-lib": "^3.0.11", "@types/shelljs": "^0.7.2", - "@types/yargs": "^8.0.0", "mz": "^2.6.0", "shelljs": "^0.7.8", "ts-node": "^3.1.0", "typescript": "^2.4.1", - "yargs": "^8.0.2" - }, - "dependencies": { "@microsoft/ts-command-line": "^2.0.2", "@types/semver": "^5.3.32", "semver": "^5.3.0" - } + }, + "dependencies": {} } diff --git a/tools/rush-tools-new.ts b/tools/rush-tools-new.ts deleted file mode 100644 index 1d733ef..0000000 --- a/tools/rush-tools-new.ts +++ /dev/null @@ -1,276 +0,0 @@ -import * as path from "path"; -import * as shelljs from "shelljs"; -import * as semver from "semver"; - -import { - CommandLineParser, - CommandLineFlagParameter, - CommandLineAction, - CommandLineStringListParameter, - CommandLineStringParameter -} from "@microsoft/ts-command-line"; - -import { RushConfiguration } from "@microsoft/rush-lib"; - -// Tasks - -class ShellTask { - constructor(private rushConfiguration: RushConfiguration, private projects: string[]) { } - - public Execute(command: string): void { - this.consoleWrite(`Starting: ${command}`); - - const failedProjects: string[] = []; - const succeededProjects: string[] = []; - - for (const projectName of this.projects) { - const project = this.rushConfiguration.getProjectByName(projectName); - - shelljs.cd(project.projectFolder); - this.consoleBox(`Package name: ${projectName}`); - - const result = shelljs.exec(command); - - if (result.code === 0) { - succeededProjects.push(projectName); - } else { - failedProjects.push(projectName); - } - } - - if (succeededProjects.length > 0) { - this.consoleBox(`Succeeded projects ${succeededProjects.length}`); - for (const project of succeededProjects) { - this.consoleWrite(project); - } - } - - if (failedProjects.length > 0) { - this.consoleBox(`Failed projects ${failedProjects.length}`); - for (const project of failedProjects) { - this.consoleWrite(project); - } - process.exit(1); - } - } - - private consoleWrite(...text: string[]): void { - console.info(text.join(" ")); - } - - private consoleBox(message: string): void { - this.consoleWrite("===================================="); - this.consoleWrite(message); - this.consoleWrite("===================================="); - } -} - -// Actions - -const defaultRushJsonFile = "rush.json"; - -abstract class BaseAction extends CommandLineAction { - protected RushConfiguration: RushConfiguration; - - protected onExecute(): void { - if (this.RushConfiguration == null) { - this.RushConfiguration = RushConfiguration.loadFromDefaultLocation(); - } - this.run(); - } - - protected abstract run(): void; -} - -class RushRunAction extends BaseAction { - private parser: RushToolsCommandLineParser; - - private excluded: CommandLineStringListParameter; - private script: CommandLineStringParameter; - - constructor(parser: RushToolsCommandLineParser) { - super({ - actionVerb: "run", - summary: "Runs scripts to all projects", - documentation: "Runs scripts to all projects" - }); - this.parser = parser; - } - - protected onDefineParameters(): void { - this.excluded = this.defineStringListParameter({ - parameterShortName: "-e", - parameterLongName: "--exclude", - description: "List of excluded project names" - }); - - this.script = this.defineStringParameter({ - parameterShortName: "-s", - parameterLongName: "--script", - description: "Name of script that will be run in projects" - }); - } - - protected run(): void { - if (this.script.value == null) { - console.error("[RUN] Please specify script name with --script/-s parameter."); - process.exit(1); - } - - const excludedProjects = this.excluded.value; - const projects = this.RushConfiguration - .projects - .map(x => x.packageName) - .filter(x => excludedProjects.indexOf(x) === -1); - - const task = new ShellTask(this.RushConfiguration, projects); - task.Execute(`npm run ${this.script.value}`); - } -} - -class RushPublicAction extends BaseAction { - private parser: RushToolsCommandLineParser; - - private excluded: CommandLineStringListParameter; - private access: CommandLineStringParameter; - - constructor(parser: RushToolsCommandLineParser) { - super({ - actionVerb: "publish", - summary: "Runs publish script on all projects", - documentation: "Runs publish script on all projects" - }); - this.parser = parser; - } - - protected onDefineParameters(): void { - this.excluded = this.defineStringListParameter({ - parameterShortName: "-e", - parameterLongName: "--exclude", - description: "List of excluded project names" - }); - - this.access = this.defineStringParameter({ - parameterLongName: "--access", - description: "Publish package to public/private" - }); - } - - protected run(): void { - const excludedProjects = this.excluded.value || []; - const projects = this.RushConfiguration - .projects - .filter(x => x.shouldPublish) - .map(x => x.packageName) - .filter(x => excludedProjects.indexOf(x) === -1); - - const task = new ShellTask(this.RushConfiguration, projects); - const access = this.access.value != null ? `--access ${this.access.value}` : ""; - task.Execute(`npm publish ${access}`); - } -} - -class RushVersionsAction extends BaseAction { - private parser: RushToolsCommandLineParser; - private publishOnly: CommandLineFlagParameter; - - constructor(parser: RushToolsCommandLineParser) { - super({ - actionVerb: "versions", - summary: "Prints list of projects versions", - documentation: "Prints list of projects versions" - }); - this.parser = parser; - } - - protected onDefineParameters(): void { - this.publishOnly = this.defineFlagParameter({ - parameterLongName: "--publishOnly", - description: "List only for publish" - }); - } - - protected run(): void { - const { projects } = this.RushConfiguration; - const publishOnly = this.publishOnly.value; - - console.info(`Projects: ${projects.length}`); - console.info("======================================"); - for (const project of projects) { - if (publishOnly && !project.shouldPublish) { - continue; - } - console.info(`${project.packageName}@${project.packageJson.version}`); - } - } -} - -class RushBumpAction extends BaseAction { - private parser: RushToolsCommandLineParser; - - private excluded: CommandLineStringListParameter; - private increment: CommandLineStringParameter; - - constructor(parser: RushToolsCommandLineParser) { - super({ - actionVerb: "bump", - summary: "Bumps versions to all projects that have shouldPublish", - documentation: "Bumps versions to all projects that have shouldPublish" - }); - this.parser = parser; - } - - protected onDefineParameters(): void { - this.excluded = this.defineStringListParameter({ - parameterShortName: "-e", - parameterLongName: "--exclude", - description: "List of excluded project names" - }); - - this.increment = this.defineStringParameter({ - parameterShortName: "-i", - parameterLongName: "--inc", - description: "Release type: major, premajor, minor, preminor, patch, prepatch, or prerelease." - }); - } - - protected run(): void { - if (this.increment.value == null) { - console.error("[BUMP] Please specify bump type: major, premajor, minor, preminor, patch, prepatch, or prerelease."); - process.exit(1); - } - - - - const excludedProjects = this.excluded.value || []; - } - - -} - -// CLI - -class RushToolsCommandLineParser extends CommandLineParser { - constructor() { - super({ - toolFilename: "rush-tools", - toolDescription: "Rush tools for rush single repo tool" - }); - - this.populateActions(); - } - - protected onDefineParameters(): void { - // Abstract - } - - private populateActions(): void { - this.addAction(new RushRunAction(this)); - this.addAction(new RushPublicAction(this)); - this.addAction(new RushVersionsAction(this)); - } -} - -const cli = new RushToolsCommandLineParser(); -cli.execute(); - diff --git a/tools/rush-tools.ts b/tools/rush-tools.ts index 537b826..63a9e3a 100644 --- a/tools/rush-tools.ts +++ b/tools/rush-tools.ts @@ -1,129 +1,272 @@ -import * as shelljs from "shelljs"; import * as path from "path"; +import * as shelljs from "shelljs"; +import * as semver from "semver"; + +import { + CommandLineParser, + CommandLineFlagParameter, + CommandLineAction, + CommandLineStringListParameter, + CommandLineStringParameter +} from "@microsoft/ts-command-line"; + import { RushConfiguration } from "@microsoft/rush-lib"; -import * as yargs from "yargs"; -const version = "0.1.0"; -const defaultRushJsonFile = "rush.json"; +// Tasks + +class ShellTask { + constructor(private rushConfiguration: RushConfiguration, private projects: string[]) { } -class RushTools { - private rushConfiguration: RushConfiguration; + public Execute(command: string): void { + console.info(`Starting: ${command}`); - constructor(args: ArgumentsValues) { - const rushConfigurationPath = path.resolve(process.cwd(), args.config); - this.rushConfiguration = RushConfiguration.loadFromConfigurationFile(rushConfigurationPath); + const failedProjects: string[] = []; + const succeededProjects: string[] = []; - if (args.run) { - this.runScript(`npm run ${args.script}`, args.exclude); - } else if (args.publish) { - const excludedPackages: string[] = args.exclude != null ? args.exclude : []; - const { projects } = this.rushConfiguration; + for (const projectName of this.projects) { + const project = this.rushConfiguration.getProjectByName(projectName); - for (const project of projects) { - if (!project.shouldPublish) { - excludedPackages.push(project.packageName); - } + shelljs.cd(project.projectFolder); + this.consoleBox(`Package name: ${projectName}`); + + const result = shelljs.exec(command); + + if (result.code === 0) { + succeededProjects.push(projectName); + } else { + failedProjects.push(projectName); } + } - const access = args.access != null ? `--access ${args.access}` : ""; - this.runScript(`npm publish ${access}`, excludedPackages); + if (succeededProjects.length > 0) { + this.consoleBox(`Succeeded projects ${succeededProjects.length}`); + for (const project of succeededProjects) { + console.info(project); + } + } + + if (failedProjects.length > 0) { + this.consoleBox(`Failed projects ${failedProjects.length}`); + for (const project of failedProjects) { + console.info(project); + } + process.exit(1); } } - private runScript(command: string, excludePackageNames?: string[]): void { - const { projects } = this.rushConfiguration; + private consoleBox(message: string): void { + console.info("===================================="); + console.info(message); + console.info("===================================="); + } +} - const failedPackages: string[] = []; +// Actions - for (const project of projects) { - // Skip package if it is in excluded list. - if (excludePackageNames != null && - excludePackageNames.indexOf(project.packageName) !== -1) { - continue; - } - shelljs.cd(project.projectFolder); - console.info("===================================="); - console.info(`Package name: ${project.packageName}`); - console.info("===================================="); - const result = shelljs.exec(command); +const defaultRushJsonFile = "rush.json"; - if (result.code !== 0) { - failedPackages.push(project.packageName); - } +abstract class BaseAction extends CommandLineAction { + protected RushConfiguration: RushConfiguration; + + protected onExecute(): void { + if (this.RushConfiguration == null) { + this.RushConfiguration = RushConfiguration.loadFromDefaultLocation(); } + this.run(); + } - if (failedPackages.length > 0) { - console.info("==================================="); - console.info(`Failed packages: ${failedPackages.length}`); - console.info("==================================="); - for (const failedPackage of failedPackages) { - console.info(failedPackage); - } + protected abstract run(): void; +} +class RushRunAction extends BaseAction { + private parser: RushToolsCommandLineParser; + + private excluded: CommandLineStringListParameter; + private script: CommandLineStringParameter; + + constructor(parser: RushToolsCommandLineParser) { + super({ + actionVerb: "run", + summary: "Runs scripts to all projects", + documentation: "Runs scripts to all projects" + }); + this.parser = parser; + } + + protected onDefineParameters(): void { + this.excluded = this.defineStringListParameter({ + parameterShortName: "-e", + parameterLongName: "--exclude", + description: "List of excluded project names" + }); + + this.script = this.defineStringParameter({ + parameterShortName: "-s", + parameterLongName: "--script", + description: "Name of script that will be run in projects" + }); + } + + protected run(): void { + if (this.script.value == null) { + console.error("[RUN] Please specify script name with --script/-s parameter."); process.exit(1); } + + const excludedProjects = this.excluded.value; + const projects = this.RushConfiguration + .projects + .map(x => x.packageName) + .filter(x => excludedProjects.indexOf(x) === -1); + + const task = new ShellTask(this.RushConfiguration, projects); + task.Execute(`npm run ${this.script.value}`); } } -interface ArgumentsValues extends yargs.Arguments { - config: string; - exclude: string[]; +class RushPublicAction extends BaseAction { + private parser: RushToolsCommandLineParser; + + private excluded: CommandLineStringListParameter; + private access: CommandLineStringParameter; + + constructor(parser: RushToolsCommandLineParser) { + super({ + actionVerb: "publish", + summary: "Runs publish script on all projects", + documentation: "Runs publish script on all projects" + }); + this.parser = parser; + } + + protected onDefineParameters(): void { + this.excluded = this.defineStringListParameter({ + parameterShortName: "-e", + parameterLongName: "--exclude", + description: "List of excluded project names" + }); + + this.access = this.defineStringParameter({ + parameterLongName: "--access", + description: "Publish package to public/private" + }); + } - run: boolean; - script: string; + protected run(): void { + const excludedProjects = this.excluded.value || []; + const projects = this.RushConfiguration + .projects + .filter(x => x.shouldPublish) + .map(x => x.packageName) + .filter(x => excludedProjects.indexOf(x) === -1); - publish: boolean; - access: string; + const task = new ShellTask(this.RushConfiguration, projects); + const access = this.access.value != null ? `--access ${this.access.value}` : ""; + task.Execute(`npm publish ${access}`); + } } -const argv = yargs - .help("h", "Show help.") - .alias("h", "help") - .version(() => `Current version: ${version}.`) - .alias("v", "version") - .option("c", { - alias: "config", - describe: "Relative path to rush config", - type: "string", - default: path.relative(process.cwd(), defaultRushJsonFile) - }) - .option("e", { - alias: "exclude", - describe: "Excluding package names list", - type: "array" - }) - .command( - "run", - "Run package.json script", - yargs => yargs, - argvObj => { - const args: string[] = argvObj._; - - const filteredArgs = args.map(arg => { - if (arg.length > 0 && arg[0] === "-") { - return false; +class RushVersionsAction extends BaseAction { + private parser: RushToolsCommandLineParser; + private publishOnly: CommandLineFlagParameter; + + constructor(parser: RushToolsCommandLineParser) { + super({ + actionVerb: "versions", + summary: "Prints list of projects versions", + documentation: "Prints list of projects versions" + }); + this.parser = parser; + } + + protected onDefineParameters(): void { + this.publishOnly = this.defineFlagParameter({ + parameterLongName: "--publishOnly", + description: "List only for publish" + }); + } + + protected run(): void { + const { projects } = this.RushConfiguration; + const publishOnly = this.publishOnly.value; + + console.info(`Projects: ${projects.length}`); + console.info("======================================"); + for (const project of projects) { + if (publishOnly && !project.shouldPublish) { + continue; } - return arg; + console.info(`${project.packageName}@${project.packageJson.version}`); + } + } +} + +class RushBumpAction extends BaseAction { + private parser: RushToolsCommandLineParser; + + private excluded: CommandLineStringListParameter; + private increment: CommandLineStringParameter; + + constructor(parser: RushToolsCommandLineParser) { + super({ + actionVerb: "bump", + summary: "Bumps versions to all projects that have shouldPublish", + documentation: "Bumps versions to all projects that have shouldPublish" + }); + this.parser = parser; + } + + protected onDefineParameters(): void { + this.excluded = this.defineStringListParameter({ + parameterShortName: "-e", + parameterLongName: "--exclude", + description: "List of excluded project names" + }); + + this.increment = this.defineStringParameter({ + parameterShortName: "-i", + parameterLongName: "--inc", + description: "Release type: major, premajor, minor, preminor, patch, prepatch, or prerelease." }); - const script = filteredArgs.slice(1, filteredArgs.length).join(" "); + } - if (script.length === 0) { - throw Error("rush-tools: Script name is required"); + protected run(): void { + if (this.increment.value == null) { + console.error("[BUMP] Please specify bump type: major, premajor, minor, preminor, patch, prepatch, or prerelease."); + process.exit(1); } - argvObj.run = true; - argvObj.script = script; - }) - .command( - "publish", - "Publish projects", - yargs => yargs.option("access", { - type: "string" - }), - argvObj => { - argvObj.publish = true; - }) - .demandCommand(1, "You need run a command") - .argv as ArgumentsValues; - -new RushTools(argv); + + + const excludedProjects = this.excluded.value || []; + } + + +} + +// CLI + +class RushToolsCommandLineParser extends CommandLineParser { + constructor() { + super({ + toolFilename: "rush-tools", + toolDescription: "Rush tools for rush single repo tool" + }); + + this.populateActions(); + } + + protected onDefineParameters(): void { + // Abstract + } + + private populateActions(): void { + this.addAction(new RushRunAction(this)); + this.addAction(new RushPublicAction(this)); + this.addAction(new RushVersionsAction(this)); + } +} + +const cli = new RushToolsCommandLineParser(); +cli.execute(); + From 528977d54fdec0f6946a4292a3bcd88d7061ef80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20=C5=BDilinskas?= Date: Wed, 12 Jul 2017 16:37:16 +0300 Subject: [PATCH 3/4] Updated scripts in package.json and travis. --- .travis.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 822abc0..0deb2a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ notifications: node_js: - stable script: -- npm run generate +- npm run rush-install - npm run tools-build - npm run source-build - npm test diff --git a/package.json b/package.json index 21c2a6d..0e2d6bc 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@simplr/react-forms-repo", "private": true, "scripts": { - "generate": "rush generate", + "rush-install": "rush install", "tools-build": "npm run rush-tools -- run -s gulp-build -e @simplr/mvdir", "source-build": "npm run rush-tools -- run -s build -e @simplr/mvdir", "test": "npm run rush-tools -- run -s test -e @simplr/mvdir", From 32014116855b3cd9c95e0ca966e0654bb7c55bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20=C5=BDilinskas?= Date: Wed, 12 Jul 2017 17:48:07 +0300 Subject: [PATCH 4/4] Removed rushBumptask. --- tools/rush-tools.ts | 44 -------------------------------------------- 1 file changed, 44 deletions(-) diff --git a/tools/rush-tools.ts b/tools/rush-tools.ts index 63a9e3a..9323db5 100644 --- a/tools/rush-tools.ts +++ b/tools/rush-tools.ts @@ -201,49 +201,6 @@ class RushVersionsAction extends BaseAction { } } -class RushBumpAction extends BaseAction { - private parser: RushToolsCommandLineParser; - - private excluded: CommandLineStringListParameter; - private increment: CommandLineStringParameter; - - constructor(parser: RushToolsCommandLineParser) { - super({ - actionVerb: "bump", - summary: "Bumps versions to all projects that have shouldPublish", - documentation: "Bumps versions to all projects that have shouldPublish" - }); - this.parser = parser; - } - - protected onDefineParameters(): void { - this.excluded = this.defineStringListParameter({ - parameterShortName: "-e", - parameterLongName: "--exclude", - description: "List of excluded project names" - }); - - this.increment = this.defineStringParameter({ - parameterShortName: "-i", - parameterLongName: "--inc", - description: "Release type: major, premajor, minor, preminor, patch, prepatch, or prerelease." - }); - } - - protected run(): void { - if (this.increment.value == null) { - console.error("[BUMP] Please specify bump type: major, premajor, minor, preminor, patch, prepatch, or prerelease."); - process.exit(1); - } - - - - const excludedProjects = this.excluded.value || []; - } - - -} - // CLI class RushToolsCommandLineParser extends CommandLineParser { @@ -269,4 +226,3 @@ class RushToolsCommandLineParser extends CommandLineParser { const cli = new RushToolsCommandLineParser(); cli.execute(); -