我有以下吞咽任务:
build.task('upload', {
execute: (config) => {
/*
THIS WORKS, BUT ONLY if i do "gulp upload".
"gulp upload -u < commandline options >" fails.
const uname = "johndoe@asdf.com";
const pwd = "supersecret";
const siteUrl = "https://<mytenant>.sharepoint.com/sites";
const siteCatalogUrl = "https://<mytenant>.sharepoint.com/sites/CatalogSiteName";
const catalogName = "AppCatalog";
console.log(uname);
console.log(siteUrl);
console.log(siteCatalogUrl);
console.log(catalogName);
*/
const uname = config.args['u'];
const pwd = config.args['p'];
const siteUrl = config.args['sU'];
const siteCatalogUrl = config.args['cU'];
const catalogName = config.args['c'];
console.log(uname);
console.log(siteUrl);
console.log(siteCatalogUrl);
console.log(catalogName);
return new Promise((resolve, reject) => {
const pkgFile = require('./config/package-solution.json');
const folderLocation = `./sharepoint/${pkgFile.paths.zippedPackage}`;
return gulp.src(folderLocation)
.pipe(spsync({
"username": uname,
"password": pwd,
"site": siteCatalogUrl,
"libraryPath": catalog,
"publish": true
}))
.on('finish', resolve);
});
}
});
当我在命令行上测试时,我这样运行:
gulp upload
它确实调用 gulp clean 的第一件事......它吹走了 sppkg。所以上传任务失败。
我注意到的另一个我无法解释的工件是,当我运行 gulp 任务时,我看到了这个:
Build target: SHIP
而不是通常的
Build target: DEBUG
输出
lab3:search-parts admin$ gulp upload
Build target: SHIP
[14:16:31] Using gulpfile /src/search/gulpfile.js
[14:16:31] Starting 'upload'...
[14:16:31] Starting gulp
[14:16:31] Starting subtask 'clean'...
[14:16:31] Finished subtask 'clean' after 119 ms
[14:16:31] The following tasks did not complete: upload
[14:16:31] Did you forget to signal async completion?
About to exit with code: 0
Process terminated before summary could be written, possible error in async code not continuing!
Trying to exit with exit code 1
不知道是否相关,但以防万一...
谢谢。
编辑 1
我可以始终如一地重现该问题,并且我也找到了一个修复程序——尽管——不是我可以在生产中使用的修复程序。但我还不知道问题的根本原因是什么。
要创建问题,我只需要通过 config 对象传入参数。换句话说,我通过这样的命令行触发了这个 gulp 方法:
gulp package-solution --ship
gulp upload --u "johndoe@asdf.com" --p "supersecret" --sU "https://<mytenant>.sharepoint.com/sites/CatalogSiteName" --cU "https://<mytenant>.sharepoint.com/sites/CatalogSiteName" --c "AppCatalog"
当我运行脚本时,它做的第一件事就是大口清洁。如果我注释掉所有逻辑以从 config.args[] 中获取变量并只使用硬编码的值......它可以工作。但我必须确保我不通过命令行提供参数。换句话说,这有效:
lab3:spparts admin$ gulp upload
Build target: DEBUG
[14:27:27] Using gulpfile /src/sp/spparts/gulpfile.js
[14:27:27] Starting 'upload'...
[14:27:27] Starting gulp
johndoe@asdf.com
https://<mytenant>.sharepoint.com/sites/CatalogSiteName
https://<mytenant>.sharepoint.com/sites/CatalogSiteName
AppCatalog
[14:27:27] Uploading spparts.sppkg
[14:27:32] Upload successful 5289ms
[14:27:35] Published file 2408ms
[14:27:35] Finished 'upload' after 7.73 s
[14:27:35] ==================[ Finished ]==================
[14:27:36] Project spparts version:4.3.0
[14:27:36] Build tools version:3.17.11
[14:27:36] Node version:v10.24.1
[14:27:36] Total duration:13 s
但这不是:(尽管 js 代码仍在使用硬编码值)
lab3:spparts admin$ gulp upload --u "johndoe@asdf.com" --p "supersecret" --sU "https://<mytenant>.sharepoint.com/sites/CatalogSiteName" --cU "https://<mytenant>.sharepoint.com/sites/CatalogSiteName" --c "AppCatalog"
Build target: SHIP
[14:27:27] Using gulpfile /src/sp/spparts/gulpfile.js
[14:27:27] Starting 'upload'...
[14:27:27] Starting gulp
[14:30:36] Starting subtask 'clean'...
[14:30:36] Finished subtask 'clean' after 68 ms
johndoe@asdf.com
https://<mytenant>.sharepoint.com/sites/CatalogSiteName
https://<mytenant>.sharepoint.com/sites/CatalogSiteName
AppCatalog
[14:30:36] 'upload' errored after 85 ms
[14:30:36] Error: File not found with singular glob: /src/spparts/sharepoint/solution/spparts.sppkg (if this was purposeful, use `allowEmpty` option)
所以总而言之,我想我可以说当我传入命令行参数时,脚本调用 gulp clean。但我不知道为什么。
如果有帮助,这是我的版本信息:
lab3:spparts admin$ gulp -v
CLI version: 2.3.0
Local version: 4.0.2
sp-build-web 的版本是 1.12.1