@tarojs/rn-runner 3.5.5 → 3.5.6-alpha.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/src/index.ts CHANGED
@@ -1,104 +1,41 @@
1
- import saveAssets from '@react-native-community/cli-plugin-metro/build/commands/bundle/saveAssets'
2
- import { createDevServerMiddleware } from '@react-native-community/cli-server-api'
3
1
  import { PLATFORMS } from '@tarojs/helper'
4
- import * as fse from 'fs-extra'
5
- import * as Metro from 'metro'
6
- import { getResolveDependencyFn } from 'metro/src/lib/transformHelpers'
7
- import * as Server from 'metro/src/Server'
8
- import * as outputBundle from 'metro/src/shared/output/bundle'
9
- import * as path from 'path'
10
- import * as qr from 'qrcode-terminal'
11
- import * as readline from 'readline'
12
- import * as url from 'url'
2
+ import { spawn } from 'child_process'
3
+ import { constants,copyFile } from 'fs'
4
+ import { join } from 'path'
13
5
 
14
- import getMetroConfig from './config'
15
6
  import buildComponent from './config/build-component'
16
- import { getRNConfigEntry } from './config/config-holder'
17
- import preview from './config/preview'
18
- import { TerminalReporter } from './config/terminal-reporter'
19
- import { getOpenHost, isWin, PLAYGROUNDINFO } from './utils'
20
7
 
21
- function concatOutputFileName (config: any): string {
22
- // 优先级:--bundle-output > config.output > config.outputRoot
23
- let output = path.join(config.outputRoot, 'index.bundle')
24
- if (config.output) {
25
- const outputType = typeof config.output
26
- if (outputType === 'string') {
27
- output = config.output
28
- } else if (outputType === 'object') {
29
- output = config.output[config.deviceType]
30
- if (!output) {
31
- console.error(`lack value for 'rn.output' configuration with platform '${config.deviceType}': ${JSON.stringify(config.output)}`)
8
+ // 确认根目录下 metro.config.js index.js 是否存在
9
+ const files = ['metro.config.js', 'index.js']
10
+ function confirmFiles () {
11
+ files.forEach(file => {
12
+ const filePath = join(process.cwd(), file)
13
+ copyFile(join(__dirname, '..', 'templates', file), filePath, constants.COPYFILE_EXCL, err => {
14
+ if (err) {
15
+ if (err.code !== 'EEXIST') {
16
+ // 不重复生成配置文件
17
+ console.log(err)
18
+ }
19
+ } else {
20
+ console.log(`${file} created`)
32
21
  }
33
- } else {
34
- console.error(`invalid value for 'rn.output' configuration: ${JSON.stringify(config.output)}`)
35
- }
36
- }
37
- if (config.bundleOutput) {
38
- output = config.bundleOutput
39
- }
40
- const res = path.isAbsolute(output) ? output : path.join('.', output)
41
- fse.ensureDirSync(path.dirname(res))
42
- return res
43
- }
44
-
45
- function concatOutputAssetsDest (config: any): string | undefined {
46
- // 优先级:--assets-dest > config.output > config.outputRoot
47
- let assetDest
48
- if (!config?.deviceType || !config?.output) {
49
- assetDest = config.outputRoot
50
- } else {
51
- assetDest = config.deviceType === 'ios' ? config.output.iosAssetsDest : config.output.androidAssetsDest
52
- }
53
- if (config.assetsDest) {
54
- assetDest = config.assetsDest
55
- }
56
- if (!assetDest) return undefined
57
- const res = path.isAbsolute(assetDest) ? assetDest : path.join('.', assetDest)
58
- fse.ensureDirSync(path.dirname(res))
59
- return res
60
- }
61
-
62
- function getOutputSourceMapOption (config: any): Record<string, any> {
63
- if (!config?.deviceType) {
64
- return {}
65
- }
66
- const isIos = config.deviceType === 'ios'
67
- const sourceMapUrl = config.sourceMapUrl || (isIos ? config?.output?.iosSourceMapUrl : config?.output?.androidSourceMapUrl)
68
- const sourcemapOutput = config.sourcemapOutput || (isIos ? config?.output?.iosSourcemapOutput : config?.output?.androidSourcemapOutput)
69
- const sourcemapSourcesRoot = config.sourcemapSourcesRoot || (isIos ? config?.output?.iosSourcemapSourcesRoot : config?.output?.androidSourcemapSourcesRoot)
70
- sourcemapOutput && fse.ensureDirSync(path.dirname(sourcemapOutput))
71
- return {
72
- sourceMapUrl,
73
- sourcemapOutput,
74
- sourcemapSourcesRoot
75
- }
22
+ })
23
+ })
76
24
  }
77
25
 
78
- // TODO: 返回值
79
- // HttpServer | {code: string, map: string}
80
- // IBuildConfig
81
26
  export default async function build (_appPath: string, config: any): Promise<any> {
27
+ confirmFiles()
82
28
  process.env.TARO_ENV = PLATFORMS.RN
83
- // TODO:新增环境变量是否可以在metro构建过程中可以访问到?
84
- const entry = getRNConfigEntry()
85
- config.entry = entry
86
- const metroConfig = await getMetroConfig(config)
87
- const sourceRoot = config.sourceRoot || 'src'
88
-
89
- const commonOptions = {
90
- platform: config.deviceType,
91
- minify: process.env.NODE_ENV === 'production' || !config.isWatch,
92
- dev: config.isWatch
93
- }
29
+ const isIos = config.deviceType === 'ios'
30
+ const cliParams:string[] = []
31
+ config.output = config.output || {}
32
+ // cli & config 参数透传
94
33
  if (config.resetCache) {
95
- metroConfig.resetCache = config.resetCache
34
+ cliParams.push('--reset-cache')
96
35
  }
97
36
  if (config.publicPath) {
98
- metroConfig.transformer.publicPath = config.publicPath
37
+ cliParams.push('--public-path', config.publicPath)
99
38
  }
100
- metroConfig.reporter = new TerminalReporter(entry, sourceRoot, metroConfig.cacheStores[0])
101
-
102
39
  const onFinish = function (error?) {
103
40
  if (typeof config.onBuildFinish === 'function') {
104
41
  config.onBuildFinish({
@@ -108,145 +45,58 @@ export default async function build (_appPath: string, config: any): Promise<any
108
45
  }
109
46
  if (error instanceof Error) throw error
110
47
  }
111
-
112
48
  if (config.isBuildNativeComp) {
113
49
  return buildComponent(
114
50
  _appPath,
115
51
  config
116
52
  )
117
53
  } else if (config.isWatch) {
118
- if (!metroConfig.server || (metroConfig.server.useGlobalHotkey === undefined)) {
119
- if (!metroConfig.server) {
120
- metroConfig.server = {}
121
- }
122
- metroConfig.server.useGlobalHotkey = true
123
- }
124
54
  if (config.port) {
125
- metroConfig.server.port = config.port
126
- }
127
-
128
- const {
129
- middleware,
130
- messageSocketEndpoint,
131
- websocketEndpoints
132
- } = createDevServerMiddleware({
133
- port: metroConfig.server.port,
134
- watchFolders: metroConfig.watchFolders
135
- })
136
- metroConfig.server.enhanceMiddleware = (metroMiddleware, metroServer) => {
137
- metroConfig.reporter.metroServerInstance = metroServer
138
-
139
- // bundle路由只识别/index.bundle
140
- return middleware.use((req, res, next) => {
141
- // eslint-disable-next-line node/no-deprecated-api
142
- const urlObj = url.parse(req.url)
143
- if (/\/[^]+.bundle/.test(urlObj.pathname || '') && (urlObj.pathname || '').toLowerCase() !== '/index.bundle') {
144
- res.writeHead(400)
145
- res.end('Please access /index.bundle for entry bundling.')
146
- } else if (/^\/debugger-ui\//.test(urlObj.pathname || '')) {
147
- next()
148
- } else {
149
- metroMiddleware(req, res, next)
150
- }
151
- })
55
+ cliParams.push('--port', config.port)
152
56
  }
153
-
154
- // 支持host
155
- return Metro.runServer(metroConfig, {
156
- ...commonOptions,
157
- hmrEnabled: true,
158
- websocketEndpoints
159
- }).then(server => {
160
- console.log(`React-Native Dev server is running on port: ${metroConfig.server.port}`)
161
- console.log('\n\nTo reload the app press "r"\nTo open developer menu press "d"\n')
162
-
163
- readline.emitKeypressEvents(process.stdin)
164
- process.stdin.setRawMode && process.stdin.setRawMode(true)
165
- process.stdin.on('keypress', (_key, data) => {
166
- const { ctrl, name } = data
167
- if (name === 'r') {
168
- messageSocketEndpoint.broadcast('reload')
169
- console.log('Reloading app...')
170
- } else if (name === 'd') {
171
- messageSocketEndpoint.broadcast('devMenu')
172
- console.log('Opening developer menu...')
173
- } else if (ctrl && (name === 'c')) {
174
- process.exit()
175
- }
57
+ try {
58
+ spawn('react-native', ['start'].concat(cliParams), {
59
+ stdio: 'inherit'
176
60
  })
177
-
178
- if (config.qr) {
179
- const host = getOpenHost()
180
- if (host) {
181
- const url = `taro://${host}:${metroConfig.server.port}`
182
- console.log(PLAYGROUNDINFO)
183
- console.log(`print qrcode of '${url}':`)
184
- qr.generate(url, { small: !isWin })
185
- } else {
186
- console.log('print qrcode error: host not found.')
187
- }
188
- }
189
61
  onFinish(null)
190
- return server
191
- }).catch(e => {
62
+ } catch(e) {
192
63
  onFinish(e)
193
- })
64
+ }
194
65
  } else {
195
- const options = {
196
- ...commonOptions,
197
- entry: './index',
198
- out: concatOutputFileName(config)
66
+ const bundleOutput = config.bundleOutput ? config.bundleOutput : (isIos ? config.output.ios : config.output.android)
67
+ cliParams.push('--bundle-output', bundleOutput)
68
+
69
+ const sourcemapOutput = config.sourcemapOutput ? config.sourcemapOutput : (isIos ? config.output.iosSourcemapOutput : config.output.androidSourcemapOutput)
70
+ if (sourcemapOutput) {
71
+ cliParams.push('--sourcemap-output', sourcemapOutput)
199
72
  }
200
- const savedBuildFunc = outputBundle.build
201
- outputBundle.build = async (packagerClient, requestOptions) => {
202
- const resolutionFn = await getResolveDependencyFn(packagerClient.getBundler().getBundler(), requestOptions.platform)
203
- // try for test case build_noWatch
204
- try {
205
- requestOptions.entryFile = resolutionFn(metroConfig.projectRoot, requestOptions.entryFile)
206
- } catch (e) {}
207
- return savedBuildFunc(packagerClient, requestOptions)
73
+
74
+ const sourceMapUrl = config.sourceMapUrl ? config.sourceMapUrl : (isIos ? config.output.iosSourceMapUrl : config.output.androidSourceMapUrl)
75
+ if (sourceMapUrl) {
76
+ cliParams.push('--sourcemap-use-absolute-path', sourceMapUrl)
208
77
  }
209
78
 
210
- const server = new Server(metroConfig)
79
+ const sourcemapSourcesRoot = config.sourcemapSourcesRoot ? config.sourcemapSourcesRoot : (isIos ? config.output.iosSourcemapSourcesRoot : config.output.androidSourcemapSourcesRoot)
80
+ if (sourcemapSourcesRoot) {
81
+ cliParams.push('--sourcemap-sources-root', sourcemapSourcesRoot)
82
+ }
211
83
 
212
- const sourceMapOption = getOutputSourceMapOption(config)
84
+ const assetsDest = config.assetsDest ? config.assetsDest : (isIos ? config.output.iosAssetsDest : config.output.androidAssetsDest)
85
+ cliParams.push('--assets-dest', assetsDest)
213
86
 
214
87
  try {
215
- const requestOptions = {
216
- ...commonOptions,
217
- ...sourceMapOption,
218
- entryFile: options.entry,
219
- inlineSourceMap: false,
220
- createModuleIdFactory: metroConfig.serializer.createModuleIdFactory
221
- }
222
- const bundle = await outputBundle.build(server, requestOptions)
223
- const outputOptions = {
224
- ...commonOptions,
225
- ...sourceMapOption,
226
- bundleOutput: options.out
227
- }
228
- await outputBundle.save(bundle, outputOptions, console.log)
229
-
230
- // Save the assets of the bundle
231
- const outputAssets = await server.getAssets({
232
- ...Server.DEFAULT_BUNDLE_OPTIONS,
233
- ...requestOptions
88
+ spawn('react-native', [
89
+ 'bundle',
90
+ '--platform',
91
+ config.deviceType,
92
+ '--entry-file',
93
+ 'index.js'
94
+ ].concat(cliParams), {
95
+ stdio: 'inherit'
234
96
  })
235
- const assetsDest = concatOutputAssetsDest(config)
236
- return await saveAssets(outputAssets, options.platform, assetsDest).then(() => {
237
- if (config.qr) {
238
- preview({
239
- out: options.out,
240
- assetsDest,
241
- platform: options.platform
242
- })
243
- }
244
- onFinish(null)
245
- })
246
- } catch (e) {
97
+ onFinish(null)
98
+ } catch(e) {
247
99
  onFinish(e)
248
- } finally {
249
- server.end()
250
100
  }
251
101
  }
252
102
  }
@@ -0,0 +1 @@
1
+ import '@tarojs/rn-supporter/entry-file.js'
@@ -0,0 +1,11 @@
1
+ const { mergeConfig } = require('metro-config')
2
+ const { getMetroConfig } = require('@tarojs/rn-supporter')
3
+
4
+ module.exports = mergeConfig({
5
+ // custom your metro config here
6
+ // https://facebook.github.io/metro/docs/configuration
7
+ resolver: {}
8
+ }, getMetroConfig({
9
+ // whether to print the preview QR code
10
+ qr: process.env.NODE_ENV !== 'production'
11
+ }))
@@ -1,57 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const FileStore = require("metro-cache/src/stores/FileStore");
13
- class ConditionalFileStore {
14
- constructor(options, entryName) {
15
- this.ignoreEntryFileCache = false;
16
- this._fileStore = new FileStore(options);
17
- this.entryName = entryName || 'app';
18
- }
19
- isEntryCache(cacheItem) {
20
- if (!cacheItem)
21
- return false;
22
- const { dependencies } = cacheItem;
23
- if (!dependencies || !dependencies.length) {
24
- return false;
25
- }
26
- for (const d of dependencies) {
27
- if (d.name.includes(`${this.entryName}.config`)) {
28
- return true;
29
- }
30
- }
31
- return false;
32
- }
33
- get(key) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const result = yield this._fileStore.get(key);
36
- if (result && this.ignoreEntryFileCache && this.isEntryCache(result)) {
37
- return null;
38
- }
39
- return result;
40
- });
41
- }
42
- set(key, value) {
43
- var _a, _b, _c, _d, _e;
44
- return __awaiter(this, void 0, void 0, function* () {
45
- // fix: 样式文件不写缓存
46
- if (((_e = (_d = (_c = (_b = (_a = value === null || value === void 0 ? void 0 : value.output) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.functionMap) === null || _d === void 0 ? void 0 : _d.names) === null || _e === void 0 ? void 0 : _e.indexOf('ignoreStyleFileCache')) > -1) {
47
- return;
48
- }
49
- return yield this._fileStore.set(key, value);
50
- });
51
- }
52
- clear() {
53
- this._fileStore.clear();
54
- }
55
- }
56
- exports.default = ConditionalFileStore;
57
- //# sourceMappingURL=conditional-file-store.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"conditional-file-store.js","sourceRoot":"","sources":["../../src/config/conditional-file-store.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,8DAA6D;AAE7D,MAAqB,oBAAoB;IAKvC,YAAa,OAAY,EAAE,SAAkB;QAJ7C,yBAAoB,GAAG,KAAK,CAAA;QAK1B,IAAI,CAAC,UAAU,GAAG,IAAI,SAAS,CAAI,OAAO,CAAC,CAAA;QAC3C,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,KAAK,CAAA;IACrC,CAAC;IAED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ports.getRNConfigOutput = exports.getRNConfigEntry = exports.getRNConfigBabelPlugin = exports.getRNConfig = exports.getConfig = void 0;
4
- const lodash_1 = require("lodash");
5
- const fs = require('fs');
6
- let config;
7
- let rnConfig;
8
- const getConfig = () => {
9
- if (config)
10
- return config;
11
- const fileName = `${process.cwd()}/config/index.js`;
12
- if (fs.existsSync(fileName)) {
13
- config = require(`${process.cwd()}/config/index`)(lodash_1.merge);
14
- return config;
15
- }
16
- else {
17
- console.warn('缺少项目基本配置');
18
- config = {};
19
- return config;
20
- }
21
- };
22
- exports.getConfig = getConfig;
23
- const getRNConfig = () => {
24
- getConfig();
25
- if (rnConfig)
26
- return rnConfig;
27
- if (config.rn) {
28
- rnConfig = config.rn;
29
- }
30
- else {
31
- rnConfig = {};
32
- }
33
- return rnConfig;
34
- };
35
- exports.getRNConfig = getRNConfig;
36
- const getRNConfigEntry = () => {
37
- getRNConfig();
38
- return rnConfig.entry || 'app';
39
- };
40
- exports.getRNConfigEntry = getRNConfigEntry;
41
- const getRNConfigOutput = (p) => {
42
- getRNConfig();
43
- if (rnConfig.output) {
44
- if (p === 'ios') {
45
- return rnConfig.output.ios;
46
- }
47
- else {
48
- return rnConfig.output.android;
49
- }
50
- }
51
- else {
52
- return null;
53
- }
54
- };
55
- exports.getRNConfigOutput = getRNConfigOutput;
56
- const getRNConfigTransformer = () => {
57
- getRNConfig();
58
- if (rnConfig.transformer) {
59
- return rnConfig.transformer;
60
- }
61
- else {
62
- return null;
63
- }
64
- };
65
- exports.getRNConfigTransformer = getRNConfigTransformer;
66
- const getRNConfigBabelPlugin = () => {
67
- getRNConfig();
68
- if (rnConfig.babelPlugin) {
69
- return rnConfig.babelPlugin;
70
- }
71
- else {
72
- return null;
73
- }
74
- };
75
- exports.getRNConfigBabelPlugin = getRNConfigBabelPlugin;
76
- //# sourceMappingURL=config-holder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config-holder.js","sourceRoot":"","sources":["../../src/config/config-holder.ts"],"names":[],"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CAAA;SAC3B;aAAM;YACL,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAA;SAC/B;KACF;SAAM;QACL,OAAO,IAAI,CAAA;KACZ;AACH,CAAC,CAAA;AAoB0E,8CAAiB;AAlB5F,MAAM,sBAAsB,GAAG,GAAG,EAAE;IAClC,WAAW,EAAE,CAAA;IACb,IAAI,QAAQ,CAAC,WAAW,EAAE;QACxB,OAAO,QAAQ,CAAC,WAAW,CAAA;KAC5B;SAAM;QACL,OAAO,IAAI,CAAA;KACZ;AACH,CAAC,CAAA;AAW6F,wDAAsB;AATpH,MAAM,sBAAsB,GAAG,GAAG,EAAE;IAClC,WAAW,EAAE,CAAA;IACb,IAAI,QAAQ,CAAC,WAAW,EAAE;QACxB,OAAO,QAAQ,CAAC,WAAW,CAAA;KAC5B;SAAM;QACL,OAAO,IAAI,CAAA;KACZ;AACH,CAAC,CAAA;AAEgC,wDAAsB"}
@@ -1,57 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.defaultConfig = void 0;
13
- const findProjectRoot_1 = require("@react-native-community/cli/build/tools/config/findProjectRoot");
14
- const resolveReactNativePath_1 = require("@react-native-community/cli/build/tools/config/resolveReactNativePath");
15
- const rn_supporter_1 = require("@tarojs/rn-supporter");
16
- const Metro = require("metro");
17
- const os = require("os");
18
- const path = require("path");
19
- const conditional_file_store_1 = require("./conditional-file-store");
20
- const reactNativePath = (0, resolveReactNativePath_1.default)((0, findProjectRoot_1.default)());
21
- const defaultConfig = getDefaultConfig();
22
- exports.defaultConfig = defaultConfig;
23
- function getDefaultConfig() {
24
- const supporter = new rn_supporter_1.Supporter({ fromRunner: true });
25
- const taroMetroConfig = supporter.getMetroConfig();
26
- const metroConfig = {
27
- transformer: taroMetroConfig.transformer,
28
- resolver: taroMetroConfig.resolver,
29
- serializer: {
30
- // We can include multiple copies of InitializeCore here because metro will
31
- // only add ones that are already part of the bundle
32
- getModulesRunBeforeMainModule: () => [
33
- require.resolve(path.join(reactNativePath, 'Libraries/Core/InitializeCore'))
34
- ],
35
- getPolyfills: () => require(path.join(reactNativePath, 'rn-get-polyfills'))()
36
- },
37
- cacheStores: [new conditional_file_store_1.default({
38
- root: path.join(os.tmpdir(), 'metro-cache')
39
- })],
40
- server: {
41
- port: 8081
42
- }
43
- };
44
- return metroConfig;
45
- }
46
- exports.default = (config) => __awaiter(void 0, void 0, void 0, function* () {
47
- const metroConfig = getDefaultConfig();
48
- const res = yield Metro.loadConfig({}, metroConfig);
49
- if (!res.cacheStores || (res.cacheStores.length !== 1) || !(res.cacheStores[0] instanceof conditional_file_store_1.default)) {
50
- throw new Error("cacheStores shouldn't be overridden in metro config.");
51
- }
52
- if (config.entry) {
53
- res.cacheStores[0].entryName = config.entry;
54
- }
55
- return res;
56
- });
57
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oGAA4F;AAC5F,kHAA0G;AAC1G,uDAAgD;AAChD,+BAA8B;AAC9B,yBAAwB;AACxB,6BAA4B;AAE5B,qEAA2D;AAE3D,MAAM,eAAe,GAAW,IAAA,gCAAsB,EAAC,IAAA,yBAAe,GAAE,CAAC,CAAA;AAyBzE,MAAM,aAAa,GAAgB,gBAAgB,EAAE,CAAA;AAyC5C,sCAAa;AAvCtB,SAAS,gBAAgB;IACvB,MAAM,SAA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AC,CAAC,SAAS,GAAG,MAAM,CAAC,KAAK,CAAA;KAC5C;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA,CAAA"}
@@ -1,102 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const fs_1 = require("fs");
4
- const http_1 = require("http");
5
- const mime = require("mime-types");
6
- const path_1 = require("path");
7
- const qr = require("qrcode-terminal");
8
- const url_1 = require("url");
9
- const utils_1 = require("../utils");
10
- const drawableFileTypes = new Set([
11
- 'gif',
12
- 'jpeg',
13
- 'jpg',
14
- 'png',
15
- 'webp',
16
- 'xml'
17
- ]);
18
- function getAndroidAssetSuffix(scale) {
19
- switch (scale) {
20
- case 0.75:
21
- return 'ldpi';
22
- case 1:
23
- return 'mdpi';
24
- case 1.5:
25
- return 'hdpi';
26
- case 2:
27
- return 'xhdpi';
28
- case 3:
29
- return 'xxhdpi';
30
- case 4:
31
- return 'xxxhdpi';
32
- default:
33
- return '';
34
- }
35
- }
36
- function getAndroidResourceFolderName(pathname) {
37
- const ext = (0, path_1.extname)(pathname).replace(/^./, '').toLowerCase();
38
- if (!drawableFileTypes.has(ext)) {
39
- return 'raw';
40
- }
41
- const suffix = getAndroidAssetSuffix(1); // TODO: auto scale
42
- const androidFolder = `drawable-${suffix}`;
43
- return androidFolder;
44
- }
45
- function getAndroidResourceIdentifier(pathname) {
46
- if (pathname[0] === '/') {
47
- pathname = pathname.substr(1);
48
- }
49
- const ext = (0, path_1.extname)(pathname).toLowerCase();
50
- const extReg = new RegExp(ext + '$');
51
- return pathname
52
- .replace(extReg, '')
53
- .toLowerCase()
54
- .replace(/\//g, '_')
55
- .replace(/([^a-z0-9_])/g, '')
56
- .replace(/^assets_/, '') + ext;
57
- }
58
- exports.default = (opt) => {
59
- const port = process.env.PORT || 8079;
60
- const host = `http://${(0, utils_1.getOpenHost)()}:${port}`;
61
- (0, http_1.createServer)(function (request, response) {
62
- const url = new url_1.URL(request.url || '', host);
63
- console.log(`${request.method} ${request.url}`);
64
- if (url.pathname === '/inspector/device') {
65
- response.writeHead(404);
66
- response.end('404', 'utf-8');
67
- return;
68
- }
69
- let filePath;
70
- const contentType = mime.lookup(url.pathname);
71
- if (url.pathname === '/index.js') {
72
- filePath = opt.out;
73
- }
74
- else if (opt.platform === 'ios') {
75
- filePath = (0, path_1.join)(opt.assetsDest || '', url.pathname);
76
- }
77
- else if (opt.platform === 'android') {
78
- filePath = (0, path_1.join)(opt.assetsDest || '', getAndroidResourceFolderName(url.pathname), getAndroidResourceIdentifier(url.pathname));
79
- }
80
- (0, fs_1.readFile)(filePath, function (error, content) {
81
- if (error) {
82
- if (error.code === 'ENOENT') {
83
- response.writeHead(404);
84
- response.end('404', 'utf-8');
85
- }
86
- else {
87
- response.writeHead(500);
88
- response.end('500', 'utf-8');
89
- }
90
- }
91
- else {
92
- response.writeHead(200, { 'Content-Type': contentType });
93
- response.end(content, 'utf-8');
94
- }
95
- });
96
- }).listen(port);
97
- const url = `${host}/index.js`;
98
- console.log(utils_1.PLAYGROUNDINFO);
99
- console.log(`print qrcode of ${opt.platform} bundle '${url}':`);
100
- qr.generate(url, { small: !utils_1.isWin });
101
- };
102
- //# sourceMappingURL=preview.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"preview.js","sourceRoot":"","sources":["../../src/config/preview.ts"],"names":[],"mappings":";;AAAA,2BAA6B;AAC7B,+BAAmC;AACnC,mCAAkC;AAClC,+BAAoC;AACpC,sCAAqC;AACrC,6BAAyB;AAEzB,oCAA6D;AAQ7D,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAS;IACxC,KAAK;IACL,MAAM;IACN,KAAK;IACL,KAAK;IACL,MAAM;IACN,KAAK;CACN,CAAC,CAAA;AAEF,SAAS,qBAAqB,CAAE,KAAa;IAC3C,QAAQ,KAAK,EAAE;QACb,KAAK,IAAI;YACP,OAAO,MAAM,CAAA;QACf,KAAK,CAAC;YACJ,OAAO,MAAM,CAAA;QACf,KAAK,GAAG;YACN,O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