|
| 1 | +const fetch = require("node-fetch"); |
| 2 | +const fs = require("fs"); |
| 3 | +const path = require("path"); |
| 4 | +const nativeJSON = require("./data/native.json"); |
| 5 | + |
| 6 | +(async function() { |
| 7 | + // console.log(cliJSON); |
| 8 | + |
| 9 | + nativeJSON.map(writePage); |
| 10 | +}()); |
| 11 | + |
| 12 | +function writePage(page) { |
| 13 | + const data = [ |
| 14 | + renderFrontmatter(page), |
| 15 | + renderReadme(page), |
| 16 | + // renderUsage(page), |
| 17 | + // renderProperties(page), |
| 18 | + // renderEvents(page), |
| 19 | + // renderMethods(page), |
| 20 | + // renderParts(page), |
| 21 | + // renderCustomProps(page), |
| 22 | + // renderSlots(page) |
| 23 | + ].join(""); |
| 24 | + |
| 25 | + const path = `docs/native/plugins/${page.packageName.replace('@ionic-native/','')}.md`; |
| 26 | + fs.writeFileSync(path, data); |
| 27 | +} |
| 28 | + |
| 29 | +function renderFrontmatter({ displayName }) { |
| 30 | + const frontmatter = { |
| 31 | + title: displayName |
| 32 | + }; |
| 33 | + |
| 34 | + return `--- |
| 35 | +${Object.entries(frontmatter) |
| 36 | + .map(([key, value]) => `${key}: ${value}`) |
| 37 | + .join("\n")} |
| 38 | +--- |
| 39 | +
|
| 40 | +`; |
| 41 | +} |
| 42 | + |
| 43 | +function renderReadme({ description, displayName }) { |
| 44 | + return ` |
| 45 | +# ${displayName} |
| 46 | +
|
| 47 | +${description}`; |
| 48 | +} |
| 49 | + |
| 50 | +// function renderUsage({ usage }) { |
| 51 | +// const keys = Object.keys(usage); |
| 52 | + |
| 53 | +// if (keys.length === 0) { |
| 54 | +// return ""; |
| 55 | +// } |
| 56 | + |
| 57 | +// if (keys.length === 1) { |
| 58 | +// return ` |
| 59 | +// ## Usage |
| 60 | + |
| 61 | +// ${usage[keys[0]]} |
| 62 | +// `; |
| 63 | +// } |
| 64 | + |
| 65 | +// return ` |
| 66 | +// ## Usage |
| 67 | + |
| 68 | +// <Tabs defaultValue="${keys[0]}" values={[${keys |
| 69 | +// .map(key => `{ value: '${key}', label: '${key.toUpperCase()}' }`) |
| 70 | +// .join(", ")}]}> |
| 71 | + |
| 72 | +// ${Object.entries(usage) |
| 73 | +// .map( |
| 74 | +// ([key, value]) => ` |
| 75 | +// <TabItem value="${key}"> |
| 76 | + |
| 77 | +// ${value} |
| 78 | + |
| 79 | +// </TabItem> |
| 80 | +// ` |
| 81 | +// ) |
| 82 | +// .join("\n")} |
| 83 | +// </Tabs> |
| 84 | +// `; |
| 85 | +// } |
| 86 | + |
| 87 | +// function renderProperties({ props: properties }) { |
| 88 | +// if (properties.length === 0) { |
| 89 | +// return ""; |
| 90 | +// } |
| 91 | + |
| 92 | +// return ` |
| 93 | +// ## Properties |
| 94 | + |
| 95 | +// ${properties |
| 96 | +// .map( |
| 97 | +// prop => ` |
| 98 | +// ### ${prop.name} |
| 99 | + |
| 100 | +// | | | |
| 101 | +// | --- | --- | |
| 102 | +// | **Description** | ${prop.docs.split("\n").join("<br />")} | |
| 103 | +// | **Attribute** | \`${prop.attr}\` | |
| 104 | +// | **Type** | \`${prop.type.replace(/\|/g, "\\|")}\` | |
| 105 | +// | **Default** | \`${prop.default}\` | |
| 106 | + |
| 107 | +// ` |
| 108 | +// ) |
| 109 | +// .join("\n")} |
| 110 | +// `; |
| 111 | +// } |
| 112 | + |
| 113 | +// function renderEvents({ events }) { |
| 114 | +// if (events.length === 0) { |
| 115 | +// return ""; |
| 116 | +// } |
| 117 | + |
| 118 | +// return ` |
| 119 | +// ## Events |
| 120 | + |
| 121 | +// | Name | Description | |
| 122 | +// | --- | --- | |
| 123 | +// ${events.map(event => `| \`${event.event}\` | ${event.docs} |`).join("\n")} |
| 124 | + |
| 125 | +// `; |
| 126 | +// } |
| 127 | + |
| 128 | +// function renderMethods({ methods }) { |
| 129 | +// if (methods.length === 0) { |
| 130 | +// return ""; |
| 131 | +// } |
| 132 | + |
| 133 | +// return ` |
| 134 | +// ## Methods |
| 135 | + |
| 136 | +// ${methods |
| 137 | +// .map( |
| 138 | +// method => ` |
| 139 | +// ### ${method.name} |
| 140 | + |
| 141 | +// | | | |
| 142 | +// | --- | --- | |
| 143 | +// | **Description** | ${method.docs.split("\n").join("<br />")} | |
| 144 | +// | **Signature** | \`${method.signature.replace(/\|/g, "\\|")}\` | |
| 145 | +// ` |
| 146 | +// ) |
| 147 | +// .join("\n")} |
| 148 | + |
| 149 | +// `; |
| 150 | +// } |
| 151 | + |
| 152 | +// function renderParts({ parts }) { |
| 153 | +// if (parts.length === 0) { |
| 154 | +// return ""; |
| 155 | +// } |
| 156 | + |
| 157 | +// return ` |
| 158 | +// ## CSS Shadow Parts |
| 159 | + |
| 160 | +// | Name | Description | |
| 161 | +// | --- | --- | |
| 162 | +// ${parts.map(prop => `| \`${prop.name}\` | ${prop.docs} |`).join("\n")} |
| 163 | + |
| 164 | +// `; |
| 165 | +// } |
| 166 | + |
| 167 | +// function renderCustomProps({ styles: customProps }) { |
| 168 | +// if (customProps.length === 0) { |
| 169 | +// return ""; |
| 170 | +// } |
| 171 | + |
| 172 | +// return ` |
| 173 | +// ## CSS Custom Properties |
| 174 | + |
| 175 | +// | Name | Description | |
| 176 | +// | --- | --- | |
| 177 | +// ${customProps.map(prop => `| \`${prop.name}\` | ${prop.docs} |`).join("\n")} |
| 178 | + |
| 179 | +// `; |
| 180 | +// } |
| 181 | + |
| 182 | +// function renderSlots({ slots }) { |
| 183 | +// if (slots.length === 0) { |
| 184 | +// return ""; |
| 185 | +// } |
| 186 | + |
| 187 | +// return ` |
| 188 | +// ## Slots |
| 189 | + |
| 190 | +// | Name | Description | |
| 191 | +// | --- | --- | |
| 192 | +// ${slots.map(slot => `| \`${slot.name}\` | ${slot.docs} |`).join("\n")} |
| 193 | + |
| 194 | +// `; |
| 195 | +// } |
| 196 | + |
0 commit comments