-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshims.js
39 lines (32 loc) · 1.02 KB
/
shims.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
const fs = require('fs');
/**
* Writes new files as shims for libraries that share interfaces but not code
* across client platforms.
*
* e.g. Making remote server requests requires fetch() for React Native and
* "node-fetch" in Node.js and "whatwg-fetch" when in a browser.
*/
/**
* @param {String} platform
*/
function makeShims(platform) {
makeShim(platform, 'fetch');
makeShim(platform, 'storage');
}
/*
* @param {String} platform
* @param {String} lib
*/
function makeShim(platform, lib) {
console.log(`Creating the ${platform} ${lib} shim for the zeit-client-api`);
let destFilePath = `${__dirname}/${lib}.js`;
let sourceFilePath = `${__dirname}/shims/${lib}.${platform}.js`;
fs.writeFileSync(destFilePath, fs.readFileSync(sourceFilePath));
}
// When creating shims from a Node process, say from the command line...
if (process.argv) {
// We're assuming Node is the default platform being used
(() => { makeShims((process.argv[2] || 'node').toLowerCase()); })();
}
module.exports = makeShims;