Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove check targets #4899

Merged
merged 3 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/plugin-app-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"dependencies": {
"@builder/app-helpers": "^2.0.0",
"@builder/app-templates": "^1.0.0",
"chalk": "^4.0.0",
"chokidar": "^3.4.1",
"ejs": "^3.0.1",
"fs-extra": "^8.1.0",
Expand All @@ -41,4 +40,4 @@
"devDependencies": {
"@types/object-hash": "^2.2.1"
}
}
}
45 changes: 0 additions & 45 deletions packages/plugin-app-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ import dev from './dev';
import { setAlias, setProjectType, setEntry, setTempDir, setRegisterMethod, setRegisterUserConfig } from './config';
import getBuildConfig from './utils/getBuildConfig';

// eslint-disable-next-line
const chalk = require('chalk');
// eslint-disable-next-line
const { constants: { MINIAPP, WECHAT_MINIPROGRAM, BAIDU_SMARTPROGRAM, KUAISHOU_MINIPROGRAM, QUICKAPP, BYTEDANCE_MICROAPP } } = require('miniapp-builder-shared');
const miniappPlatforms = [ MINIAPP, WECHAT_MINIPROGRAM, BYTEDANCE_MICROAPP, BAIDU_SMARTPROGRAM, KUAISHOU_MINIPROGRAM ];

export default (api, options) => {
const { onHook, context, setValue } = api;
const { command, userConfig, rootDir } = context;
const { targets = ['web'] } = userConfig;
const { framework } = options;

// Set framework field
Expand All @@ -43,9 +40,6 @@ export default (api, options) => {
// Set webpack cache id
setValue('WEBPACK_CACHE_ID', hash({ ...userConfig, hasJsxRuntime }));

// Check target
checkTargets(targets);

// Set temporary directory
// eg: .ice or .rax
setTempDir(api, options);
Expand Down Expand Up @@ -150,42 +144,3 @@ function getDefaultRenderData(api, options) {
};
}
}

function checkTargets(targets) {
let hasError = false;

if (Object.prototype.toString.call(targets) === '[object Object]') {
hasError = true;
}

if (typeof targets === 'string') {
hasError = true;
}

if (Array.isArray(targets) && !matchTargets(targets)) {
hasError = true;
}

if (hasError) {
const msg = `
targets must be the array type in build.json.

e.g. { "targets": ["miniapp", "wechat-miniprogram"] }

if you want to describes the browserslist environments for your project.
you should set browserslist in build.json.

e.g. { "browserslist": { "chrome": "58", "ie": 11 } }
`;
console.log();
console.log(chalk.red(msg));
console.log();
process.exit(1);
}
}

function matchTargets(targets) {
return targets.every(target => {
return ['web', 'weex', 'kraken', MINIAPP, WECHAT_MINIPROGRAM, BYTEDANCE_MICROAPP, BAIDU_SMARTPROGRAM, KUAISHOU_MINIPROGRAM, QUICKAPP].includes(target);
});
}