This repository has been archived by the owner on Jan 9, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpack.ts
77 lines (68 loc) · 3.28 KB
/
pack.ts
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
import {execSync} from "child_process";
import {resolve} from "path";
import {existsSync, readFileSync, rmSync, writeFileSync} from "fs";
import CLIParser from "./utils/CLIParser";
function packPackage(packageDirectory: string){
const packageFilename = execSync("npm pack", {cwd: packageDirectory})
.toString()
.split("\n")
.filter(line => line.trim())
.pop();
return resolve(packageDirectory, packageFilename);
}
// pack fullstacked main package
export const fullstackedPackage = packPackage(".");
function installPackageInPackage(packageDirectory: string, packageToInstall: string, dev?: boolean){
execSync(`npm i ${packageToInstall} ${dev ? "-D" : ""}`, {cwd: packageDirectory, stdio: "inherit"});
}
const toPack = CLIParser.getCommandLineArgumentsValues({
packages: {
type: "string[]"
}
})
function installPackageThenPack(packageToPack: string, packageToInstall: string){
if(toPack?.packages && !toPack.packages.includes(packageToPack))
return;
packageToPack = "packages/" + packageToPack;
installPackageInPackage(packageToPack, packageToInstall);
return packPackage(packageToPack);
}
function removePackages(packageLocation: string, packages: string[]){
packageLocation = "packages/" + packageLocation
const packageJSON = JSON.parse(readFileSync(packageLocation + "/package.json").toString());
packages.forEach(packageName => {
delete packageJSON.devDependencies[packageName];
delete packageJSON.dependencies[packageName];
});
writeFileSync(packageLocation + "/package.json", JSON.stringify(packageJSON, null, 2));
if(existsSync(packageLocation + "/node_modules"))
rmSync(packageLocation + "/node_modules", {recursive: true});
if(existsSync(packageLocation + "/package-lock.json"))
rmSync(packageLocation + "/package-lock.json");
}
// pack packages
export const buildPackage = installPackageThenPack("build" , fullstackedPackage);
export const runPackage = installPackageThenPack("run" , fullstackedPackage);
export const watchPackage = installPackageThenPack("watch" , fullstackedPackage);
export const deployPackage = installPackageThenPack("deploy" , fullstackedPackage);
export const backupPackage = installPackageThenPack("backup" , fullstackedPackage);
export const sharePackage = installPackageThenPack("share" , fullstackedPackage);
export const syncPackage = installPackageThenPack("sync" , fullstackedPackage);
export const webappPackage = installPackageThenPack("webapp" , fullstackedPackage);
export const createPackage = installPackageThenPack("create" , fullstackedPackage);
// gui
const guiLocation = "gui";
if(!toPack?.packages || toPack.packages.includes(guiLocation)){
removePackages(guiLocation, [
"@fullstacked/build",
"@fullstacked/deploy",
"@fullstacked/watch",
"@fullstacked/webapp"
]);
const guiPackageLocation = "packages/" + guiLocation;
installPackageInPackage(guiPackageLocation, buildPackage, true);
installPackageInPackage(guiPackageLocation, deployPackage, true);
installPackageInPackage(guiPackageLocation, watchPackage, true);
installPackageInPackage(guiPackageLocation, webappPackage, true);
}
export const guiPackage = installPackageThenPack(guiLocation, fullstackedPackage);