dingtalk-design-cli
Version:
dingtalk design cli
136 lines (133 loc) • 5.56 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const watcher_1 = require("../../lib/cli-shared-utils/lib/watcher");
const types_1 = require("../../lib/common/types");
const path = __importStar(require("path"));
const fs = __importStar(require("fs"));
const getJson_1 = __importDefault(require("../../lib/util/getJson"));
const getMiniProjectJson_1 = __importDefault(require("../../lib/util/getMiniProjectJson"));
const logger_1 = require("../../lib/cli-shared-utils/lib/logger");
const config_1 = __importDefault(require("../../lib/common/config"));
class CommandContextFactory {
get dtdConfig() {
return this._dtdConfig;
}
get logger() {
return this._logger;
}
get commandName() {
return this._commandName;
}
get miniProgramConfigContent() {
return this._mpConfigContent;
}
constructor(originCwd, yuyanId, commandArgs, commandOptions, verbose) {
this.originCwd = originCwd;
this.yuyanId = yuyanId;
this.commandArgs = commandArgs;
this.commandOptions = commandOptions;
this.verbose = verbose;
this._commandName = '';
this._logger = logger_1.logger;
this.commandArgs = commandArgs;
this.commandOptions = commandOptions;
const { dtdConfig, hasOriginDtdConfig, } = this.getDtdConfig();
this.cwd = path.join(originCwd, './');
this._dtdConfig = dtdConfig;
this.hasOriginDtdConfig = hasOriginDtdConfig;
const mpConfig = this.getMiniProgramConfig();
this._mpConfigContent = mpConfig.content;
this.miniProgramConfigPath = mpConfig.path;
const watcher = new watcher_1.Watcher({
cwd: this.cwd,
files: [],
});
this.watcher = watcher;
}
setDtdConfig(dtdConfig) {
this._dtdConfig = dtdConfig;
}
setLogger(logger) {
this._logger = logger;
}
setCommandName(commandName) {
this._commandName = commandName;
}
setMiniProgramConfig(mpConfigContent) {
this._mpConfigContent = mpConfigContent;
}
getDtdConfig() {
const originCwd = this.originCwd;
const configPath = path.join(originCwd, config_1.default.workspaceRcName);
let hasOriginDtdConfig = false;
let dtdConfig;
if (fs.existsSync(configPath)) {
hasOriginDtdConfig = true;
dtdConfig = (0, getJson_1.default)(configPath, true, {});
}
else {
dtdConfig = {
type: '',
};
}
return {
hasOriginDtdConfig,
dtdConfig,
};
}
getMiniProgramConfig() {
const cwd = this.cwd;
let miniProjectJson = (0, getMiniProjectJson_1.default)(cwd);
if (!miniProjectJson.path) {
miniProjectJson = (0, getMiniProjectJson_1.default)(this.originCwd);
}
return miniProjectJson;
}
/**
* 引导客户获取应用的miniAppId和token
*/
logTips(appType, commandName) {
if ([types_1.EAppType.MP, types_1.EAppType.PLUGIN].indexOf(appType) === -1)
return;
const isDevCommand = this._commandName === types_1.ECommandName.dev;
this._logger.info(`
「如何获取miniAppId」
1. 登录开发者后台 https://open-dev.dingtalk.com/
${appType === types_1.EAppType.MP
? '2. 选中一个小程序,在基础信息界面可以看到小程序的miniAppId'
: '2. 进入页面 https://open-dev.dingtalk.com/v1/fe/old#/plugin,可以获取工作台组件的miniAppId'}
3. 拿到miniAppId后,${isDevCommand ? '在当前命令行输入「updateConfig miniAppId <miniAppId> + 回车」进行配置更新' : `更新配置文件${config_1.default.workspaceRcName}中的miniAppId字段`}
「如何获取API Token」
1. 参考开发者文档 https://developers.dingtalk.com/document/app/used-to-obtain-the-application-authorization-without-api-token
2. 拿到token后,${isDevCommand ? '在当前命令行输入「updateConfig token <token> + 回车」进行配置更新' : `更新配置文件${config_1.default.workspaceRcName}中的token字段`}
在设置好miniAppId和token之后,在当前命令行输入「${commandName} + 回车」 即可正常使用
`);
}
}
exports.default = CommandContextFactory;