Skip to content

Commit

Permalink
add support for Red Mini Program
Browse files Browse the repository at this point in the history
  • Loading branch information
malash committed Oct 25, 2023
1 parent 3833737 commit 68e224c
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 5 deletions.
13 changes: 11 additions & 2 deletions packages/cli/src/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ export interface CliConfig {
progress?: boolean;
}

const GOJI_TARGETS: Array<GojiTarget> = ['wechat', 'baidu', 'alipay', 'toutiao', 'qq', 'toutiao'];
const GOJI_TARGETS: Array<GojiTarget> = [
'wechat',
'baidu',
'alipay',
'toutiao',
'qq',
'toutiao',
'red',
];

export const parseArgv = (arg: Array<string>) => new Promise<CliConfig>((resolve, reject) => {
export const parseArgv = (arg: Array<string>) =>
new Promise<CliConfig>((resolve, reject) => {
const yargsConfig = yargs
.command({
command: 'start [target]',
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/config/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const getWebpackConfig = ({
baidu: 'css',
alipay: 'acss',
toutiao: 'ttss',
red: 'css',
};

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const GOJI_VIRTUAL_ROOT = 'GOJI_VIRTUAL_ROOT';
export const TYPE_TEXT = 'GOJI_TYPE_TEXT';
export const TYPE_SUBTREE = 'GOJI_TYPE_SUBTREE';

export type GojiTarget = 'wechat' | 'baidu' | 'alipay' | 'toutiao' | 'qq' | 'toutiao';
export type GojiTarget = 'wechat' | 'baidu' | 'alipay' | 'toutiao' | 'qq' | 'red';

export interface SimplifyComponent {
name: string;
Expand Down
5 changes: 3 additions & 2 deletions packages/webpack-plugin/src/constants/features.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GojiTarget } from '@goji/core';

export const getFeatures = (target: GojiTarget) => ({
useSubtree: target === 'wechat' || target === 'qq',
useSubtree: target === 'wechat' || target === 'qq' || target === 'red',

useInlineChildrenInComponent:
// Alipay only support circular dependency self to self so we have to inline the children.wxml
Expand All @@ -11,7 +11,8 @@ export const getFeatures = (target: GojiTarget) => ({
// Baidu changes the behavior of circular dependency on dev tool >= v4.22 with new compiler
// so we have to inline the children.wxml
// https://smartprogram.baidu.com/docs/develop/devtools/beta-notify#_5-%E6%A8%A1%E6%9D%BF-import-%E8%AF%AD%E6%B3%95%E4%B8%8D%E5%85%81%E8%AE%B8%E5%BE%AA%E7%8E%AF%E5%BC%95%E7%94%A8%E3%80%82
target === 'baidu',
target === 'baidu' ||
target === 'red',

// Alipay doesn't support <include> in <template> if Lib v2.0 is enabled.
// Unfortunately, it has been forced to enable since mid-year 2023.
Expand Down
1 change: 1 addition & 0 deletions packages/webpack-plugin/src/plugins/shim/variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const API_VARIABLE_NAME: Record<GojiTarget, string> = {
alipay: 'my',
qq: 'qq',
toutiao: 'tt',
red: 'xhs',
};

export const getApiVariableDefinitions = (target: GojiTarget) => {
Expand Down
9 changes: 9 additions & 0 deletions packages/webpack-plugin/src/utils/render/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ export const transformTemplate = async (
default:
return source;
}
case 'red':
switch (type) {
case 'wxml':
return source.replace(/wx:/g, 'xhs:').replace(/\.wxml/g, '.xhsml');
case 'js':
return source;
default:
return source;
}
default:
return source;
}
Expand Down
9 changes: 9 additions & 0 deletions packages/webpack-plugin/src/utils/transformExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export const transformExtension = ({
default:
return extension;
}
case 'red':
switch (extension) {
case '.wxml':
return '.xhsml';
case '.wxss':
return '.css';
default:
return extension;
}
default:
return extension;
}
Expand Down

0 comments on commit 68e224c

Please sign in to comment.