UNPKG

3.37 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.docs = exports.contributing = exports.community = exports.blog = void 0;
7exports.getOS = getOS;
8exports.setPlatform = setPlatform;
9exports.setVersion = setVersion;
10exports.showcase = void 0;
11function _os() {
12 const data = _interopRequireDefault(require("os"));
13 _os = function () {
14 return data;
15 };
16 return data;
17}
18function _assert() {
19 const data = _interopRequireDefault(require("assert"));
20 _assert = function () {
21 return data;
22 };
23 return data;
24}
25function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26// No platform specific documentation
27
28function getOS() {
29 // Using os.platform instead of process.platform so we can test more easily. Once jest upgrades
30 // to ^29.4 we could use process.platforms and jest.replaceProperty(process, 'platforms', 'someplatform');
31 switch (_os().default.platform()) {
32 case 'aix':
33 case 'freebsd':
34 case 'linux':
35 case 'openbsd':
36 case 'sunos':
37 // King of controversy, right here.
38 return 'linux';
39 case 'darwin':
40 return 'macos';
41 case 'win32':
42 return 'windows';
43 default:
44 return '';
45 }
46}
47let _platform = null;
48let _version;
49/**
50 * Create a deeplink to our documentation based on the user's OS and the Platform they're trying to build.
51 */
52function doclink(section, path, platform, hashOrOverrides) {
53 const url = new URL('https://reactnative.dev/');
54
55 // Overrides
56 const isObj = typeof hashOrOverrides === 'object';
57 const hash = isObj ? hashOrOverrides.hash : hashOrOverrides;
58 const version = isObj && hashOrOverrides.version ? hashOrOverrides.version : _version;
59 const OS = isObj && hashOrOverrides.os ? hashOrOverrides.os : getOS();
60 url.pathname = _version ? `${section}/${version}/${path}` : `${section}/${path}`;
61 url.searchParams.set('os', OS);
62 if (platform === 'inherit') {
63 _assert().default.ok(_platform !== null, `Please report this CLI error: link.setPlatform('ios'|'android'|'none') was expected to be set before using link.${section}(${path}, 'inherit').`);
64 }
65 const plat = platform === 'inherit' ? _platform : platform ?? _platform;
66 if (plat !== 'none') {
67 url.searchParams.set('platform', plat);
68 }
69 if (isObj) {
70 const otherKeys = Object.keys(hashOrOverrides).filter(key => !['hash', 'version', 'os'].includes(key));
71 for (let key of otherKeys) {
72 url.searchParams.set(key, hashOrOverrides[key]);
73 }
74 }
75 if (hash) {
76 _assert().default.doesNotMatch(hash, /#/, "Anchor links should be written without a '#'");
77 url.hash = hash;
78 }
79 return url.toString();
80}
81const docs = doclink.bind(null, 'docs');
82exports.docs = docs;
83const contributing = doclink.bind(null, 'contributing');
84exports.contributing = contributing;
85const community = doclink.bind(null, 'community');
86exports.community = community;
87const showcase = doclink.bind(null, 'showcase');
88exports.showcase = showcase;
89const blog = doclink.bind(null, 'blog');
90
91/**
92 * When the user builds, we should define the target platform globally.
93 */
94exports.blog = blog;
95function setPlatform(target) {
96 _platform = target;
97}
98
99/**
100 * Can we figure out what version of react native they're using?
101 */
102function setVersion(reactNativeVersion) {
103 _version = reactNativeVersion;
104}
105
106//# sourceMappingURL=doclink.ts.map
\No newline at end of file