mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-16 19:57:52 +01:00
misc: add script for generating flatpak sources
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,3 +9,4 @@ nx-cloud.env
|
|||||||
.env.local
|
.env.local
|
||||||
.nyc_output
|
.nyc_output
|
||||||
site
|
site
|
||||||
|
node_modules.backup
|
||||||
37
packages/crypto/package-lock.json
generated
37
packages/crypto/package-lock.json
generated
@@ -1,37 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@notesnook/crypto",
|
|
||||||
"version": "1.0.1",
|
|
||||||
"lockfileVersion": 2,
|
|
||||||
"requires": true,
|
|
||||||
"packages": {
|
|
||||||
"": {
|
|
||||||
"name": "@notesnook/crypto",
|
|
||||||
"version": "1.0.1",
|
|
||||||
"license": "GPL-3.0-or-later",
|
|
||||||
"devDependencies": {
|
|
||||||
"typescript": "^4.8.2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/typescript": {
|
|
||||||
"version": "4.8.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz",
|
|
||||||
"integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==",
|
|
||||||
"dev": true,
|
|
||||||
"bin": {
|
|
||||||
"tsc": "bin/tsc",
|
|
||||||
"tsserver": "bin/tsserver"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4.2.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"typescript": {
|
|
||||||
"version": "4.8.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz",
|
|
||||||
"integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==",
|
|
||||||
"dev": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
103
scripts/generate-sources.mjs
Normal file
103
scripts/generate-sources.mjs
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
This file is part of the Notesnook project (https://notesnook.com/)
|
||||||
|
|
||||||
|
Copyright (C) 2023 Streetwriters (Private) Limited
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { $, fs, path, which } from "zx";
|
||||||
|
|
||||||
|
function uniqBy(a, key) {
|
||||||
|
let seen = new Set();
|
||||||
|
return a.filter((item) => {
|
||||||
|
let k = key(item);
|
||||||
|
if (!k) return true;
|
||||||
|
return seen.has(k) ? false : seen.add(k);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$.env = process.env;
|
||||||
|
$.quote = (s) => s;
|
||||||
|
|
||||||
|
const generators = await which("flatpak-node-generator");
|
||||||
|
|
||||||
|
if (generators.length <= 0)
|
||||||
|
throw new Error(
|
||||||
|
"flatpak-node-generator not found. Please install flatpak-node-generator from https://github.com/flatpak/flatpak-builder-tools."
|
||||||
|
);
|
||||||
|
|
||||||
|
const lockfiles = [
|
||||||
|
{
|
||||||
|
name: "main",
|
||||||
|
path: path.join(__dirname, "..", "package-lock.json"),
|
||||||
|
ignoreDev: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "desktop",
|
||||||
|
path: path.join(__dirname, "..", "apps", "desktop", "package-lock.json")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "sodium",
|
||||||
|
path: path.join(__dirname, "..", "packages", "sodium", "package-lock.json")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "crypto",
|
||||||
|
path: path.join(__dirname, "..", "packages", "crypto", "package-lock.json")
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
let allSources = [];
|
||||||
|
for (const lockfile of lockfiles) {
|
||||||
|
if (!fs.existsSync(lockfile.path)) {
|
||||||
|
console.error("skipping. lockfile does not exist at", lockfile.path);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
console.log("generating sources for", lockfile.name);
|
||||||
|
|
||||||
|
const nodeModulesPath = path.join(
|
||||||
|
path.dirname(lockfile.path),
|
||||||
|
"node_modules"
|
||||||
|
);
|
||||||
|
console.log("backing up node_modules at", nodeModulesPath);
|
||||||
|
fs.moveSync(
|
||||||
|
nodeModulesPath,
|
||||||
|
path.join(path.dirname(lockfile.path), "node_modules.backup")
|
||||||
|
);
|
||||||
|
|
||||||
|
const output = `${lockfile.name}-sources.json`;
|
||||||
|
await $`flatpak-node-generator${
|
||||||
|
lockfile.ignoreDev ? " --no-devel" : ""
|
||||||
|
} npm ${lockfile.path} -o ${output}`;
|
||||||
|
|
||||||
|
const sources = JSON.parse(fs.readFileSync(output, "utf-8"));
|
||||||
|
allSources = [...allSources, ...sources];
|
||||||
|
|
||||||
|
fs.rmSync(output, { force: true });
|
||||||
|
|
||||||
|
console.log("recovering node_modules to", nodeModulesPath);
|
||||||
|
fs.moveSync(
|
||||||
|
path.join(path.dirname(lockfile.path), "node_modules.backup"),
|
||||||
|
nodeModulesPath
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("writing sources");
|
||||||
|
|
||||||
|
fs.writeFileSync(
|
||||||
|
"generated-sources.json",
|
||||||
|
JSON.stringify(uniqBy(allSources, (i) => i.url))
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log("done");
|
||||||
Reference in New Issue
Block a user