forked from solidjs-community/solid-primitives
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlerna.js
More file actions
85 lines (82 loc) · 3.75 KB
/
lerna.js
File metadata and controls
85 lines (82 loc) · 3.75 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const { loadPackages, iter } = require("lerna-script");
const fs = require("fs").promises;
const path = require("path");
// ------------------------------------------------------------
// Generates a new README with updates primitive details
// ------------------------------------------------------------
async function updateReadme(log) {
log.info("updateReadme", "Updating README documentation");
const markdownMagic = require("markdown-magic");
const tablemark = require("json-to-markdown-table");
const githubURL = "https://github.com/davedbase/solid-primitives/tree/main/packages/";
const sizeShield = "https://img.shields.io/bundlephobia/minzip/";
const bundlephobiaURL = "https://bundlephobia.com/package/";
const npmShield = "https://img.shields.io/npm/v/";
const npmURL = "https://www.npmjs.com/package/";
let categories = {};
// Retrieve packages managed by Lerna
await iter.forEach(await loadPackages())(async lernaPackage => {
const pkgData = await fs.readFile(`${lernaPackage.location}/package.json`, "utf8");
const package = JSON.parse(pkgData);
if (!package.primitive) {
return;
}
const { name, list, category, stage } = package.primitive;
if (name) {
let data = {};
data.Name = `[${name}](${githubURL}${name})`;
// Detect the stage and build size/version only if needed
if (data.Stage == "X" || data.Stage == 0) {
data.Size = "";
data.NPM = "";
} else {
data.Size = `[](${bundlephobiaURL}${lernaPackage.name})`;
data.NPM = `[](${npmURL}${lernaPackage.name})`;
}
// data.Stage = stage ? stage.toString() : "2";
data.Stage = `[ : "2"
}.json)](https://github.com/davedbase/solid-primitives#contribution-process)`;
data.Primitives = list.join("<br />");
// Merge the package into the correct category
let cat = category || "Misc";
categories[cat] = Array.isArray(categories[cat]) ? [...categories[cat], data] : [data];
}
});
// Generate and insert collected package data into Markdown
return new Promise(resolve => {
markdownMagic(
path.join(__dirname, "README.md"),
{
transforms: {
GENERATE_PRIMITIVES_TABLE: () => {
return Object.entries(categories).reduce((md, [category, items]) => {
// Some MD jousting to get the table to render nicely
// with consistent columns
md += `|<br />*${category}*<br /><br />|\n`;
md += tablemark(items, ["Name", "Stage", "Primitives", "Size", "NPM"])
.replace("|Name|Stage|Primitives|Size|NPM|\n", "")
.replace("|----|----|----|----|----|\n", "");
return md;
}, "|Name|Stage|Primitives|Size|NPM|\n|----|----|----|----|----|\n");
}
}
},
resolve
);
});
}
// ------------------------------------------------------------
// Create a new primitive folder based on the default template
// ------------------------------------------------------------
async function createPrimitive(log) {
const shell = require("child_process").execSync;
const { join } = require("path");
const packageName = process.argv.pop();
const src = join(__dirname, "template");
const dest = join(__dirname, "packages", packageName);
shell(`mkdir -p ${dest}`);
shell(`cp -r ${src}/* ${dest}`);
}
module.exports.updateReadme = updateReadme;
module.exports.createPrimitive = createPrimitive;