@pnp/cli-microsoft365 6.11.0-beta.1b96aef → 6.11.0-beta.2d03676

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.workflow = void 0;
4
+ exports.workflow = {
5
+ name: "Deploy Solution {{ name }}",
6
+ on: {
7
+ push: {
8
+ branches: [
9
+ "main"
10
+ ]
11
+ }
12
+ },
13
+ jobs: {
14
+ "build-and-deploy": {
15
+ "runs-on": "ubuntu-latest",
16
+ steps: [
17
+ {
18
+ name: "Checkout",
19
+ uses: "actions/checkout@v3.5.3"
20
+ },
21
+ {
22
+ name: "Use Node.js 16.x",
23
+ uses: "actions/setup-node@v3.7.0",
24
+ with: {
25
+ "node-version": "16.x"
26
+ }
27
+ },
28
+ {
29
+ name: "Run npm ci",
30
+ run: "npm ci"
31
+ },
32
+ {
33
+ name: "Bundle & Package",
34
+ run: "gulp bundle --ship\ngulp package-solution --ship\n"
35
+ },
36
+ {
37
+ name: "CLI for Microsoft 365 Login",
38
+ uses: "pnp/action-cli-login@v2.2.2",
39
+ with: {
40
+ "CERTIFICATE_ENCODED": "${{ secrets.CERTIFICATE_ENCODED }}",
41
+ "CERTIFICATE_PASSWORD": "${{ secrets.CERTIFICATE_PASSWORD }}",
42
+ "APP_ID": "${{ secrets.APP_ID }}"
43
+ }
44
+ },
45
+ {
46
+ name: "CLI for Microsoft 365 Deploy App",
47
+ uses: "pnp/action-cli-deploy@v3.0.1",
48
+ with: {
49
+ "APP_FILE_PATH": "sharepoint/solution/{{ solutionName }}.sppkg",
50
+ "SKIP_FEATURE_DEPLOYMENT": false,
51
+ "OVERWRITE": false
52
+ }
53
+ }
54
+ ]
55
+ }
56
+ }
57
+ };
58
+ //# sourceMappingURL=DeployWorkflow.js.map
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var _SpfxProjectGithubWorkflowAddCommand_instances, _SpfxProjectGithubWorkflowAddCommand_initTelemetry, _SpfxProjectGithubWorkflowAddCommand_initOptions, _SpfxProjectGithubWorkflowAddCommand_initValidators;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const fs = require("fs");
19
+ const path = require("path");
20
+ const yaml = require("yaml");
21
+ const Command_1 = require("../../../../Command");
22
+ const fsUtil_1 = require("../../../../utils/fsUtil");
23
+ const validation_1 = require("../../../../utils/validation");
24
+ const commands_1 = require("../../commands");
25
+ const DeployWorkflow_1 = require("./DeployWorkflow");
26
+ const base_project_command_1 = require("./base-project-command");
27
+ class SpfxProjectGithubWorkflowAddCommand extends base_project_command_1.BaseProjectCommand {
28
+ get name() {
29
+ return commands_1.default.PROJECT_GITHUB_WORKFLOW_ADD;
30
+ }
31
+ get description() {
32
+ return 'Adds a GitHub workflow for a SharePoint Framework project.';
33
+ }
34
+ constructor() {
35
+ super();
36
+ _SpfxProjectGithubWorkflowAddCommand_instances.add(this);
37
+ __classPrivateFieldGet(this, _SpfxProjectGithubWorkflowAddCommand_instances, "m", _SpfxProjectGithubWorkflowAddCommand_initTelemetry).call(this);
38
+ __classPrivateFieldGet(this, _SpfxProjectGithubWorkflowAddCommand_instances, "m", _SpfxProjectGithubWorkflowAddCommand_initOptions).call(this);
39
+ __classPrivateFieldGet(this, _SpfxProjectGithubWorkflowAddCommand_instances, "m", _SpfxProjectGithubWorkflowAddCommand_initValidators).call(this);
40
+ }
41
+ commandAction(logger, args) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ this.projectRootPath = this.getProjectRoot(process.cwd());
44
+ if (this.projectRootPath === null) {
45
+ throw new Command_1.CommandError(`Couldn't find project root folder`, SpfxProjectGithubWorkflowAddCommand.ERROR_NO_PROJECT_ROOT_FOLDER);
46
+ }
47
+ const solutionPackageJsonFile = path.join(this.projectRootPath, 'package.json');
48
+ const packageJson = fs.readFileSync(solutionPackageJsonFile, 'utf-8');
49
+ const solutionName = JSON.parse(packageJson).name;
50
+ if (this.debug) {
51
+ logger.logToStderr(`Adding GitHub workflow in the current SPFx project`);
52
+ }
53
+ try {
54
+ this.updateWorkflow(solutionName, DeployWorkflow_1.workflow, args.options);
55
+ this.saveWorkflow(DeployWorkflow_1.workflow);
56
+ }
57
+ catch (error) {
58
+ throw new Command_1.CommandError(error);
59
+ }
60
+ });
61
+ }
62
+ saveWorkflow(workflow) {
63
+ const githubPath = path.join(this.projectRootPath, '.github');
64
+ fsUtil_1.fsUtil.ensureDirectory(githubPath);
65
+ const workflowPath = path.join(githubPath, 'workflows');
66
+ fsUtil_1.fsUtil.ensureDirectory(workflowPath);
67
+ const workflowFile = path.join(workflowPath, 'deploy-spfx-solution.yml');
68
+ fs.writeFileSync(path.resolve(workflowFile), yaml.stringify(workflow), 'utf-8');
69
+ }
70
+ updateWorkflow(solutionName, workflow, options) {
71
+ var _a;
72
+ workflow.name = workflow.name.replace('{{ name }}', (_a = options.name) !== null && _a !== void 0 ? _a : solutionName);
73
+ if (options.branchName) {
74
+ workflow.on.push.branches[0] = options.branchName;
75
+ }
76
+ if (options.manuallyTrigger) {
77
+ // eslint-disable-next-line camelcase
78
+ workflow.on.workflow_dispatch = null;
79
+ }
80
+ if (options.skipFeatureDeployment) {
81
+ this.getDeployAction(workflow).with.SKIP_FEATURE_DEPLOYMENT = true;
82
+ }
83
+ if (options.overwrite) {
84
+ this.getDeployAction(workflow).with.OVERWRITE = true;
85
+ }
86
+ if (options.loginMethod === 'user') {
87
+ const loginAction = this.getLoginAction(workflow);
88
+ loginAction.with = {
89
+ ADMIN_USERNAME: '${{ secrets.ADMIN_USERNAME }}',
90
+ ADMIN_PASSWORD: '${{ secrets.ADMIN_PASSWORD }}'
91
+ };
92
+ }
93
+ if (options.scope === 'sitecollection') {
94
+ const deployAction = this.getDeployAction(workflow);
95
+ deployAction.with.SCOPE = 'sitecollection';
96
+ deployAction.with.SITE_COLLECTION_URL = options.siteUrl;
97
+ }
98
+ if (solutionName) {
99
+ const deployAction = this.getDeployAction(workflow);
100
+ deployAction.with.APP_FILE_PATH = deployAction.with.APP_FILE_PATH.replace('{{ solutionName }}', solutionName);
101
+ }
102
+ }
103
+ getLoginAction(workflow) {
104
+ const steps = this.getWorkFlowSteps(workflow);
105
+ return steps.find(step => step.uses && step.uses.indexOf('action-cli-login') >= 0);
106
+ }
107
+ getDeployAction(workflow) {
108
+ const steps = this.getWorkFlowSteps(workflow);
109
+ return steps.find(step => step.uses && step.uses.indexOf('action-cli-deploy') >= 0);
110
+ }
111
+ getWorkFlowSteps(workflow) {
112
+ return workflow.jobs['build-and-deploy'].steps;
113
+ }
114
+ }
115
+ _SpfxProjectGithubWorkflowAddCommand_instances = new WeakSet(), _SpfxProjectGithubWorkflowAddCommand_initTelemetry = function _SpfxProjectGithubWorkflowAddCommand_initTelemetry() {
116
+ this.telemetry.push((args) => {
117
+ Object.assign(this.telemetryProperties, {
118
+ name: typeof args.options.name !== 'undefined',
119
+ branchName: typeof args.options.branchName !== 'undefined',
120
+ manuallyTrigger: !!args.options.manuallyTrigger,
121
+ loginMethod: typeof args.options.loginMethod !== 'undefined',
122
+ scope: typeof args.options.scope !== 'undefined',
123
+ skipFeatureDeployment: !!args.options.skipFeatureDeployment,
124
+ overwrite: !!args.options.overwrite
125
+ });
126
+ });
127
+ }, _SpfxProjectGithubWorkflowAddCommand_initOptions = function _SpfxProjectGithubWorkflowAddCommand_initOptions() {
128
+ this.options.unshift({
129
+ option: '-n, --name [name]'
130
+ }, {
131
+ option: '-b, --branchName [branchName]'
132
+ }, {
133
+ option: '-m, --manuallyTrigger'
134
+ }, {
135
+ option: '-l, --loginMethod [loginMethod]',
136
+ autocomplete: SpfxProjectGithubWorkflowAddCommand.loginMethod
137
+ }, {
138
+ option: '-s, --scope [scope]',
139
+ autocomplete: SpfxProjectGithubWorkflowAddCommand.scope
140
+ }, {
141
+ option: '-u, --siteUrl [siteUrl]'
142
+ }, {
143
+ option: '--skipFeatureDeployment'
144
+ }, {
145
+ option: '--overwrite'
146
+ });
147
+ }, _SpfxProjectGithubWorkflowAddCommand_initValidators = function _SpfxProjectGithubWorkflowAddCommand_initValidators() {
148
+ this.validators.push((args) => __awaiter(this, void 0, void 0, function* () {
149
+ if (args.options.scope && args.options.scope === 'sitecollection') {
150
+ if (!args.options.siteUrl) {
151
+ return `siteUrl option has to be defined when scope set to ${args.options.scope}`;
152
+ }
153
+ const isValidSharePointUrl = validation_1.validation.isValidSharePointUrl(args.options.siteUrl);
154
+ if (isValidSharePointUrl !== true) {
155
+ return isValidSharePointUrl;
156
+ }
157
+ }
158
+ if (args.options.loginMethod && SpfxProjectGithubWorkflowAddCommand.loginMethod.indexOf(args.options.loginMethod) < 0) {
159
+ return `${args.options.loginMethod} is not a valid login method. Allowed values are ${SpfxProjectGithubWorkflowAddCommand.loginMethod.join(', ')}`;
160
+ }
161
+ if (args.options.scope && SpfxProjectGithubWorkflowAddCommand.scope.indexOf(args.options.scope) < 0) {
162
+ return `${args.options.scope} is not a valid scope. Allowed values are ${SpfxProjectGithubWorkflowAddCommand.scope.join(', ')}`;
163
+ }
164
+ return true;
165
+ }));
166
+ };
167
+ SpfxProjectGithubWorkflowAddCommand.loginMethod = ['application', 'user'];
168
+ SpfxProjectGithubWorkflowAddCommand.scope = ['tenant', 'sitecollection'];
169
+ SpfxProjectGithubWorkflowAddCommand.ERROR_NO_PROJECT_ROOT_FOLDER = 1;
170
+ module.exports = new SpfxProjectGithubWorkflowAddCommand();
171
+ //# sourceMappingURL=project-github-workflow-add.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=project-github-workflow-model.js.map
@@ -6,6 +6,7 @@ exports.default = {
6
6
  PACKAGE_GENERATE: `${prefix} package generate`,
7
7
  PROJECT_DOCTOR: `${prefix} project doctor`,
8
8
  PROJECT_EXTERNALIZE: `${prefix} project externalize`,
9
+ PROJECT_GITHUB_WORKFLOW_ADD: `${prefix} project github workflow add`,
9
10
  PROJECT_PERMISSIONS_GRANT: `${prefix} project permissions grant`,
10
11
  PROJECT_RENAME: `${prefix} project rename`,
11
12
  PROJECT_UPGRADE: `${prefix} project upgrade`
@@ -99,6 +99,11 @@ exports.fsUtil = {
99
99
  },
100
100
  getRemoveCommand(command, shell) {
101
101
  return removeFileCommands[shell][command];
102
+ },
103
+ ensureDirectory(path) {
104
+ if (!fs.existsSync(path)) {
105
+ fs.mkdirSync(path, { recursive: true });
106
+ }
102
107
  }
103
108
  };
104
109
  //# sourceMappingURL=fsUtil.js.map
@@ -0,0 +1,94 @@
1
+ import Global from '/docs/cmd/_global.mdx';
2
+
3
+ # spfx project github workflow add
4
+
5
+ Adds a GitHub workflow for a SharePoint Framework project
6
+
7
+ ## Usage
8
+
9
+ ```sh
10
+ m365 spfx project github workflow add [options]
11
+ ```
12
+
13
+ ## Options
14
+
15
+ ```md definition-list
16
+ `-n, --name [name]`
17
+ : Name of the workflow that will be created. If none is specified a default name will be used 'Deploy Solution ${name of sppkg file}'
18
+
19
+ `-b, --branchName [branchName]`
20
+ : Specify the branch name which should trigger the workflow on push. If none is specified a default will be used which is 'main'
21
+
22
+ `-m, --manuallyTrigger`
23
+ : When specified a manual trigger option will be added to the workflow: `workflow_dispatch`
24
+
25
+ `-l, --loginMethod [loginMethod]`
26
+ : Specify the login method used for the login action. Possible options are: `user`, `application`. Default `application`'
27
+
28
+ `-s, --scope [scope]`
29
+ : Scope of the app catalog: `tenant`, `sitecollection`. Default is `tenant`
30
+
31
+ `-u, --siteUrl [siteUrl]`
32
+ : The URL of the site collection where the solution package will be added. Required if scope is set to `sitecollection`
33
+
34
+ `--skipFeatureDeployment`
35
+ : When specified and the app supports tenant-wide deployment, deploy it to the whole tenant
36
+
37
+ `--overwrite`
38
+ : When specified the workflow will overwrite the existing .sppkg if it is already deployed in the app catalog.
39
+ ```
40
+
41
+ <Global />
42
+
43
+ ## Remarks
44
+
45
+ The `spfx project github workflow add` will create a workflow .yml file in the `.github/workflows` directory in your project. If such directory does not exist the command will automatically create it.
46
+
47
+ For the `application` login method the command does not register AAD application nor create the required certificate. In order for you to proceed you will need to first obtain (create) a self-signed certificate and register a new AAD application with certificate authentication. After that in GitHub repo settings, you will need to create the following secrets:
48
+
49
+ - `APP_ID` - client id of the registered AAD application
50
+ - `CERTIFICATE_ENCODED` - application's encoded certificate
51
+ - `CERTIFICATE_PASSWORD` - certificate password. This applies only if the certificate is encoded which is the recommended approach
52
+
53
+ This use case is perfect in a production context as it does not create any dependencies on an account
54
+
55
+ For the `user` login method you will need to create the following secrets in GitHub repo settings:
56
+
57
+ - `ADMIN_USERNAME` - username
58
+ - `ADMIN_PASSWORD` - password
59
+
60
+ This method is perfect to test your workflow, in a dev context, for personal usage. It will not work for accounts with MFA.
61
+
62
+ :::info
63
+
64
+ Run this command in the SPFx solution folder.
65
+
66
+ :::
67
+
68
+ ## Examples
69
+
70
+ Adds a GitHub workflow for a SharePoint Framework project with `application` login method triggered on push to main
71
+
72
+ ```sh
73
+ m365 spfx project github workflow add
74
+ ```
75
+
76
+ Adds a GitHub workflow for a SharePoint Framework project with `user` login method triggered on push to main and when manually triggered.
77
+
78
+ ```sh
79
+ m365 spfx project github workflow add --manuallyTrigger --loginMethod "user"
80
+ ```
81
+
82
+ Adds a GitHub workflow for a SharePoint Framework project with deployment to a site collection app catalog
83
+
84
+ ```sh
85
+ m365 spfx project github workflow add --scope "sitecollection" --siteUrl "https://some.sharepoint.com/sites/someSite"
86
+ ```
87
+
88
+ ## Response
89
+
90
+ The command won't return a response on success.
91
+
92
+ ## More information
93
+
94
+ - Automate your CI/CD workflow using CLI for Microsoft 365 GitHub Actions: [https://pnp.github.io/cli-microsoft365/user-guide/github-actions](https://pnp.github.io/cli-microsoft365/user-guide/github-actions)
@@ -33,7 +33,8 @@
33
33
  "strip-json-comments": "^3.1.1",
34
34
  "typescript": "^4.9.5",
35
35
  "update-notifier": "^5.1.0",
36
- "uuid": "^9.0.0"
36
+ "uuid": "^9.0.0",
37
+ "yaml": "^2.3.1"
37
38
  },
38
39
  "bin": {
39
40
  "m365": "dist/index.js",
@@ -6037,6 +6038,14 @@
6037
6038
  "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
6038
6039
  "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g=="
6039
6040
  },
6041
+ "node_modules/yaml": {
6042
+ "version": "2.3.1",
6043
+ "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.3.1.tgz",
6044
+ "integrity": "sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==",
6045
+ "engines": {
6046
+ "node": ">= 14"
6047
+ }
6048
+ },
6040
6049
  "node_modules/yargs": {
6041
6050
  "version": "16.2.0",
6042
6051
  "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz",
@@ -10458,6 +10467,11 @@
10458
10467
  "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
10459
10468
  "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g=="
10460
10469
  },
10470
+ "yaml": {
10471
+ "version": "2.3.1",
10472
+ "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.3.1.tgz",
10473
+ "integrity": "sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ=="
10474
+ },
10461
10475
  "yargs": {
10462
10476
  "version": "16.2.0",
10463
10477
  "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnp/cli-microsoft365",
3
- "version": "6.11.0-beta.1b96aef",
3
+ "version": "6.11.0-beta.2d03676",
4
4
  "description": "Manage Microsoft 365 and SharePoint Framework projects on any platform",
5
5
  "license": "MIT",
6
6
  "main": "./dist/api.js",
@@ -251,7 +251,8 @@
251
251
  "strip-json-comments": "^3.1.1",
252
252
  "typescript": "^4.9.5",
253
253
  "update-notifier": "^5.1.0",
254
- "uuid": "^9.0.0"
254
+ "uuid": "^9.0.0",
255
+ "yaml": "^2.3.1"
255
256
  },
256
257
  "devDependencies": {
257
258
  "@microsoft/microsoft-graph-types": "^2.38.0",