Skip to content

Commit

Permalink
Lite version (#7647)
Browse files Browse the repository at this point in the history
* fix user links

* add gradio as dependency to lite

* tweak

* fiiiiix

* fix deps

* changes

* asd

* asd

* asd

* asd

* fixed

* asd

* asd

* asd

* asd

* asd

* asd

* asd

* fgh

* asd

* asd

* asd

* asd

* add changeset

* prevent duplicate dependency entries

* Update .changeset/changeset.cjs

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
  • Loading branch information
3 people committed Mar 8, 2024
1 parent d0688b3 commit 57510f9
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 22 deletions.
83 changes: 69 additions & 14 deletions .changeset/changeset.cjs
@@ -1,10 +1,17 @@
const { getPackagesSync } = require("@manypkg/get-packages");
const dependents_graph = require("@changesets/get-dependents-graph");

const gh = require("@changesets/get-github-info");
const { existsSync, readFileSync, writeFileSync } = require("fs");
const { join } = require("path");

const { getInfo, getInfoFromPullRequest } = gh;
const { packages, rootDir } = getPackagesSync(process.cwd());
const pkg_data = getPackagesSync(process.cwd());
const { packages, rootDir } = pkg_data;
const dependents = dependents_graph.getDependentsGraph({
packages,
root: pkg_data.rootPackage
});

/**
* @typedef {{packageJson: {name: string, python?: boolean}, dir: string}} Package
Expand Down Expand Up @@ -34,6 +41,10 @@ function find_packages_dirs(package_name) {
return package_dirs;
}

let lines = {
_handled: []
};

const changelogFunctions = {
/**
*
Expand Down Expand Up @@ -76,7 +87,53 @@ const changelogFunctions = {
* @param {any} dependency The dependency that has been updated
* @returns {string} The formatted dependency
*/
(dependency) => ` - ${dependency.name}@${dependency.newVersion}`
(dependency) => {
const updates = dependents.get(dependency.name);

if (updates && updates.length > 0) {
updates.forEach((update) => {
if (!lines[update]) {
lines[update] = {
dirs: find_packages_dirs(update),
current_changelog: "",
feat: [],
fix: [],
highlight: [],
previous_version: packages.find(
(p) => p.packageJson.name === update
).packageJson.version,
dependencies: []
};

const changelog_path = join(
//@ts-ignore
lines[update].dirs[1] || lines[update].dirs[0],
"CHANGELOG.md"
);

if (existsSync(changelog_path)) {
//@ts-ignore
lines[update].current_changelog = readFileSync(
changelog_path,
"utf-8"
)
.replace(`# ${update}`, "")
.trim();
}
}
lines[update].dependencies.push(
` - ${dependency.name}@${dependency.newVersion}`
);
});
}

return ` - ${dependency.name}@${dependency.newVersion}`;
}
);

writeFileSync(
join(rootDir, ".changeset", "_changelog.json"),
JSON.stringify(lines, null, 2)
);

return [changesetLink, ...updatedDepenenciesList].join("\n");
Expand Down Expand Up @@ -151,11 +208,14 @@ const changelogFunctions = {
};
})();

const user_link = /\[(@[^]+)\]/.exec(links.user);
const users =
usersFromSummary && usersFromSummary.length
? usersFromSummary
.map((userFromSummary) => `@${userFromSummary}`)
.join(", ")
: user_link
? user_link[1]
: links.user;

const prefix = [
Expand All @@ -174,31 +234,26 @@ const changelogFunctions = {
/**
* @type { ChangesetMeta & { _handled: string[] } }}
*/
let lines;
if (existsSync(join(rootDir, ".changeset", "_changelog.json"))) {
lines = JSON.parse(
readFileSync(join(rootDir, ".changeset", "_changelog.json"), "utf-8")
);
} else {
lines = {
_handled: []
};
}

if (lines._handled.includes(changeset.id)) {
return "done";
}
lines._handled.push(changeset.id);

changeset.releases.forEach((release) => {
if (!lines[release.name])
if (!lines[release.name]) {
lines[release.name] = {
dirs: find_packages_dirs(release.name),
current_changelog: "",
feat: [],
fix: [],
highlight: []
highlight: [],
previous_version: packages.find(
(p) => p.packageJson.name === release.name
).packageJson.version,
dependencies: []
};
}

const changelog_path = join(
//@ts-ignore
Expand Down
37 changes: 32 additions & 5 deletions .changeset/fix_changelogs.cjs
Expand Up @@ -44,19 +44,46 @@ function run() {
}, /** @type {{[key:string] : PackageMeta}} */ ({}));

for (const pkg_name in packages) {
const { dirs, highlight, feat, fix, current_changelog } =
const { dirs, highlight, feat, fix, current_changelog, dependencies } =
/**@type {ChangesetMeta} */ (packages[pkg_name]);

if (pkg_name === "@gradio/lite") {
const target = all_packages.gradio.packageJson.version.split(".");

const current_version = packages[pkg_name].previous_version.split(".");

if (!packages.gradio) {
const patch = parseInt(current_version[2]) + 1;
const new_version = [target[0], target[1], patch];
all_packages[pkg_name].packageJson.version = new_version.join(".");
} else {
if (parseInt(target[1]) > parseInt(current_version[1])) {
all_packages[pkg_name].packageJson.version = target.join(".");
} else if (parseInt(target[1]) === parseInt(current_version[1])) {
const patch = parseInt(current_version[2]) + 1;
const new_version = [target[0], target[1], patch];
all_packages[pkg_name].packageJson.version = new_version.join(".");
}
}

writeFileSync(
join(all_packages[pkg_name].dir, "package.json"),
JSON.stringify(all_packages[pkg_name].packageJson, null, "\t")
);
}

const { version, python } = all_packages[pkg_name].packageJson;

const highlights = highlight.map((h) => `${h.summary}`);
const features = feat.map((f) => `- ${f.summary}`);
const fixes = fix.map((f) => `- ${f.summary}`);
const highlights = highlight?.map((h) => `${h.summary}`) || [];
const features = feat?.map((f) => `- ${f.summary}`) || [];
const fixes = fix?.map((f) => `- ${f.summary}`) || [];
const deps = Array.from(new Set(dependencies?.map((d) => d.trim()))) || [];

const release_notes = /** @type {[string[], string][]} */ ([
[highlights, "### Highlights"],
[features, "### Features"],
[fixes, "### Fixes"]
[fixes, "### Fixes"],
[deps, "### Dependency updates"]
])
.filter(([s], i) => s.length > 0)
.map(([lines, title]) => {
Expand Down
5 changes: 5 additions & 0 deletions .changeset/tender-women-tie.md
@@ -0,0 +1,5 @@
---
"@gradio/lite": patch
---

feat:Lite version
3 changes: 3 additions & 0 deletions js/lite/package.json
Expand Up @@ -12,6 +12,9 @@
"scripts": {
"build": "pnpm --filter @gradio/app build:lite"
},
"dependencies": {
"gradio": "workspace:^"
},
"devDependencies": {
"@gradio/app": "workspace:^",
"@gradio/wasm": "workspace:^",
Expand Down
7 changes: 4 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 57510f9

Please sign in to comment.