From d7220acb089cfeff26b620956a2d885e3a4d4f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20=C5=BDilinskas?= Date: Tue, 11 Jul 2017 10:44:54 +0300 Subject: [PATCH 1/5] Changed from Promise to Promise. --- packages/react-forms-dom/src/contracts/form.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-forms-dom/src/contracts/form.ts b/packages/react-forms-dom/src/contracts/form.ts index 671f746..ea70b04 100644 --- a/packages/react-forms-dom/src/contracts/form.ts +++ b/packages/react-forms-dom/src/contracts/form.ts @@ -9,11 +9,11 @@ import { } from "../contracts/field"; export interface FormOnSubmitInternalCallback { - (event: React.FormEvent, ...parameters: any[]): void | Promise | FormError | string; + (event: React.FormEvent, ...parameters: any[]): void | Promise | FormError | string; } export interface FormOnSubmitCallback { - (event: React.FormEvent, store: FormStore): void | Promise | FormError | string; + (event: React.FormEvent, store: FormStore): void | Promise | FormError | string; } export interface FormProps extends CoreFormProps, React.HTMLProps { From 70cc39ace69fcc406226c15e78c9d44742c0331d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20=C5=BDilinskas?= Date: Tue, 11 Jul 2017 13:29:47 +0300 Subject: [PATCH 2/5] Updating rush-tools. --- package.json | 5 +- tools/rush-tools-new.ts | 196 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 tools/rush-tools-new.ts diff --git a/package.json b/package.json index ce63571..05e55a1 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "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", - "rush-tools": "ts-node ./tools/rush-tools.ts", + "rush-tools": "ts-node ./tools/rush-tools-new.ts", "publish": "npm run rush-tools -- publish --access public" }, "devDependencies": { @@ -19,5 +19,8 @@ "ts-node": "^3.1.0", "typescript": "^2.4.1", "yargs": "^8.0.2" + }, + "dependencies": { + "@microsoft/ts-command-line": "^2.0.2" } } diff --git a/tools/rush-tools-new.ts b/tools/rush-tools-new.ts new file mode 100644 index 0000000..c574b74 --- /dev/null +++ b/tools/rush-tools-new.ts @@ -0,0 +1,196 @@ +import * as path from "path"; +import * as shelljs from "shelljs"; + +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}`); + } +} + +// 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)); + } +} + +const cli = new RushToolsCommandLineParser(); +cli.execute(); + From aa5551f7b80652056e5e8ef6c4b7c270048a4a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20=C5=BDilinskas?= Date: Tue, 11 Jul 2017 13:51:23 +0300 Subject: [PATCH 3/5] Added semver package. And version printer. --- package.json | 4 ++- tools/rush-tools-new.ts | 80 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 05e55a1..7390927 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,8 @@ "yargs": "^8.0.2" }, "dependencies": { - "@microsoft/ts-command-line": "^2.0.2" + "@microsoft/ts-command-line": "^2.0.2", + "@types/semver": "^5.3.32", + "semver": "^5.3.0" } } diff --git a/tools/rush-tools-new.ts b/tools/rush-tools-new.ts index c574b74..1d733ef 100644 --- a/tools/rush-tools-new.ts +++ b/tools/rush-tools-new.ts @@ -1,5 +1,6 @@ import * as path from "path"; import * as shelljs from "shelljs"; +import * as semver from "semver"; import { CommandLineParser, @@ -169,6 +170,84 @@ class RushPublicAction extends BaseAction { } } +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 { @@ -188,6 +267,7 @@ class RushToolsCommandLineParser extends CommandLineParser { private populateActions(): void { this.addAction(new RushRunAction(this)); this.addAction(new RushPublicAction(this)); + this.addAction(new RushVersionsAction(this)); } } From 498b233247348683d93c8723b3df7c3eae0353a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20=C5=BDilinskas?= Date: Tue, 11 Jul 2017 13:54:10 +0300 Subject: [PATCH 4/5] Added onClick in submit button. --- packages/react-forms-dom/src/components/submit.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/react-forms-dom/src/components/submit.tsx b/packages/react-forms-dom/src/components/submit.tsx index 2f9c5c3..48751ec 100644 --- a/packages/react-forms-dom/src/components/submit.tsx +++ b/packages/react-forms-dom/src/components/submit.tsx @@ -9,8 +9,13 @@ import { BaseFormButtonProps, BaseFormButtonStateRecord } from "../abstractions/base-form-button"; +import { HTMLElementProps } from "../contracts/field"; -export type SubmitProps = BaseFormButtonProps; +export interface SubmitProps extends BaseFormButtonProps, HTMLElementProps { + fieldIds?: string[]; + + ref?: React.Ref; +} export class Submit extends BaseFormButton { public static defaultProps: BaseFormButtonProps = { @@ -23,6 +28,11 @@ export class Submit extends BaseFormButton Date: Tue, 11 Jul 2017 13:55:38 +0300 Subject: [PATCH 5/5] Reverted to old rush-tools. --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7390927..8ce8fa5 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "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", - "rush-tools": "ts-node ./tools/rush-tools-new.ts", - "publish": "npm run rush-tools -- publish --access public" + "publish": "npm run rush-tools -- publish --access public", + "rush-tools": "ts-node ./tools/rush-tools.ts" }, "devDependencies": { "@microsoft/rush": "^3.0.11",