@pnp/cli-microsoft365-spfx-toolkit 1.12.0 → 1.14.0
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.
- package/.eslintcache +1 -1
- package/dist/AuthServer.js +103 -4
- package/dist/assets/logo-large.png +0 -0
- package/dist/assets/pnp-logo.png +0 -0
- package/dist/autocomplete.js +1 -1
- package/dist/chili/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/m365/spfx/commands/project/DeployWorkflow.js +18 -22
- package/dist/m365/spfx/commands/project/base-project-command.js +22 -0
- package/dist/m365/spfx/commands/project/project-azuredevops-pipeline-add.js +53 -11
- package/dist/m365/spfx/commands/project/project-github-workflow-add.js +40 -12
- package/dist/utils/spfx.js +59 -0
- package/npm-shrinkwrap.json +12 -11
- package/package.json +1 -1
package/dist/AuthServer.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AuthServer = void 0;
|
|
4
4
|
const http = require("http");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
5
7
|
const url = require("url");
|
|
6
8
|
const Auth_1 = require("./Auth");
|
|
7
9
|
const browserUtil_1 = require("./utils/browserUtil");
|
|
@@ -44,9 +46,27 @@ class AuthServer {
|
|
|
44
46
|
const hasError = queryString.error !== undefined;
|
|
45
47
|
let body = "";
|
|
46
48
|
if (hasCode === true) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
const toolkitLogoImage = this.getAssetDataUri('logo-large.png');
|
|
50
|
+
const pnpLogoImage = this.getAssetDataUri('pnp-logo.png');
|
|
51
|
+
const toolkitLogoImageTag = toolkitLogoImage !== '' ? `<img class="logo-large" src="${toolkitLogoImage}" alt="SPFx Toolkit logo" />` : '';
|
|
52
|
+
const pnpLogoImageTag = pnpLogoImage !== '' ? `<img class="pnp-logo" src="${pnpLogoImage}" alt="PnP logo" />` : '';
|
|
53
|
+
body = `
|
|
54
|
+
<script type="text/JavaScript">
|
|
55
|
+
setTimeout(function(){ window.location = "https://spfxtoolkit.community.ms/"; }, 10000);
|
|
56
|
+
</script>
|
|
57
|
+
<div class="page">
|
|
58
|
+
<div class="card">
|
|
59
|
+
${toolkitLogoImageTag}
|
|
60
|
+
<h1>Signed in to SPFx Toolkit</h1>
|
|
61
|
+
<p>You can close this window and return to VS Code.</p>
|
|
62
|
+
<p>This page will redirect you to the <a href="https://spfxtoolkit.community.ms/">SPFx Toolkit</a> documentation in a few seconds.</p>
|
|
63
|
+
<div class="community">
|
|
64
|
+
${pnpLogoImageTag}
|
|
65
|
+
<p>This extension is supported by Microsoft 365 & Power Platform Community.</p>
|
|
66
|
+
<p><a href="https://pnp.github.io/">Microsoft 365 & Power Platform Community</a></p>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
</div>`;
|
|
50
70
|
this.resolve({
|
|
51
71
|
code: queryString.code,
|
|
52
72
|
redirectUri: this.generatedServerUrl
|
|
@@ -75,7 +95,75 @@ class AuthServer {
|
|
|
75
95
|
this.reject(errorMessage);
|
|
76
96
|
}
|
|
77
97
|
response.writeHead(200, { 'Access-Control-Allow-Origin': '*', 'Content-Type': 'text/html' });
|
|
78
|
-
response.write(`<html><head><title>SPFx Toolkit</title
|
|
98
|
+
response.write(`<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><title>SPFx Toolkit</title><style>
|
|
99
|
+
:root {
|
|
100
|
+
color-scheme: dark;
|
|
101
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
102
|
+
}
|
|
103
|
+
body {
|
|
104
|
+
margin: 0;
|
|
105
|
+
min-height: 100vh;
|
|
106
|
+
display: flex;
|
|
107
|
+
align-items: center;
|
|
108
|
+
justify-content: center;
|
|
109
|
+
background: #1f1f1f;
|
|
110
|
+
color: #cccccc;
|
|
111
|
+
}
|
|
112
|
+
.page {
|
|
113
|
+
width: 100%;
|
|
114
|
+
display: flex;
|
|
115
|
+
align-items: center;
|
|
116
|
+
justify-content: center;
|
|
117
|
+
padding: 24px;
|
|
118
|
+
}
|
|
119
|
+
.card {
|
|
120
|
+
width: min(480px, 100%);
|
|
121
|
+
background: #252526;
|
|
122
|
+
border: 1px solid #3c3c3c;
|
|
123
|
+
border-radius: 8px;
|
|
124
|
+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
|
|
125
|
+
padding: 32px;
|
|
126
|
+
text-align: center;
|
|
127
|
+
display: flex;
|
|
128
|
+
flex-direction: column;
|
|
129
|
+
}
|
|
130
|
+
.logo-large {
|
|
131
|
+
width: min(260px, 100%);
|
|
132
|
+
height: auto;
|
|
133
|
+
margin: 0 auto 20px;
|
|
134
|
+
}
|
|
135
|
+
h1 {
|
|
136
|
+
margin: 0 0 8px;
|
|
137
|
+
color: #ffffff;
|
|
138
|
+
font-size: 24px;
|
|
139
|
+
font-weight: 600;
|
|
140
|
+
}
|
|
141
|
+
p {
|
|
142
|
+
margin: 0 0 12px;
|
|
143
|
+
line-height: 1.5;
|
|
144
|
+
}
|
|
145
|
+
a {
|
|
146
|
+
color: #3794ff;
|
|
147
|
+
text-decoration: none;
|
|
148
|
+
}
|
|
149
|
+
a:hover {
|
|
150
|
+
text-decoration: underline;
|
|
151
|
+
}
|
|
152
|
+
.community {
|
|
153
|
+
margin-top: 20px;
|
|
154
|
+
padding-top: 16px;
|
|
155
|
+
border-top: 1px solid #3c3c3c;
|
|
156
|
+
}
|
|
157
|
+
.community p {
|
|
158
|
+
margin: 0 0 8px;
|
|
159
|
+
}
|
|
160
|
+
.pnp-logo {
|
|
161
|
+
width: 56px;
|
|
162
|
+
height: auto;
|
|
163
|
+
margin: 0 auto 8px;
|
|
164
|
+
display: block;
|
|
165
|
+
}
|
|
166
|
+
</style></head><body>${body}</body></html>`);
|
|
79
167
|
response.end();
|
|
80
168
|
this.httpServer.close();
|
|
81
169
|
};
|
|
@@ -83,6 +171,17 @@ class AuthServer {
|
|
|
83
171
|
get server() {
|
|
84
172
|
return this.httpServer;
|
|
85
173
|
}
|
|
174
|
+
getAssetDataUri(assetFileName) {
|
|
175
|
+
try {
|
|
176
|
+
const imagePath = path.join(__dirname, 'assets', assetFileName);
|
|
177
|
+
const imageBuffer = fs.readFileSync(imagePath);
|
|
178
|
+
const mimeType = path.extname(assetFileName).toLowerCase() === '.png' ? 'image/png' : 'application/octet-stream';
|
|
179
|
+
return `data:${mimeType};base64,${imageBuffer.toString('base64')}`;
|
|
180
|
+
}
|
|
181
|
+
catch (_a) {
|
|
182
|
+
return '';
|
|
183
|
+
}
|
|
184
|
+
}
|
|
86
185
|
openUrl(url) {
|
|
87
186
|
browserUtil_1.browserUtil.open(url)
|
|
88
187
|
.then(_ => {
|
|
Binary file
|
|
Binary file
|
package/dist/autocomplete.js
CHANGED
package/dist/chili/index.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,16 +14,16 @@ exports.workflow = {
|
|
|
14
14
|
"build-and-deploy": {
|
|
15
15
|
"runs-on": "ubuntu-latest",
|
|
16
16
|
env: {
|
|
17
|
-
NodeVersion: "
|
|
17
|
+
NodeVersion: ""
|
|
18
18
|
},
|
|
19
19
|
steps: [
|
|
20
20
|
{
|
|
21
21
|
name: "Checkout",
|
|
22
|
-
uses: "actions/checkout@
|
|
22
|
+
uses: "actions/checkout@v6"
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
25
|
name: "Use Node.js",
|
|
26
|
-
uses: "actions/setup-node@
|
|
26
|
+
uses: "actions/setup-node@v6",
|
|
27
27
|
with: {
|
|
28
28
|
"node-version": "${{ env.NodeVersion }}"
|
|
29
29
|
}
|
|
@@ -33,12 +33,12 @@ exports.workflow = {
|
|
|
33
33
|
run: "npm ci"
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
|
-
name: "
|
|
37
|
-
run: "
|
|
36
|
+
name: "Build & Package",
|
|
37
|
+
run: "npm run build"
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
40
|
name: "CLI for Microsoft 365 Login",
|
|
41
|
-
uses: "pnp/action-cli-login@
|
|
41
|
+
uses: "pnp/action-cli-login@v4",
|
|
42
42
|
with: {
|
|
43
43
|
"CERTIFICATE_ENCODED": "${{ secrets.CERTIFICATE_ENCODED }}",
|
|
44
44
|
"CERTIFICATE_PASSWORD": "${{ secrets.CERTIFICATE_PASSWORD }}",
|
|
@@ -48,9 +48,9 @@ exports.workflow = {
|
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
50
|
name: "CLI for Microsoft 365 Deploy App",
|
|
51
|
-
uses: "pnp/action-cli-deploy@
|
|
51
|
+
uses: "pnp/action-cli-deploy@v6",
|
|
52
52
|
with: {
|
|
53
|
-
"APP_FILE_PATH": "sharepoint/
|
|
53
|
+
"APP_FILE_PATH": "sharepoint/{{ sppkgPath }}",
|
|
54
54
|
"SKIP_FEATURE_DEPLOYMENT": false,
|
|
55
55
|
"OVERWRITE": false
|
|
56
56
|
}
|
|
@@ -108,13 +108,17 @@ exports.pipeline = {
|
|
|
108
108
|
name: "PackageName",
|
|
109
109
|
value: ""
|
|
110
110
|
},
|
|
111
|
+
{
|
|
112
|
+
name: "SppkgPath",
|
|
113
|
+
value: ""
|
|
114
|
+
},
|
|
111
115
|
{
|
|
112
116
|
name: "SiteAppCatalogUrl",
|
|
113
117
|
value: ""
|
|
114
118
|
},
|
|
115
119
|
{
|
|
116
120
|
name: "NodeVersion",
|
|
117
|
-
value: "
|
|
121
|
+
value: ""
|
|
118
122
|
}
|
|
119
123
|
],
|
|
120
124
|
stages: [
|
|
@@ -139,20 +143,12 @@ exports.pipeline = {
|
|
|
139
143
|
}
|
|
140
144
|
},
|
|
141
145
|
{
|
|
142
|
-
task: "
|
|
143
|
-
displayName: "
|
|
144
|
-
inputs: {
|
|
145
|
-
gulpFile: "./gulpfile.js",
|
|
146
|
-
targets: "bundle",
|
|
147
|
-
arguments: "--ship"
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
task: "Gulp@0",
|
|
152
|
-
displayName: "Gulp package",
|
|
146
|
+
task: "Npm@1",
|
|
147
|
+
displayName: "Build and package",
|
|
153
148
|
inputs: {
|
|
154
|
-
|
|
155
|
-
|
|
149
|
+
command: "custom",
|
|
150
|
+
verbose: false,
|
|
151
|
+
customCommand: "run build"
|
|
156
152
|
}
|
|
157
153
|
},
|
|
158
154
|
{
|
|
@@ -7,6 +7,7 @@ const formatting_1 = require("../../../../utils/formatting");
|
|
|
7
7
|
const fsUtil_1 = require("../../../../utils/fsUtil");
|
|
8
8
|
const AnonymousCommand_1 = require("../../../base/AnonymousCommand");
|
|
9
9
|
const project_model_1 = require("./project-model");
|
|
10
|
+
const Command_1 = require("../../../../Command");
|
|
10
11
|
class BaseProjectCommand extends AnonymousCommand_1.default {
|
|
11
12
|
constructor() {
|
|
12
13
|
super(...arguments);
|
|
@@ -236,6 +237,27 @@ class BaseProjectCommand extends AnonymousCommand_1.default {
|
|
|
236
237
|
catch (_b) { }
|
|
237
238
|
return undefined;
|
|
238
239
|
}
|
|
240
|
+
readAndParseJsonFile(filePath, project, keyPath) {
|
|
241
|
+
if (fs.existsSync(filePath)) {
|
|
242
|
+
try {
|
|
243
|
+
const source = formatting_1.formatting.removeSingleLineComments(fs.readFileSync(filePath, 'utf-8'));
|
|
244
|
+
const keys = keyPath.split('.');
|
|
245
|
+
let current = project;
|
|
246
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
247
|
+
current = current[keys[i]];
|
|
248
|
+
}
|
|
249
|
+
const finalKey = keys[keys.length - 1];
|
|
250
|
+
current[finalKey] = JSON.parse(source);
|
|
251
|
+
if (typeof current[finalKey] === 'object' && current[finalKey] !== null) {
|
|
252
|
+
current[finalKey].source = source;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
throw new Command_1.CommandError(`The file ${filePath} is not a valid JSON file or is not utf-8 encoded. Error: ${error}`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return project;
|
|
260
|
+
}
|
|
239
261
|
}
|
|
240
262
|
exports.BaseProjectCommand = BaseProjectCommand;
|
|
241
263
|
//# sourceMappingURL=base-project-command.js.map
|
|
@@ -23,6 +23,8 @@ const commands_1 = require("../../commands");
|
|
|
23
23
|
const base_project_command_1 = require("./base-project-command");
|
|
24
24
|
const validation_1 = require("../../../../utils/validation");
|
|
25
25
|
const fsUtil_1 = require("../../../../utils/fsUtil");
|
|
26
|
+
const SpfxCompatibilityMatrix_1 = require("../SpfxCompatibilityMatrix");
|
|
27
|
+
const spfx_1 = require("../../../../utils/spfx");
|
|
26
28
|
class SpfxProjectAzureDevOpsPipelineAddCommand extends base_project_command_1.BaseProjectCommand {
|
|
27
29
|
get name() {
|
|
28
30
|
return commands_1.default.PROJECT_AZUREDEVOPS_PIPELINE_ADD;
|
|
@@ -38,14 +40,12 @@ class SpfxProjectAzureDevOpsPipelineAddCommand extends base_project_command_1.Ba
|
|
|
38
40
|
__classPrivateFieldGet(this, _SpfxProjectAzureDevOpsPipelineAddCommand_instances, "m", _SpfxProjectAzureDevOpsPipelineAddCommand_initValidators).call(this);
|
|
39
41
|
}
|
|
40
42
|
commandAction(logger, args) {
|
|
43
|
+
var _a, _b;
|
|
41
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
45
|
this.projectRootPath = this.getProjectRoot(process.cwd());
|
|
43
46
|
if (this.projectRootPath === null) {
|
|
44
47
|
throw new Command_1.CommandError(`Couldn't find project root folder`, SpfxProjectAzureDevOpsPipelineAddCommand.ERROR_NO_PROJECT_ROOT_FOLDER);
|
|
45
48
|
}
|
|
46
|
-
const solutionPackageJsonFile = path.join(this.projectRootPath, 'package.json');
|
|
47
|
-
const packageJson = fs.readFileSync(solutionPackageJsonFile, 'utf-8');
|
|
48
|
-
const solutionName = JSON.parse(packageJson).name;
|
|
49
49
|
if (this.debug) {
|
|
50
50
|
logger.logToStderr(`Adding Azure DevOps pipeline in the current SPFx project`);
|
|
51
51
|
}
|
|
@@ -53,11 +53,15 @@ class SpfxProjectAzureDevOpsPipelineAddCommand extends base_project_command_1.Ba
|
|
|
53
53
|
delete require.cache[require.resolve('./DeployWorkflow')];
|
|
54
54
|
const deployWorkflow = require('./DeployWorkflow');
|
|
55
55
|
const pipeline = deployWorkflow.pipeline;
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
56
|
+
const project = { path: this.projectRootPath };
|
|
57
|
+
this.readAndParseJsonFile(path.join(this.projectRootPath, 'config', 'package-solution.json'), project, 'packageSolutionJson');
|
|
58
|
+
const sppkgPath = (_b = (_a = project.packageSolutionJson) === null || _a === void 0 ? void 0 : _a.paths) === null || _b === void 0 ? void 0 : _b.zippedPackage;
|
|
59
|
+
const pipelineToSave = structuredClone(pipeline);
|
|
60
|
+
this.updatePipeline(sppkgPath, pipelineToSave, args.options);
|
|
61
|
+
this.savePipeline(pipelineToSave);
|
|
58
62
|
}
|
|
59
63
|
catch (error) {
|
|
60
|
-
|
|
64
|
+
this.handleError(error);
|
|
61
65
|
}
|
|
62
66
|
});
|
|
63
67
|
}
|
|
@@ -69,7 +73,7 @@ class SpfxProjectAzureDevOpsPipelineAddCommand extends base_project_command_1.Ba
|
|
|
69
73
|
const pipelineFile = path.join(pipelinesPath, 'deploy-spfx-solution.yml');
|
|
70
74
|
fs.writeFileSync(path.resolve(pipelineFile), yaml.stringify(pipeline), 'utf-8');
|
|
71
75
|
}
|
|
72
|
-
updatePipeline(
|
|
76
|
+
updatePipeline(sppkgPath, pipeline, options) {
|
|
73
77
|
if (options.name) {
|
|
74
78
|
pipeline.name = options.name;
|
|
75
79
|
}
|
|
@@ -79,6 +83,16 @@ class SpfxProjectAzureDevOpsPipelineAddCommand extends base_project_command_1.Ba
|
|
|
79
83
|
if (options.branchName) {
|
|
80
84
|
pipeline.trigger.branches.include[0] = options.branchName;
|
|
81
85
|
}
|
|
86
|
+
const version = this.getProjectVersion();
|
|
87
|
+
if (!version) {
|
|
88
|
+
throw 'Unable to determine the version of the current SharePoint Framework project. Could not find the correct version based on the version property in the .yo-rc.json file.';
|
|
89
|
+
}
|
|
90
|
+
const versionRequirements = SpfxCompatibilityMatrix_1.versions[version];
|
|
91
|
+
if (!versionRequirements) {
|
|
92
|
+
throw `Could not find Node version for version '${version}' of SharePoint Framework.`;
|
|
93
|
+
}
|
|
94
|
+
const nodeVersion = spfx_1.spfx.getHighestNodeVersion(versionRequirements.node.range);
|
|
95
|
+
this.assignPipelineVariables(pipeline, 'NodeVersion', nodeVersion);
|
|
82
96
|
const script = this.getScriptAction(pipeline);
|
|
83
97
|
if (script.script) {
|
|
84
98
|
if (options.loginMethod === 'user') {
|
|
@@ -96,20 +110,48 @@ class SpfxProjectAzureDevOpsPipelineAddCommand extends base_project_command_1.Ba
|
|
|
96
110
|
}
|
|
97
111
|
if (options.scope === 'sitecollection') {
|
|
98
112
|
script.script = script.script.replace(`{{deploy}}`, `m365 spo app deploy --name '$(PackageName)' --appCatalogScope sitecollection --appCatalogUrl '$(SiteAppCatalogUrl)'`);
|
|
99
|
-
script.script = script.script.replace(`{{addApp}}`, `m365 spo app add --filePath '$(Build.SourcesDirectory)/sharepoint
|
|
113
|
+
script.script = script.script.replace(`{{addApp}}`, `m365 spo app add --filePath '$(Build.SourcesDirectory)/sharepoint/$(SppkgPath)' --appCatalogScope sitecollection --appCatalogUrl '$(SiteAppCatalogUrl)' --overwrite`);
|
|
100
114
|
this.assignPipelineVariables(pipeline, 'SiteAppCatalogUrl', options.siteUrl);
|
|
101
115
|
}
|
|
102
116
|
else {
|
|
103
117
|
script.script = script.script.replace(`{{deploy}}`, `m365 spo app deploy --name '$(PackageName)' --appCatalogScope 'tenant'`);
|
|
104
|
-
script.script = script.script.replace(`{{addApp}}`, `m365 spo app add --filePath '$(Build.SourcesDirectory)/sharepoint
|
|
118
|
+
script.script = script.script.replace(`{{addApp}}`, `m365 spo app add --filePath '$(Build.SourcesDirectory)/sharepoint/$(SppkgPath)' --overwrite`);
|
|
105
119
|
pipeline.variables = pipeline.variables.filter(v => v.name !== 'SiteAppCatalogUrl');
|
|
106
120
|
}
|
|
107
|
-
if (
|
|
108
|
-
this.assignPipelineVariables(pipeline, '
|
|
121
|
+
if (sppkgPath) {
|
|
122
|
+
this.assignPipelineVariables(pipeline, 'SppkgPath', sppkgPath);
|
|
123
|
+
this.assignPipelineVariables(pipeline, 'PackageName', path.basename(sppkgPath));
|
|
109
124
|
}
|
|
110
125
|
if (options.skipFeatureDeployment) {
|
|
111
126
|
script.script = script.script.replace(`m365 spo app deploy `, `m365 spo app deploy --skipFeatureDeployment `);
|
|
112
127
|
}
|
|
128
|
+
if (versionRequirements.heft === undefined) {
|
|
129
|
+
let steps = this.getPipelineSteps(pipeline);
|
|
130
|
+
const npmBuildScript = steps.find(step => step.task && step.displayName === 'Build and package');
|
|
131
|
+
if (npmBuildScript) {
|
|
132
|
+
pipeline.stages[0].jobs[0].steps = steps.filter(step => step !== npmBuildScript);
|
|
133
|
+
}
|
|
134
|
+
const gulpBundleStep = {
|
|
135
|
+
task: 'Gulp@0',
|
|
136
|
+
displayName: 'Gulp bundle',
|
|
137
|
+
inputs: {
|
|
138
|
+
gulpFile: './gulpfile.js',
|
|
139
|
+
targets: 'bundle',
|
|
140
|
+
arguments: '--ship'
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const gulpPackageStep = {
|
|
144
|
+
task: 'Gulp@0',
|
|
145
|
+
displayName: 'Gulp package',
|
|
146
|
+
inputs: {
|
|
147
|
+
targets: 'package-solution',
|
|
148
|
+
arguments: '--ship'
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
steps = this.getPipelineSteps(pipeline);
|
|
152
|
+
const installCLIStepIndex = steps.findIndex(step => step.task === 'Npm@1' && step.displayName === 'Install CLI for Microsoft 365');
|
|
153
|
+
pipeline.stages[0].jobs[0].steps.splice(installCLIStepIndex, 0, gulpBundleStep, gulpPackageStep);
|
|
154
|
+
}
|
|
113
155
|
}
|
|
114
156
|
}
|
|
115
157
|
assignPipelineVariables(pipeline, variableName, newVariableValue) {
|
|
@@ -23,6 +23,8 @@ const fsUtil_1 = require("../../../../utils/fsUtil");
|
|
|
23
23
|
const validation_1 = require("../../../../utils/validation");
|
|
24
24
|
const commands_1 = require("../../commands");
|
|
25
25
|
const base_project_command_1 = require("./base-project-command");
|
|
26
|
+
const SpfxCompatibilityMatrix_1 = require("../SpfxCompatibilityMatrix");
|
|
27
|
+
const spfx_1 = require("../../../../utils/spfx");
|
|
26
28
|
class SpfxProjectGithubWorkflowAddCommand extends base_project_command_1.BaseProjectCommand {
|
|
27
29
|
get name() {
|
|
28
30
|
return commands_1.default.PROJECT_GITHUB_WORKFLOW_ADD;
|
|
@@ -38,26 +40,30 @@ class SpfxProjectGithubWorkflowAddCommand extends base_project_command_1.BasePro
|
|
|
38
40
|
__classPrivateFieldGet(this, _SpfxProjectGithubWorkflowAddCommand_instances, "m", _SpfxProjectGithubWorkflowAddCommand_initValidators).call(this);
|
|
39
41
|
}
|
|
40
42
|
commandAction(logger, args) {
|
|
43
|
+
var _a, _b;
|
|
41
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
45
|
this.projectRootPath = this.getProjectRoot(process.cwd());
|
|
43
46
|
if (this.projectRootPath === null) {
|
|
44
47
|
throw new Command_1.CommandError(`Couldn't find project root folder`, SpfxProjectGithubWorkflowAddCommand.ERROR_NO_PROJECT_ROOT_FOLDER);
|
|
45
48
|
}
|
|
46
|
-
const solutionPackageJsonFile = path.join(this.projectRootPath, 'package.json');
|
|
47
|
-
const packageJson = fs.readFileSync(solutionPackageJsonFile, 'utf-8');
|
|
48
|
-
const solutionName = JSON.parse(packageJson).name;
|
|
49
|
-
if (this.debug) {
|
|
50
|
-
logger.logToStderr(`Adding GitHub workflow in the current SPFx project`);
|
|
51
|
-
}
|
|
52
49
|
try {
|
|
50
|
+
const project = { path: this.projectRootPath };
|
|
51
|
+
this.readAndParseJsonFile(path.join(this.projectRootPath, 'package.json'), project, 'packageJson');
|
|
52
|
+
this.readAndParseJsonFile(path.join(this.projectRootPath, 'config', 'package-solution.json'), project, 'packageSolutionJson');
|
|
53
|
+
const solutionName = project.packageJson.name;
|
|
54
|
+
const sppkgPath = (_b = (_a = project.packageSolutionJson) === null || _a === void 0 ? void 0 : _a.paths) === null || _b === void 0 ? void 0 : _b.zippedPackage;
|
|
55
|
+
if (this.debug) {
|
|
56
|
+
logger.logToStderr(`Adding GitHub workflow in the current SPFx project`);
|
|
57
|
+
}
|
|
53
58
|
delete require.cache[require.resolve('./DeployWorkflow')];
|
|
54
59
|
const deployWorkflow = require('./DeployWorkflow');
|
|
55
60
|
const workflow = deployWorkflow.workflow;
|
|
56
|
-
|
|
57
|
-
this.
|
|
61
|
+
const workflowToSave = structuredClone(workflow);
|
|
62
|
+
this.updateWorkflow(solutionName, sppkgPath, workflowToSave, args.options);
|
|
63
|
+
this.saveWorkflow(workflowToSave);
|
|
58
64
|
}
|
|
59
65
|
catch (error) {
|
|
60
|
-
|
|
66
|
+
this.handleError(error);
|
|
61
67
|
}
|
|
62
68
|
});
|
|
63
69
|
}
|
|
@@ -69,11 +75,21 @@ class SpfxProjectGithubWorkflowAddCommand extends base_project_command_1.BasePro
|
|
|
69
75
|
const workflowFile = path.join(workflowPath, 'deploy-spfx-solution.yml');
|
|
70
76
|
fs.writeFileSync(path.resolve(workflowFile), yaml.stringify(workflow), 'utf-8');
|
|
71
77
|
}
|
|
72
|
-
updateWorkflow(solutionName, workflow, options) {
|
|
78
|
+
updateWorkflow(solutionName, sppkgPath, workflow, options) {
|
|
73
79
|
workflow.name = options.name ? options.name : workflow.name.replace('{{ name }}', solutionName);
|
|
74
80
|
if (options.branchName) {
|
|
75
81
|
workflow.on.push.branches[0] = options.branchName;
|
|
76
82
|
}
|
|
83
|
+
const version = this.getProjectVersion();
|
|
84
|
+
if (!version) {
|
|
85
|
+
throw 'Unable to determine the version of the current SharePoint Framework project. Could not find the correct version based on the version property in the .yo-rc.json file.';
|
|
86
|
+
}
|
|
87
|
+
const versionRequirements = SpfxCompatibilityMatrix_1.versions[version];
|
|
88
|
+
if (!versionRequirements) {
|
|
89
|
+
throw `Could not find Node version for version '${version}' of SharePoint Framework.`;
|
|
90
|
+
}
|
|
91
|
+
const nodeVersion = spfx_1.spfx.getHighestNodeVersion(versionRequirements.node.range);
|
|
92
|
+
this.assignNodeVersion(workflow, nodeVersion);
|
|
77
93
|
if (options.manuallyTrigger) {
|
|
78
94
|
// eslint-disable-next-line camelcase
|
|
79
95
|
workflow.on.workflow_dispatch = null;
|
|
@@ -96,11 +112,23 @@ class SpfxProjectGithubWorkflowAddCommand extends base_project_command_1.BasePro
|
|
|
96
112
|
deployAction.with.SCOPE = 'sitecollection';
|
|
97
113
|
deployAction.with.SITE_COLLECTION_URL = options.siteUrl;
|
|
98
114
|
}
|
|
99
|
-
if (
|
|
115
|
+
if (sppkgPath) {
|
|
100
116
|
const deployAction = this.getDeployAction(workflow);
|
|
101
|
-
deployAction.with.APP_FILE_PATH = deployAction.with.APP_FILE_PATH.replace('{{
|
|
117
|
+
deployAction.with.APP_FILE_PATH = deployAction.with.APP_FILE_PATH.replace('{{ sppkgPath }}', sppkgPath);
|
|
118
|
+
}
|
|
119
|
+
if (versionRequirements.heft === undefined) {
|
|
120
|
+
const buildAndPackageStep = this.getBuildAndPackageStep(workflow);
|
|
121
|
+
buildAndPackageStep.run = `gulp bundle --ship\ngulp package-solution --ship\n`;
|
|
122
|
+
buildAndPackageStep.name = 'Bundle & Package';
|
|
102
123
|
}
|
|
103
124
|
}
|
|
125
|
+
assignNodeVersion(workflow, nodeVersion) {
|
|
126
|
+
workflow.jobs['build-and-deploy'].env.NodeVersion = nodeVersion;
|
|
127
|
+
}
|
|
128
|
+
getBuildAndPackageStep(workflow) {
|
|
129
|
+
const steps = this.getWorkFlowSteps(workflow);
|
|
130
|
+
return steps.find(step => step.run && step.name === 'Build & Package');
|
|
131
|
+
}
|
|
104
132
|
getLoginAction(workflow) {
|
|
105
133
|
const steps = this.getWorkFlowSteps(workflow);
|
|
106
134
|
return steps.find(step => step.uses && step.uses.indexOf('action-cli-login') >= 0);
|
package/dist/utils/spfx.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.spfx = void 0;
|
|
4
|
+
const semver_1 = require("semver");
|
|
4
5
|
exports.spfx = {
|
|
5
6
|
isReactProject(project) {
|
|
6
7
|
var _a, _b;
|
|
@@ -16,6 +17,64 @@ exports.spfx = {
|
|
|
16
17
|
typeof project.yoRcJson['@microsoft/generator-sharepoint'] !== 'undefined' &&
|
|
17
18
|
project.yoRcJson["@microsoft/generator-sharepoint"].framework === 'knockout') ||
|
|
18
19
|
typeof ((_b = (_a = project.packageJson) === null || _a === void 0 ? void 0 : _a.dependencies) === null || _b === void 0 ? void 0 : _b['knockout']) !== 'undefined';
|
|
20
|
+
},
|
|
21
|
+
getHighestNodeVersion(versionRange) {
|
|
22
|
+
if (!versionRange) {
|
|
23
|
+
throw new Error('Node version range was not provided.');
|
|
24
|
+
}
|
|
25
|
+
const ranges = versionRange
|
|
26
|
+
.split('||')
|
|
27
|
+
.map(range => range.trim())
|
|
28
|
+
.filter(range => range.length > 0);
|
|
29
|
+
let highestMajor = null;
|
|
30
|
+
let exactVersion = null;
|
|
31
|
+
const simpleVersionPattern = /^\d+(\.\d+(\.\d+)?)?$/;
|
|
32
|
+
if (ranges.every(r => simpleVersionPattern.test(r))) {
|
|
33
|
+
const highest = ranges.reduce((best, curr) => (0, semver_1.gt)((0, semver_1.coerce)(curr), (0, semver_1.coerce)(best)) ? curr : best);
|
|
34
|
+
const parts = highest.split('.');
|
|
35
|
+
if (parts.length >= 3) {
|
|
36
|
+
return highest;
|
|
37
|
+
}
|
|
38
|
+
if (parts.length === 2) {
|
|
39
|
+
return `${highest}.x`;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
for (const rangeString of ranges) {
|
|
43
|
+
const normalized = (0, semver_1.validRange)(rangeString);
|
|
44
|
+
if (!normalized) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const rangeObj = new semver_1.Range(normalized);
|
|
48
|
+
let maxMajor = 0;
|
|
49
|
+
// Analyze the range to find the maximum major version
|
|
50
|
+
for (const comparatorSet of rangeObj.set) {
|
|
51
|
+
for (const comparator of comparatorSet) {
|
|
52
|
+
if (comparator.operator === '<') {
|
|
53
|
+
// Exclusive upper bound: <17.0.0 means max major is 16
|
|
54
|
+
maxMajor = Math.max(maxMajor, comparator.semver.major - 1);
|
|
55
|
+
}
|
|
56
|
+
else if (comparator.operator === '<=') {
|
|
57
|
+
// Inclusive upper bound: <=17.0.0 means we can use exactly that version
|
|
58
|
+
maxMajor = Math.max(maxMajor, comparator.semver.major);
|
|
59
|
+
// Store the exact version for <= comparator
|
|
60
|
+
if (highestMajor === null || comparator.semver.major > highestMajor) {
|
|
61
|
+
exactVersion = comparator.semver.version;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (comparator.operator === '>=' || comparator.operator === '>') {
|
|
65
|
+
// For lower bounds use the major version
|
|
66
|
+
maxMajor = Math.max(maxMajor, comparator.semver.major);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Track the highest major version across all ranges
|
|
71
|
+
highestMajor = Math.max(highestMajor !== null && highestMajor !== void 0 ? highestMajor : 0, maxMajor);
|
|
72
|
+
}
|
|
73
|
+
if (highestMajor === null) {
|
|
74
|
+
throw new Error(`Unable to resolve the highest Node version for range '${versionRange}'.`);
|
|
75
|
+
}
|
|
76
|
+
// Return exact version if we have a <= comparator, otherwise use .x
|
|
77
|
+
return exactVersion || `${highestMajor}.x`;
|
|
19
78
|
}
|
|
20
79
|
};
|
|
21
80
|
//# sourceMappingURL=spfx.js.map
|