File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+ // See LICENSE in the project root for license information.
3+
4+ import { CommandLineAction } from '@microsoft/ts-command-line' ;
5+ import { RushStackCommandLine } from './RushStackCommandLine' ;
6+ import { BasicTasks } from '../logic/BasicTasks' ;
7+ import { BuildContext } from '../logic/BuildContext' ;
8+
9+ export class CleanAction extends CommandLineAction {
10+ constructor ( parser : RushStackCommandLine ) {
11+ super ( {
12+ actionVerb : 'clean' ,
13+ summary : 'Delete all the intermediary files created during a build' ,
14+ documentation : ''
15+ } ) ;
16+ }
17+
18+ protected onDefineParameters ( ) : void { // override
19+ }
20+
21+ protected onExecute ( ) : Promise < void > { // override
22+ console . log ( 'Cleaning' ) ;
23+
24+ const buildContext : BuildContext = new BuildContext ( ) ;
25+
26+ BasicTasks . doClean ( buildContext ) ;
27+
28+ return Promise . resolve ( ) ;
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+ // See LICENSE in the project root for license information.
3+
4+ import { CommandLineParser } from '@microsoft/ts-command-line' ;
5+
6+ import { CleanAction } from './CleanAction' ;
7+
8+ export class RushStackCommandLine extends CommandLineParser {
9+ constructor ( ) {
10+ super ( {
11+ toolFilename : 'rush-stack' ,
12+ toolDescription : 'The professional quality TypeScript build rig that\'s complete, integrated, and scalable'
13+ } ) ;
14+ this . _populateActions ( ) ;
15+ }
16+
17+ protected onDefineParameters ( ) : void { // override
18+ // No parameters
19+ }
20+
21+ private _populateActions ( ) : void {
22+ this . addAction ( new CleanAction ( this ) ) ;
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+ // See LICENSE in the project root for license information.
3+
4+ import { BuildContext } from './BuildContext' ;
5+
6+ export class BasicTasks {
7+ public static doClean ( buildContext : BuildContext ) : void {
8+ console . log ( `Project folder is: "${ buildContext . projectFolder } "` ) ;
9+ }
10+ }
Original file line number Diff line number Diff line change 1+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+ // See LICENSE in the project root for license information.
3+
4+ import { PackageJsonLookup } from '@microsoft/node-core-library' ;
5+
6+ export interface IBuildContextParameters {
7+ /**
8+ * If unspecified, then process.cwd() is used.
9+ */
10+ currentWorkingDirectory ?: string ;
11+ }
12+
13+ export class BuildContext {
14+ public readonly packageJsonLookup : PackageJsonLookup = new PackageJsonLookup ( ) ;
15+
16+ /**
17+ * The absolute path to the folder containing package.json for the project
18+ * that we're building.
19+ * Example: "C:\MyRepo\project-1"
20+ */
21+ public readonly projectFolder : string ;
22+
23+ public constructor ( parameters ?: IBuildContextParameters ) {
24+ let currentWorkingDirectory : string = process . cwd ( ) ;
25+ if ( parameters ) {
26+ if ( parameters . currentWorkingDirectory ) {
27+ currentWorkingDirectory = parameters . currentWorkingDirectory ;
28+ }
29+ }
30+ const projectFolder : string | undefined = this . packageJsonLookup
31+ . tryGetPackageFolderFor ( currentWorkingDirectory ) ;
32+ if ( ! projectFolder ) {
33+ throw new Error ( 'Unable to find a package.json for the current folder: ' + currentWorkingDirectory ) ;
34+ }
35+ this . projectFolder = projectFolder ;
36+ }
37+ }
Original file line number Diff line number Diff line change @@ -5,10 +5,16 @@ import * as os from 'os';
55import * as colors from 'colors' ;
66import * as path from 'path' ;
77
8+ import { RushStackCommandLine } from './cli/RushStackCommandLine' ;
9+
810const myPackageJsonFilename : string = path . resolve ( path . join (
911 __dirname , '..' , 'package.json' )
1012) ;
1113const myPackageJson : { version : string } = require ( myPackageJsonFilename ) ;
1214
1315console . log ( os . EOL + colors . bold ( `rush-stack ${ myPackageJson . version } `
1416 + colors . cyan ( ' - http://rushstack.io' ) + os . EOL ) ) ;
17+
18+ const parser : RushStackCommandLine = new RushStackCommandLine ( ) ;
19+
20+ parser . execute ( ) ;
You can’t perform that action at this time.
0 commit comments