mlcl 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +31 -0
- package/.eslintrc.json +54 -0
- package/LICENSE +200 -0
- package/README.md +101 -0
- package/babel.config.json +10 -0
- package/build/API/authorization.js +107 -0
- package/build/API/client.js +11 -0
- package/build/API/index.js +8 -0
- package/build/API/molecule/index.js +11 -0
- package/build/API/molecule/types.js +6 -0
- package/build/API/resource/device/index.js +12 -0
- package/build/API/resource/device/types.js +6 -0
- package/build/API/resource/device/utilities/confirmSshKey.js +20 -0
- package/build/API/resource/device/utilities/index.js +7 -0
- package/build/API/resource/device/utilities/sendSshKey.js +64 -0
- package/build/API/resource/index.js +10 -0
- package/build/API/resource/molecule/index.js +12 -0
- package/build/API/resource/molecule/types.js +6 -0
- package/build/API/resource/molecule/utilities/getPlan.js +15 -0
- package/build/API/resource/molecule/utilities/index.js +6 -0
- package/build/API/resource/payment/index.js +9 -0
- package/build/API/resource/payment/plans.js +28 -0
- package/build/API/resource/payment/platform.js +7 -0
- package/build/API/resource/payment/platforms/apple/index.js +21 -0
- package/build/API/resource/payment/platforms/apple/plans/appleMonthly.js +17 -0
- package/build/API/resource/payment/platforms/apple/plans/appleYearly.js +18 -0
- package/build/API/resource/payment/platforms/apple/plans/index.js +7 -0
- package/build/API/resource/payment/platforms/google/index.js +21 -0
- package/build/API/resource/payment/platforms/google/plans/googleMonthly.js +17 -0
- package/build/API/resource/payment/platforms/google/plans/googleYearly.js +18 -0
- package/build/API/resource/payment/platforms/google/plans/index.js +7 -0
- package/build/API/resource/payment/platforms/index.js +8 -0
- package/build/API/resource/payment/platforms/stripe/index.js +25 -0
- package/build/API/resource/payment/platforms/stripe/plans/index.js +11 -0
- package/build/API/resource/payment/platforms/stripe/plans/stripeBusinessMolecule.js +21 -0
- package/build/API/resource/payment/platforms/stripe/plans/stripeMonthly.js +18 -0
- package/build/API/resource/payment/platforms/stripe/plans/stripeMonthlyMolecule.js +18 -0
- package/build/API/resource/payment/platforms/stripe/plans/stripeSingleUseMolecule.js +19 -0
- package/build/API/resource/payment/platforms/stripe/plans/stripeUnlimitedUseMolecule.js +19 -0
- package/build/API/resource/payment/platforms/stripe/plans/stripeYearly.js +19 -0
- package/build/API/resource/payment/types.js +6 -0
- package/build/API/resource/types.js +6 -0
- package/build/API/resource/user/index.js +15 -0
- package/build/API/resource/user/types.js +6 -0
- package/build/API/resource/user/utilities/getPlan.js +12 -0
- package/build/API/resource/user/utilities/index.js +7 -0
- package/build/API/resource/user/utilities/logIn.js +60 -0
- package/build/cli.js +15 -0
- package/build/commands/add-ssh-key.js +24 -0
- package/build/commands/buy.js +70 -0
- package/build/commands/clone.js +329 -0
- package/build/commands/index.js +17 -0
- package/build/commands/info.js +33 -0
- package/build/commands/login.js +20 -0
- package/build/commands/logout.js +23 -0
- package/build/commands/molecule/index.js +11 -0
- package/build/commands/molecule/types.js +6 -0
- package/build/commands/remove-ssh-key.js +36 -0
- package/build/commands/select.js +98 -0
- package/build/commands/set-api-key.js +73 -0
- package/build/commands/subscribe.js +74 -0
- package/build/commands/unsubscribe.js +59 -0
- package/build/commands/utilities/asyncExec.js +6 -0
- package/build/commands/utilities/branchExists.js +13 -0
- package/build/commands/utilities/branchExistsSync.js +12 -0
- package/build/commands/utilities/checkoutSelectionBranch.js +49 -0
- package/build/commands/utilities/cherryPick.js +20 -0
- package/build/commands/utilities/cloneRepo.js +9 -0
- package/build/commands/utilities/convertNpmToYarn.js +60 -0
- package/build/commands/utilities/convertTypeDocToJSDoc.js +51 -0
- package/build/commands/utilities/convertTypeScriptToJavaScript.js +451 -0
- package/build/commands/utilities/enableMergeDrivers.js +50 -0
- package/build/commands/utilities/getCurrentBranch.js +11 -0
- package/build/commands/utilities/getCurrentBranchSync.js +7 -0
- package/build/commands/utilities/getRepoRootPath.js +7 -0
- package/build/commands/utilities/getRepoRootPathSync.js +13 -0
- package/build/commands/utilities/index.js +16 -0
- package/build/commands/utilities/npm-to-yarn.js +41 -0
- package/build/commands/utilities/ts-to-js.js +344 -0
- package/build/commands/version.js +14 -0
- package/build/commands/x-merge-json.js +33 -0
- package/build/config.js +5 -0
- package/build/environment.js +80 -0
- package/build/index.js +23 -0
- package/build/logger.js +12 -0
- package/build/pkg.js +5 -0
- package/build/repoConfig copy.js +5 -0
- package/build/repoConfig.js +5 -0
- package/build/types/global.js +6 -0
- package/build/types/index.js +6 -0
- package/build/userConfig.js +5 -0
- package/build/utilities/__tests__/getErrorMessage.js +26 -0
- package/build/utilities/__tests__/timeAgo.js +39 -0
- package/build/utilities/checkVersion.js +29 -0
- package/build/utilities/getErrorMessage.js +15 -0
- package/build/utilities/index.js +13 -0
- package/build/utilities/readConfig.js +19 -0
- package/build/utilities/readRepoConfig copy.js +20 -0
- package/build/utilities/readRepoConfig.js +19 -0
- package/build/utilities/readUserConfig.js +20 -0
- package/build/utilities/synchronizeUserConfig.js +25 -0
- package/build/utilities/timeAgo.js +42 -0
- package/build/utilities/userLoggedIn.js +24 -0
- package/build/utilities/writeConfig.js +8 -0
- package/build/utilities/writeRepoConfig copy.js +9 -0
- package/build/utilities/writeRepoConfig.js +10 -0
- package/build/utilities/writeUserConfig.js +11 -0
- package/jest.config.json +11 -0
- package/package.json +56 -0
- package/src/API/authorization.ts +143 -0
- package/src/API/client.ts +12 -0
- package/src/API/index.ts +10 -0
- package/src/API/resource/device/index.ts +27 -0
- package/src/API/resource/device/types.ts +80 -0
- package/src/API/resource/device/utilities/confirmSshKey.ts +25 -0
- package/src/API/resource/device/utilities/index.ts +8 -0
- package/src/API/resource/device/utilities/sendSshKey.ts +80 -0
- package/src/API/resource/index.ts +12 -0
- package/src/API/resource/molecule/index.ts +30 -0
- package/src/API/resource/molecule/types.ts +332 -0
- package/src/API/resource/molecule/utilities/getPlan.ts +21 -0
- package/src/API/resource/molecule/utilities/index.ts +7 -0
- package/src/API/resource/payment/index.ts +12 -0
- package/src/API/resource/payment/plans.ts +32 -0
- package/src/API/resource/payment/platform.ts +11 -0
- package/src/API/resource/payment/platforms/apple/index.ts +25 -0
- package/src/API/resource/payment/platforms/apple/plans/appleMonthly.ts +19 -0
- package/src/API/resource/payment/platforms/apple/plans/appleYearly.ts +20 -0
- package/src/API/resource/payment/platforms/apple/plans/index.ts +9 -0
- package/src/API/resource/payment/platforms/google/index.ts +25 -0
- package/src/API/resource/payment/platforms/google/plans/googleMonthly.ts +19 -0
- package/src/API/resource/payment/platforms/google/plans/googleYearly.ts +20 -0
- package/src/API/resource/payment/platforms/google/plans/index.ts +9 -0
- package/src/API/resource/payment/platforms/index.ts +10 -0
- package/src/API/resource/payment/platforms/stripe/index.ts +29 -0
- package/src/API/resource/payment/platforms/stripe/plans/index.ts +12 -0
- package/src/API/resource/payment/platforms/stripe/plans/stripeBusinessMolecule.ts +23 -0
- package/src/API/resource/payment/platforms/stripe/plans/stripeMonthly.ts +20 -0
- package/src/API/resource/payment/platforms/stripe/plans/stripeMonthlyMolecule.ts +20 -0
- package/src/API/resource/payment/platforms/stripe/plans/stripeSingleUseMolecule.ts +21 -0
- package/src/API/resource/payment/platforms/stripe/plans/stripeUnlimitedUseMolecule.ts +21 -0
- package/src/API/resource/payment/platforms/stripe/plans/stripeYearly.ts +21 -0
- package/src/API/resource/payment/types.ts +201 -0
- package/src/API/resource/types.ts +169 -0
- package/src/API/resource/user/index.ts +29 -0
- package/src/API/resource/user/types.ts +131 -0
- package/src/API/resource/user/utilities/getPlan.ts +16 -0
- package/src/API/resource/user/utilities/index.ts +8 -0
- package/src/API/resource/user/utilities/logIn.ts +71 -0
- package/src/commands/add-ssh-key.ts +30 -0
- package/src/commands/buy.ts +83 -0
- package/src/commands/clone.ts +363 -0
- package/src/commands/index.ts +19 -0
- package/src/commands/info.ts +40 -0
- package/src/commands/login.ts +24 -0
- package/src/commands/logout.ts +27 -0
- package/src/commands/remove-ssh-key.ts +42 -0
- package/src/commands/subscribe.ts +84 -0
- package/src/commands/unsubscribe.ts +67 -0
- package/src/commands/utilities/asyncExec.ts +7 -0
- package/src/commands/utilities/branchExists.ts +15 -0
- package/src/commands/utilities/checkoutSelectionBranch.ts +62 -0
- package/src/commands/utilities/cherryPick.ts +23 -0
- package/src/commands/utilities/cloneRepo.ts +10 -0
- package/src/commands/utilities/convertNpmToYarn.ts +71 -0
- package/src/commands/utilities/convertTypeDocToJSDoc.ts +55 -0
- package/src/commands/utilities/convertTypeScriptToJavaScript.ts +526 -0
- package/src/commands/utilities/enableMergeDrivers.ts +55 -0
- package/src/commands/utilities/getCurrentBranch.ts +14 -0
- package/src/commands/utilities/getRepoRootPathSync.ts +13 -0
- package/src/commands/utilities/index.ts +17 -0
- package/src/commands/version.ts +22 -0
- package/src/commands/x-merge-json.ts +41 -0
- package/src/environment.ts +88 -0
- package/src/index.ts +30 -0
- package/src/logger.ts +29 -0
- package/src/pkg.ts +11 -0
- package/src/repoConfig.ts +6 -0
- package/src/types/global.ts +26 -0
- package/src/types/index.ts +53 -0
- package/src/types/process.env.d.ts +56 -0
- package/src/userConfig.ts +6 -0
- package/src/utilities/__tests__/getErrorMessage.ts +32 -0
- package/src/utilities/__tests__/timeAgo.ts +46 -0
- package/src/utilities/checkVersion.ts +31 -0
- package/src/utilities/getErrorMessage.ts +30 -0
- package/src/utilities/index.ts +14 -0
- package/src/utilities/readRepoConfig.ts +22 -0
- package/src/utilities/readUserConfig.ts +24 -0
- package/src/utilities/synchronizeUserConfig.ts +26 -0
- package/src/utilities/timeAgo.ts +39 -0
- package/src/utilities/userLoggedIn.ts +28 -0
- package/src/utilities/writeRepoConfig.ts +11 -0
- package/src/utilities/writeUserConfig.ts +13 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import open from 'open';
|
|
2
|
+
import { userLoggedIn } from '../utilities/userLoggedIn.js';
|
|
3
|
+
import { repoConfig } from '../repoConfig.js';
|
|
4
|
+
import * as API from '../API/index.js';
|
|
5
|
+
import { logger } from '../logger.js';
|
|
6
|
+
import { getErrorMessage } from '../utilities/getErrorMessage.js';
|
|
7
|
+
import { plans } from '../API/resource/payment/plans.js';
|
|
8
|
+
/**
|
|
9
|
+
* Adds the `subscribe` command to the program.
|
|
10
|
+
*/
|
|
11
|
+
export const subscribe = (program) => {
|
|
12
|
+
program.command(`subscribe`)
|
|
13
|
+
.description(`enables or renews your Molecule's subscription`)
|
|
14
|
+
.action(async () => {
|
|
15
|
+
const user = await userLoggedIn();
|
|
16
|
+
if (!user) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (!repoConfig?.id) {
|
|
20
|
+
logger.warn(`Not within a Molecule repository or \`.mlclrc.json\` not found.`);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const molecule = (await API.resource.molecule.read(repoConfig.id)).data.props;
|
|
25
|
+
if (!molecule) {
|
|
26
|
+
throw new Error(`Failed to fetch Molecule by ID ${repoConfig.id}.`);
|
|
27
|
+
}
|
|
28
|
+
const planKey = molecule.planKey || ``;
|
|
29
|
+
const planAutoRenews = molecule.planAutoRenews;
|
|
30
|
+
const planExpiresAt = molecule.planExpiresAt;
|
|
31
|
+
const planExpiresDate = planKey
|
|
32
|
+
? (planAutoRenews || plans[planKey].autoRenews)
|
|
33
|
+
? planExpiresAt && new Date(planExpiresAt)
|
|
34
|
+
: null
|
|
35
|
+
: undefined;
|
|
36
|
+
const planExpiresLocaleString = (planExpiresDate && planExpiresDate.toLocaleString()) || `never`;
|
|
37
|
+
if (planKey && (planAutoRenews || !plans[planKey].autoRenews)) {
|
|
38
|
+
if (planAutoRenews) {
|
|
39
|
+
logger.info(`Your Molecule is already subscribed!`);
|
|
40
|
+
logger.info(`Your ${plans[planKey].title} plan will ${planAutoRenews ? `automatically renew` : `expire`} ${planExpiresLocaleString}.`);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
logger.info(`You already have a ${plans[planKey].title} license, so no subscription is necessary.`);
|
|
44
|
+
logger.info(`Thank you!`);
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
logger.info(`Subscribing...`);
|
|
49
|
+
const { props, checkoutUrl } = (await API.resource.molecule.updatePlan(molecule.id, { planKey: `stripeMonthlyMolecule`, quantity: 1 })).data;
|
|
50
|
+
if (checkoutUrl) {
|
|
51
|
+
logger.info(`Opening your browser to complete checkout via Stripe...`);
|
|
52
|
+
const childProcess = await open(checkoutUrl);
|
|
53
|
+
childProcess.on(`error`, error => {
|
|
54
|
+
logger.warn(`Error opening the checkout URL: ${getErrorMessage(error)}`);
|
|
55
|
+
logger.warn(`If your browser didn't open on its own, visit the following URL: ${checkoutUrl}`);
|
|
56
|
+
});
|
|
57
|
+
childProcess.on(`close`, code => {
|
|
58
|
+
if (code !== 0) {
|
|
59
|
+
logger.warn(`If your browser didn't open on its own, visit the following URL: ${checkoutUrl}`);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else if (props?.planKey) {
|
|
64
|
+
logger.info(`Your Molecule is now subscribed! Thank you!`);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
throw new Error(`Unexpected response. Please contact developer-support@molecule.dev so we can fix this.`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
logger.warn(`Failed to subscribe. ${getErrorMessage(error)}`);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { userLoggedIn } from '../utilities/userLoggedIn.js';
|
|
2
|
+
import { repoConfig } from '../repoConfig.js';
|
|
3
|
+
import * as API from '../API/index.js';
|
|
4
|
+
import { logger } from '../logger.js';
|
|
5
|
+
import { getErrorMessage } from '../utilities/getErrorMessage.js';
|
|
6
|
+
import { plans } from '../API/resource/payment/plans.js';
|
|
7
|
+
/**
|
|
8
|
+
* Adds the `unsubscribe` command to the program.
|
|
9
|
+
*/
|
|
10
|
+
export const unsubscribe = (program) => {
|
|
11
|
+
program.command(`unsubscribe`)
|
|
12
|
+
.description(`cancels your Molecule's subscription`)
|
|
13
|
+
.action(async () => {
|
|
14
|
+
const user = await userLoggedIn();
|
|
15
|
+
if (!user) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (!repoConfig?.id) {
|
|
19
|
+
logger.warn(`Not within a Molecule repository or \`.mlclrc.json\` not found.`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const molecule = (await API.resource.molecule.read(repoConfig.id)).data.props;
|
|
24
|
+
if (!molecule) {
|
|
25
|
+
throw new Error(`Failed to fetch Molecule by ID ${repoConfig.id}.`);
|
|
26
|
+
}
|
|
27
|
+
const planKey = molecule.planKey || ``;
|
|
28
|
+
const planAutoRenews = molecule.planAutoRenews;
|
|
29
|
+
const planExpiresAt = molecule.planExpiresAt;
|
|
30
|
+
const planExpiresDate = planKey
|
|
31
|
+
? (planAutoRenews || plans[planKey].autoRenews)
|
|
32
|
+
? planExpiresAt && new Date(planExpiresAt)
|
|
33
|
+
: null
|
|
34
|
+
: undefined;
|
|
35
|
+
const planExpiresLocaleString = (planExpiresDate && planExpiresDate.toLocaleString()) || `never`;
|
|
36
|
+
if (!planAutoRenews) {
|
|
37
|
+
if (planKey && !plans[planKey].autoRenews) {
|
|
38
|
+
logger.info(`You already have a ${plans[planKey].title} license, so there is nothing to unsubscribe.`);
|
|
39
|
+
logger.info(`Thank you!`);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
logger.info(`Your Molecule is not subscribed.`);
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
logger.info(`Unsubscribing...`);
|
|
47
|
+
const { props } = (await API.resource.molecule.updatePlan(molecule.id, { planKey: `` })).data;
|
|
48
|
+
if (props?.planAutoRenews === false) {
|
|
49
|
+
logger.info(`Your Molecule has been unsubscribed and will expire ${planExpiresLocaleString}.`);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throw new Error(`Unexpected response. Please contact developer-support@molecule.dev so we can fix this.`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
logger.warn(`Failed to unsubscribe. ${getErrorMessage(error)}`);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { asyncExec } from './asyncExec.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves `true` if the branch exists.
|
|
4
|
+
*/
|
|
5
|
+
export const branchExists = async (branchName, repoPath = ``, branchPath = `refs/heads`) => {
|
|
6
|
+
try {
|
|
7
|
+
const result = await asyncExec(`git${repoPath ? ` -C "${repoPath}"` : ``} show-ref ${branchPath}/${branchName}`);
|
|
8
|
+
return Boolean(result.stdout);
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
/**
|
|
3
|
+
* Returns `true` if the branch exists.
|
|
4
|
+
*/
|
|
5
|
+
export const branchExistsSync = (branchName, branchPath = `refs/heads`, repoPath = ``) => {
|
|
6
|
+
try {
|
|
7
|
+
return Boolean(execSync(`git ${repoPath ? ` -C "${repoPath}"` : ``} show-ref ${branchPath}/${branchName}`, { encoding: `utf8` }));
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { asyncExec } from './asyncExec.js';
|
|
2
|
+
import { branchExists } from './branchExists.js';
|
|
3
|
+
import { getCurrentBranch } from './getCurrentBranch.js';
|
|
4
|
+
import { logger } from '../../logger.js';
|
|
5
|
+
/**
|
|
6
|
+
* Checks out the branch for the Molecule selection.
|
|
7
|
+
*
|
|
8
|
+
* If it does not yet exist, it will be created as an empty branch.
|
|
9
|
+
*
|
|
10
|
+
* Returns `true` if an empty branch was created.
|
|
11
|
+
*/
|
|
12
|
+
export const checkoutSelectionBranch = async (selectionHash, repoPath = ``, branchPath = ``, resetIfLocalExists = false) => {
|
|
13
|
+
const branchName = `mlcl-${selectionHash}`;
|
|
14
|
+
if (await branchExists(branchName, repoPath, branchPath)) {
|
|
15
|
+
if ((await getCurrentBranch(repoPath)) === branchName) {
|
|
16
|
+
logger.info(`Already on branch ${branchName}.`);
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (/^remotes\/(.+)/.test(branchPath)) {
|
|
20
|
+
logger.info(`Branch ${branchName} exists at ${branchPath}.`);
|
|
21
|
+
logger.info(`Checking out ${branchName} with tracking from ${branchPath}...`);
|
|
22
|
+
await asyncExec(`git${repoPath ? ` -C "${repoPath}"` : ``} checkout --track ${branchPath.replace(/^remotes\//, ``)}/${branchName}`);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
logger.info(`Checking out branch ${branchName}...`);
|
|
26
|
+
await asyncExec(`git${repoPath ? ` -C "${repoPath}"` : ``} checkout ${branchName}`);
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const localBranchExists = await branchExists(branchName, repoPath);
|
|
31
|
+
if (localBranchExists) {
|
|
32
|
+
logger.info(`Branch ${branchName} already exists locally!`);
|
|
33
|
+
if (!resetIfLocalExists) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
// Branch does not yet exist, so create it.
|
|
39
|
+
logger.info(`Creating new orphan branch ${branchName}...`);
|
|
40
|
+
await asyncExec(`git${repoPath ? ` -C "${repoPath}"` : ``} checkout --orphan ${branchName}`);
|
|
41
|
+
}
|
|
42
|
+
// Reset it to an empty repository.
|
|
43
|
+
logger.info(`Resetting branch to an empty repository...`);
|
|
44
|
+
await asyncExec(`git${repoPath ? ` -C "${repoPath}"` : ``} rm -rf .`);
|
|
45
|
+
logger.info(`Creating empty initial commit...`);
|
|
46
|
+
await asyncExec(`git${repoPath ? ` -C "${repoPath}"` : ``} commit --allow-empty -m "initialize empty repository"`);
|
|
47
|
+
logger.info(`Branch ${branchName} is ready for assembly.`);
|
|
48
|
+
return true;
|
|
49
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { asyncExec } from './asyncExec.js';
|
|
2
|
+
import { logger } from '../../logger.js';
|
|
3
|
+
/**
|
|
4
|
+
* Cherry picks the commit onto the current branch.
|
|
5
|
+
*
|
|
6
|
+
* Returns `true` if successful.
|
|
7
|
+
*/
|
|
8
|
+
export const cherryPick = async (commitHash, repoPath = ``, parameters = ``) => {
|
|
9
|
+
try {
|
|
10
|
+
const { stderr } = await asyncExec(`git${repoPath ? ` -C "${repoPath}"` : ``} cherry-pick ${commitHash} ${parameters}`);
|
|
11
|
+
if (stderr) {
|
|
12
|
+
throw new Error(stderr);
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
logger.error(error);
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { logger } from '../../logger.js';
|
|
2
|
+
import { asyncExec } from './asyncExec.js';
|
|
3
|
+
/**
|
|
4
|
+
* Clones a repository by URL to the specified path.
|
|
5
|
+
*/
|
|
6
|
+
export const cloneRepo = (repoUrl, repoPath) => {
|
|
7
|
+
logger.info(`Cloning ${repoUrl} into ${repoPath}...`);
|
|
8
|
+
return asyncExec(`git clone ${repoUrl} ${repoPath}`);
|
|
9
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import glob from 'glob';
|
|
4
|
+
/**
|
|
5
|
+
* A very quick and dirty hacked together script to convert an NPM codebase to a Yarn one.
|
|
6
|
+
*/
|
|
7
|
+
export const convertNpmToYarn = async (cwd = `.`) => {
|
|
8
|
+
try {
|
|
9
|
+
// Add Yarn to prerequisites in README.
|
|
10
|
+
const readmePath = path.join(cwd, `README.md`);
|
|
11
|
+
let README = await fs.promises.readFile(readmePath, `utf8`);
|
|
12
|
+
README = README.replace(`- [Node.js](https://nodejs.org/) (version 16)`, `- [Node.js](https://nodejs.org/) (version 16)
|
|
13
|
+
|
|
14
|
+
- [Yarn](https://yarnpkg.com/getting-started/install)
|
|
15
|
+
|
|
16
|
+
- The recommended way to install Yarn is by enabling [Corepack](https://github.com/nodejs/corepack), which is included by default with the latest Node.js version, but it is opt-in. To enable Corepack, run \`corepack enable\` in your console, which may require elevated permissions (if on Windows, run command prompt as administrator). `);
|
|
17
|
+
await fs.promises.writeFile(readmePath, README);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
// Replace all "npm" descriptions/instructions with "yarn".
|
|
23
|
+
await new Promise((resolve, reject) => {
|
|
24
|
+
glob(`{*.md,**!(node_modules)/*.md,src/**/*.{js,jsx,ts,tsx}}`, { cwd }, async (error, files) => {
|
|
25
|
+
if (error) {
|
|
26
|
+
reject(error);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const replace = async (file) => {
|
|
30
|
+
const filePath = path.join(cwd, file);
|
|
31
|
+
const npmContents = await fs.promises.readFile(filePath, `utf8`);
|
|
32
|
+
const yarnContents = npmContents
|
|
33
|
+
.replace(/npm run/g, `yarn run`)
|
|
34
|
+
.replace(/npm start/g, `yarn start`)
|
|
35
|
+
.replace(/npm install/g, `yarn install`)
|
|
36
|
+
.replace(/npm version/g, `yarn version`)
|
|
37
|
+
.replace(/npm test/g, `yarn test`)
|
|
38
|
+
.replace(/npx cap/g, `yarn run cap`);
|
|
39
|
+
if (npmContents !== yarnContents) {
|
|
40
|
+
await fs.promises.writeFile(filePath, yarnContents);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
await replace(`package.json`);
|
|
44
|
+
try {
|
|
45
|
+
await fs.promises.access(path.join(cwd, `electron/package.json`), fs.constants.R_OK | fs.constants.W_OK);
|
|
46
|
+
await replace(`electron/package.json`);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
}
|
|
50
|
+
await Promise.all(files.map(file => replace(file)));
|
|
51
|
+
// yarn install
|
|
52
|
+
// git add yarn.lock
|
|
53
|
+
// git add electron/yarn.lock
|
|
54
|
+
resolve();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
}
|
|
60
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
/**
|
|
4
|
+
* A very quick and dirty hacked together script to convert TypeDoc usage to JSDoc.
|
|
5
|
+
*/
|
|
6
|
+
export const convertTypeDocToJSDoc = async (cwd = `.`) => {
|
|
7
|
+
try {
|
|
8
|
+
// Replace `typedoc` with `jsdoc` in `package.json`.
|
|
9
|
+
const packageJsonPath = path.join(cwd, `package.json`);
|
|
10
|
+
const packageJson = JSON.parse(await fs.promises.readFile(packageJsonPath, `utf8`));
|
|
11
|
+
delete packageJson.devDependencies.typedoc;
|
|
12
|
+
packageJson.devDependencies.jsdoc = `^3.6.10`;
|
|
13
|
+
packageJson.scripts.docs = `jsdoc -r -c jsdoc.json && open-cli ./docs/index.html`;
|
|
14
|
+
await fs.promises.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
// Replace `typedoc.json` with `jsdoc.json`.
|
|
20
|
+
await fs.promises.rm(path.join(cwd, `typedoc.json`));
|
|
21
|
+
await fs.promises.writeFile(path.join(cwd, `jsdoc.json`), JSON.stringify({
|
|
22
|
+
"source": {
|
|
23
|
+
"include": "./src",
|
|
24
|
+
"includePattern": "\\.jsx?$",
|
|
25
|
+
"excludePattern": "(/|\\\\)__tests__(/|\\\\)|\\.(spec|test)\\.jsx?$"
|
|
26
|
+
},
|
|
27
|
+
"opts": {
|
|
28
|
+
"destination": "./docs",
|
|
29
|
+
"readme": "./README.md"
|
|
30
|
+
},
|
|
31
|
+
"plugins": [
|
|
32
|
+
"plugins/markdown"
|
|
33
|
+
]
|
|
34
|
+
}, null, 2));
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
// Replace all TypeDoc info with JSDoc.
|
|
40
|
+
const readmePath = path.join(cwd, `README.md`);
|
|
41
|
+
let README = await fs.promises.readFile(readmePath, `utf8`);
|
|
42
|
+
README = README
|
|
43
|
+
.replace(/typedoc\.org/g, `jsdoc.app`)
|
|
44
|
+
.replace(/TypeDoc\.org/g, `JSDoc.app`)
|
|
45
|
+
.replace(/typedoc/g, `jsdoc`)
|
|
46
|
+
.replace(/TypeDoc/g, `JSDoc`);
|
|
47
|
+
await fs.promises.writeFile(readmePath, README);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
}
|
|
51
|
+
};
|