-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa97088
commit 87d497a
Showing
13 changed files
with
320 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Please, keep this file alphabetically ordered. | ||
*/ | ||
|
||
export * from "./commands/link"; | ||
|
||
export * from "./commands/mklink"; | ||
|
||
export * from "./commands/performLinks"; | ||
export * from "./commands/processGlobalLinks"; | ||
export * from "./commands/resetGlobalLinks"; | ||
|
||
export * from "./commands/unlink"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Yarn } from "../../helpers/Yarn"; | ||
import { App, ILinkOptions } from "../App"; | ||
|
||
/** | ||
* Creates a link for a given package. | ||
* @param link The link options. | ||
*/ | ||
export const link = async (link: ILinkOptions) => { | ||
const app = App.instance(); | ||
|
||
// If no package was given | ||
if (!link.package) { | ||
// If has no package.json | ||
/*if (!app.packageJson) { | ||
throw new Error("No package name was given and also a package.json wasn't found."); | ||
} | ||
// Create a new link for it | ||
const obj = app[link.global ? "globalConfig" : "localConfig"]; | ||
// Create a link for it | ||
obj.links ??= {}; | ||
obj.links[app.packageJson.name] = process.cwd(); | ||
console.log(app); | ||
// Save the configuration files | ||
//app.save(link.global ? "global" : "local");*/ | ||
|
||
// Link the current package | ||
await Yarn.link(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { glob } from "glob"; | ||
import * as path from "path"; | ||
import * as fs from "fs"; | ||
import { logger } from "../Logger"; | ||
import { Yarn } from "../../helpers/Yarn"; | ||
|
||
/** | ||
* Creates multiple links for a given pattern. | ||
* @param link The link options. | ||
*/ | ||
export const mklink = async(link: { | ||
pattern: string; | ||
depth?: number; | ||
}) => { | ||
// If there's no pattern | ||
if (!link.pattern) { | ||
return logger.error("no pattern was given"); | ||
} | ||
|
||
// Remove the last slash from the pattern if has one | ||
if (link.pattern.endsWith("/")) { | ||
link.pattern = link.pattern.substring(0, link.pattern.length - 1); | ||
} | ||
|
||
const possibleProjectPaths = await glob.glob(link.pattern + "/", { | ||
maxDepth: link.depth, | ||
follow: true, | ||
absolute: true, | ||
cwd: process.cwd(), | ||
ignore: "node_modules/**" | ||
}); | ||
|
||
for (const projectPath of possibleProjectPaths) { | ||
const packageJsonPath = path.resolve(projectPath, "package.json"); | ||
|
||
// Ignore if there's no package.json in the folder | ||
if (!fs.existsSync(packageJsonPath)) { | ||
continue; | ||
} | ||
|
||
const packageJson = require(packageJsonPath); | ||
|
||
// Call a link for it | ||
await Yarn.execYarn({ | ||
cmd: "link", | ||
cwd: projectPath | ||
}); | ||
|
||
logger.info("linked package \"%s\"", packageJson.name); | ||
} | ||
}; |
Oops, something went wrong.