UNPKG

3.09 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 }; }
26function getOS() {
27 // Using os.platform instead of process.platform so we can test more easily. Once jest upgrades
28 // to ^29.4 we could use process.platforms and jest.replaceProperty(process, 'platforms', 'someplatform');
29 switch (_os().default.platform()) {
30 case 'aix':
31 case 'freebsd':
32 case 'linux':
33 case 'openbsd':
34 case 'sunos':
35 // King of controversy, right here.
36 return 'linux';
37 case 'darwin':
38 return 'macos';
39 case 'win32':
40 return 'windows';
41 default:
42 return '';
43 }
44}
45let _platform = 'android';
46let _version;
47/**
48 * Create a deeplink to our documentation based on the user's OS and the Platform they're trying to build.
49 */
50function doclink(section, path, hashOrOverrides) {
51 const url = new URL('https://reactnative.dev/');
52
53 // Overrides
54 const isObj = typeof hashOrOverrides === 'object';
55 const hash = isObj ? hashOrOverrides.hash : hashOrOverrides;
56 const version = isObj && hashOrOverrides.version ? hashOrOverrides.version : _version;
57 const OS = isObj && hashOrOverrides.os ? hashOrOverrides.os : getOS();
58 const platform = isObj && hashOrOverrides.platform ? hashOrOverrides.platform : _platform;
59 url.pathname = _version ? `${section}/${version}/${path}` : `${section}/${path}`;
60 url.searchParams.set('os', OS);
61 url.searchParams.set('platform', platform);
62 if (isObj) {
63 const otherKeys = Object.keys(hashOrOverrides).filter(key => !['hash', 'version', 'os', 'platform'].includes(key));
64 for (let key of otherKeys) {
65 url.searchParams.set(key, hashOrOverrides[key]);
66 }
67 }
68 if (hash) {
69 _assert().default.doesNotMatch(hash, /#/, "Anchor links should be written withou a '#'");
70 url.hash = hash;
71 }
72 return url.toString();
73}
74const docs = doclink.bind(null, 'docs');
75exports.docs = docs;
76const contributing = doclink.bind(null, 'contributing');
77exports.contributing = contributing;
78const community = doclink.bind(null, 'community');
79exports.community = community;
80const showcase = doclink.bind(null, 'showcase');
81exports.showcase = showcase;
82const blog = doclink.bind(null, 'blog');
83
84/**
85 * When the user builds, we should define the target platform globally.
86 */
87exports.blog = blog;
88function setPlatform(target) {
89 _platform = target;
90}
91
92/**
93 * Can we figure out what version of react native they're using?
94 */
95function setVersion(reactNativeVersion) {
96 _version = reactNativeVersion;
97}
98
99//# sourceMappingURL=doclink.js.map
\No newline at end of file