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.
Files changed (195) hide show
  1. package/.eslintignore +31 -0
  2. package/.eslintrc.json +54 -0
  3. package/LICENSE +200 -0
  4. package/README.md +101 -0
  5. package/babel.config.json +10 -0
  6. package/build/API/authorization.js +107 -0
  7. package/build/API/client.js +11 -0
  8. package/build/API/index.js +8 -0
  9. package/build/API/molecule/index.js +11 -0
  10. package/build/API/molecule/types.js +6 -0
  11. package/build/API/resource/device/index.js +12 -0
  12. package/build/API/resource/device/types.js +6 -0
  13. package/build/API/resource/device/utilities/confirmSshKey.js +20 -0
  14. package/build/API/resource/device/utilities/index.js +7 -0
  15. package/build/API/resource/device/utilities/sendSshKey.js +64 -0
  16. package/build/API/resource/index.js +10 -0
  17. package/build/API/resource/molecule/index.js +12 -0
  18. package/build/API/resource/molecule/types.js +6 -0
  19. package/build/API/resource/molecule/utilities/getPlan.js +15 -0
  20. package/build/API/resource/molecule/utilities/index.js +6 -0
  21. package/build/API/resource/payment/index.js +9 -0
  22. package/build/API/resource/payment/plans.js +28 -0
  23. package/build/API/resource/payment/platform.js +7 -0
  24. package/build/API/resource/payment/platforms/apple/index.js +21 -0
  25. package/build/API/resource/payment/platforms/apple/plans/appleMonthly.js +17 -0
  26. package/build/API/resource/payment/platforms/apple/plans/appleYearly.js +18 -0
  27. package/build/API/resource/payment/platforms/apple/plans/index.js +7 -0
  28. package/build/API/resource/payment/platforms/google/index.js +21 -0
  29. package/build/API/resource/payment/platforms/google/plans/googleMonthly.js +17 -0
  30. package/build/API/resource/payment/platforms/google/plans/googleYearly.js +18 -0
  31. package/build/API/resource/payment/platforms/google/plans/index.js +7 -0
  32. package/build/API/resource/payment/platforms/index.js +8 -0
  33. package/build/API/resource/payment/platforms/stripe/index.js +25 -0
  34. package/build/API/resource/payment/platforms/stripe/plans/index.js +11 -0
  35. package/build/API/resource/payment/platforms/stripe/plans/stripeBusinessMolecule.js +21 -0
  36. package/build/API/resource/payment/platforms/stripe/plans/stripeMonthly.js +18 -0
  37. package/build/API/resource/payment/platforms/stripe/plans/stripeMonthlyMolecule.js +18 -0
  38. package/build/API/resource/payment/platforms/stripe/plans/stripeSingleUseMolecule.js +19 -0
  39. package/build/API/resource/payment/platforms/stripe/plans/stripeUnlimitedUseMolecule.js +19 -0
  40. package/build/API/resource/payment/platforms/stripe/plans/stripeYearly.js +19 -0
  41. package/build/API/resource/payment/types.js +6 -0
  42. package/build/API/resource/types.js +6 -0
  43. package/build/API/resource/user/index.js +15 -0
  44. package/build/API/resource/user/types.js +6 -0
  45. package/build/API/resource/user/utilities/getPlan.js +12 -0
  46. package/build/API/resource/user/utilities/index.js +7 -0
  47. package/build/API/resource/user/utilities/logIn.js +60 -0
  48. package/build/cli.js +15 -0
  49. package/build/commands/add-ssh-key.js +24 -0
  50. package/build/commands/buy.js +70 -0
  51. package/build/commands/clone.js +329 -0
  52. package/build/commands/index.js +17 -0
  53. package/build/commands/info.js +33 -0
  54. package/build/commands/login.js +20 -0
  55. package/build/commands/logout.js +23 -0
  56. package/build/commands/molecule/index.js +11 -0
  57. package/build/commands/molecule/types.js +6 -0
  58. package/build/commands/remove-ssh-key.js +36 -0
  59. package/build/commands/select.js +98 -0
  60. package/build/commands/set-api-key.js +73 -0
  61. package/build/commands/subscribe.js +74 -0
  62. package/build/commands/unsubscribe.js +59 -0
  63. package/build/commands/utilities/asyncExec.js +6 -0
  64. package/build/commands/utilities/branchExists.js +13 -0
  65. package/build/commands/utilities/branchExistsSync.js +12 -0
  66. package/build/commands/utilities/checkoutSelectionBranch.js +49 -0
  67. package/build/commands/utilities/cherryPick.js +20 -0
  68. package/build/commands/utilities/cloneRepo.js +9 -0
  69. package/build/commands/utilities/convertNpmToYarn.js +60 -0
  70. package/build/commands/utilities/convertTypeDocToJSDoc.js +51 -0
  71. package/build/commands/utilities/convertTypeScriptToJavaScript.js +451 -0
  72. package/build/commands/utilities/enableMergeDrivers.js +50 -0
  73. package/build/commands/utilities/getCurrentBranch.js +11 -0
  74. package/build/commands/utilities/getCurrentBranchSync.js +7 -0
  75. package/build/commands/utilities/getRepoRootPath.js +7 -0
  76. package/build/commands/utilities/getRepoRootPathSync.js +13 -0
  77. package/build/commands/utilities/index.js +16 -0
  78. package/build/commands/utilities/npm-to-yarn.js +41 -0
  79. package/build/commands/utilities/ts-to-js.js +344 -0
  80. package/build/commands/version.js +14 -0
  81. package/build/commands/x-merge-json.js +33 -0
  82. package/build/config.js +5 -0
  83. package/build/environment.js +80 -0
  84. package/build/index.js +23 -0
  85. package/build/logger.js +12 -0
  86. package/build/pkg.js +5 -0
  87. package/build/repoConfig copy.js +5 -0
  88. package/build/repoConfig.js +5 -0
  89. package/build/types/global.js +6 -0
  90. package/build/types/index.js +6 -0
  91. package/build/userConfig.js +5 -0
  92. package/build/utilities/__tests__/getErrorMessage.js +26 -0
  93. package/build/utilities/__tests__/timeAgo.js +39 -0
  94. package/build/utilities/checkVersion.js +29 -0
  95. package/build/utilities/getErrorMessage.js +15 -0
  96. package/build/utilities/index.js +13 -0
  97. package/build/utilities/readConfig.js +19 -0
  98. package/build/utilities/readRepoConfig copy.js +20 -0
  99. package/build/utilities/readRepoConfig.js +19 -0
  100. package/build/utilities/readUserConfig.js +20 -0
  101. package/build/utilities/synchronizeUserConfig.js +25 -0
  102. package/build/utilities/timeAgo.js +42 -0
  103. package/build/utilities/userLoggedIn.js +24 -0
  104. package/build/utilities/writeConfig.js +8 -0
  105. package/build/utilities/writeRepoConfig copy.js +9 -0
  106. package/build/utilities/writeRepoConfig.js +10 -0
  107. package/build/utilities/writeUserConfig.js +11 -0
  108. package/jest.config.json +11 -0
  109. package/package.json +56 -0
  110. package/src/API/authorization.ts +143 -0
  111. package/src/API/client.ts +12 -0
  112. package/src/API/index.ts +10 -0
  113. package/src/API/resource/device/index.ts +27 -0
  114. package/src/API/resource/device/types.ts +80 -0
  115. package/src/API/resource/device/utilities/confirmSshKey.ts +25 -0
  116. package/src/API/resource/device/utilities/index.ts +8 -0
  117. package/src/API/resource/device/utilities/sendSshKey.ts +80 -0
  118. package/src/API/resource/index.ts +12 -0
  119. package/src/API/resource/molecule/index.ts +30 -0
  120. package/src/API/resource/molecule/types.ts +332 -0
  121. package/src/API/resource/molecule/utilities/getPlan.ts +21 -0
  122. package/src/API/resource/molecule/utilities/index.ts +7 -0
  123. package/src/API/resource/payment/index.ts +12 -0
  124. package/src/API/resource/payment/plans.ts +32 -0
  125. package/src/API/resource/payment/platform.ts +11 -0
  126. package/src/API/resource/payment/platforms/apple/index.ts +25 -0
  127. package/src/API/resource/payment/platforms/apple/plans/appleMonthly.ts +19 -0
  128. package/src/API/resource/payment/platforms/apple/plans/appleYearly.ts +20 -0
  129. package/src/API/resource/payment/platforms/apple/plans/index.ts +9 -0
  130. package/src/API/resource/payment/platforms/google/index.ts +25 -0
  131. package/src/API/resource/payment/platforms/google/plans/googleMonthly.ts +19 -0
  132. package/src/API/resource/payment/platforms/google/plans/googleYearly.ts +20 -0
  133. package/src/API/resource/payment/platforms/google/plans/index.ts +9 -0
  134. package/src/API/resource/payment/platforms/index.ts +10 -0
  135. package/src/API/resource/payment/platforms/stripe/index.ts +29 -0
  136. package/src/API/resource/payment/platforms/stripe/plans/index.ts +12 -0
  137. package/src/API/resource/payment/platforms/stripe/plans/stripeBusinessMolecule.ts +23 -0
  138. package/src/API/resource/payment/platforms/stripe/plans/stripeMonthly.ts +20 -0
  139. package/src/API/resource/payment/platforms/stripe/plans/stripeMonthlyMolecule.ts +20 -0
  140. package/src/API/resource/payment/platforms/stripe/plans/stripeSingleUseMolecule.ts +21 -0
  141. package/src/API/resource/payment/platforms/stripe/plans/stripeUnlimitedUseMolecule.ts +21 -0
  142. package/src/API/resource/payment/platforms/stripe/plans/stripeYearly.ts +21 -0
  143. package/src/API/resource/payment/types.ts +201 -0
  144. package/src/API/resource/types.ts +169 -0
  145. package/src/API/resource/user/index.ts +29 -0
  146. package/src/API/resource/user/types.ts +131 -0
  147. package/src/API/resource/user/utilities/getPlan.ts +16 -0
  148. package/src/API/resource/user/utilities/index.ts +8 -0
  149. package/src/API/resource/user/utilities/logIn.ts +71 -0
  150. package/src/commands/add-ssh-key.ts +30 -0
  151. package/src/commands/buy.ts +83 -0
  152. package/src/commands/clone.ts +363 -0
  153. package/src/commands/index.ts +19 -0
  154. package/src/commands/info.ts +40 -0
  155. package/src/commands/login.ts +24 -0
  156. package/src/commands/logout.ts +27 -0
  157. package/src/commands/remove-ssh-key.ts +42 -0
  158. package/src/commands/subscribe.ts +84 -0
  159. package/src/commands/unsubscribe.ts +67 -0
  160. package/src/commands/utilities/asyncExec.ts +7 -0
  161. package/src/commands/utilities/branchExists.ts +15 -0
  162. package/src/commands/utilities/checkoutSelectionBranch.ts +62 -0
  163. package/src/commands/utilities/cherryPick.ts +23 -0
  164. package/src/commands/utilities/cloneRepo.ts +10 -0
  165. package/src/commands/utilities/convertNpmToYarn.ts +71 -0
  166. package/src/commands/utilities/convertTypeDocToJSDoc.ts +55 -0
  167. package/src/commands/utilities/convertTypeScriptToJavaScript.ts +526 -0
  168. package/src/commands/utilities/enableMergeDrivers.ts +55 -0
  169. package/src/commands/utilities/getCurrentBranch.ts +14 -0
  170. package/src/commands/utilities/getRepoRootPathSync.ts +13 -0
  171. package/src/commands/utilities/index.ts +17 -0
  172. package/src/commands/version.ts +22 -0
  173. package/src/commands/x-merge-json.ts +41 -0
  174. package/src/environment.ts +88 -0
  175. package/src/index.ts +30 -0
  176. package/src/logger.ts +29 -0
  177. package/src/pkg.ts +11 -0
  178. package/src/repoConfig.ts +6 -0
  179. package/src/types/global.ts +26 -0
  180. package/src/types/index.ts +53 -0
  181. package/src/types/process.env.d.ts +56 -0
  182. package/src/userConfig.ts +6 -0
  183. package/src/utilities/__tests__/getErrorMessage.ts +32 -0
  184. package/src/utilities/__tests__/timeAgo.ts +46 -0
  185. package/src/utilities/checkVersion.ts +31 -0
  186. package/src/utilities/getErrorMessage.ts +30 -0
  187. package/src/utilities/index.ts +14 -0
  188. package/src/utilities/readRepoConfig.ts +22 -0
  189. package/src/utilities/readUserConfig.ts +24 -0
  190. package/src/utilities/synchronizeUserConfig.ts +26 -0
  191. package/src/utilities/timeAgo.ts +39 -0
  192. package/src/utilities/userLoggedIn.ts +28 -0
  193. package/src/utilities/writeRepoConfig.ts +11 -0
  194. package/src/utilities/writeUserConfig.ts +13 -0
  195. package/tsconfig.json +25 -0
@@ -0,0 +1,15 @@
1
+ import { asyncExec } from './asyncExec.js'
2
+
3
+ /**
4
+ * Resolves `true` if the branch exists.
5
+ */
6
+ export const branchExists = async (branchName: string, repoPath = ``, branchPath = `refs/heads`) => {
7
+ try {
8
+ const result = await asyncExec(`git${repoPath ? ` -C "${repoPath}"` : ``} show-ref ${branchPath}/${branchName}`)
9
+
10
+ return Boolean(result.stdout)
11
+ } catch (error) {
12
+ }
13
+
14
+ return false
15
+ }
@@ -0,0 +1,62 @@
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
+ /**
7
+ * Checks out the branch for the Molecule selection.
8
+ *
9
+ * If it does not yet exist, it will be created as an empty branch.
10
+ *
11
+ * Returns `true` if an empty branch was created.
12
+ */
13
+ export const checkoutSelectionBranch = async (
14
+ selectionHash: string,
15
+ repoPath = ``,
16
+ branchPath = ``,
17
+ resetIfLocalExists = false,
18
+ ) => {
19
+ const branchName = `mlcl-${selectionHash}`
20
+
21
+ if (await branchExists(branchName, repoPath, branchPath)) {
22
+ if ((await getCurrentBranch(repoPath)) === branchName) {
23
+ logger.info(`Already on branch ${branchName}.`)
24
+ return false
25
+ }
26
+
27
+ if (/^remotes\/(.+)/.test(branchPath)) {
28
+ logger.info(`Branch ${branchName} exists at ${branchPath}.`)
29
+ logger.info(`Checking out ${branchName} with tracking from ${branchPath}...`)
30
+ await asyncExec(`git${repoPath ? ` -C "${repoPath}"` : ``} checkout --track ${branchPath.replace(/^remotes\//, ``)}/${branchName}`)
31
+ } else {
32
+ logger.info(`Checking out branch ${branchName}...`)
33
+ await asyncExec(`git${repoPath ? ` -C "${repoPath}"` : ``} checkout ${branchName}`)
34
+ }
35
+
36
+ return false
37
+ }
38
+
39
+ const localBranchExists = await branchExists(branchName, repoPath)
40
+
41
+ if (localBranchExists) {
42
+ logger.info(`Branch ${branchName} already exists locally!`)
43
+
44
+ if (!resetIfLocalExists) {
45
+ return false
46
+ }
47
+ } else {
48
+ // Branch does not yet exist, so create it.
49
+ logger.info(`Creating new orphan branch ${branchName}...`)
50
+ await asyncExec(`git${repoPath ? ` -C "${repoPath}"` : ``} checkout --orphan ${branchName}`)
51
+ }
52
+
53
+ // Reset it to an empty repository.
54
+ logger.info(`Resetting branch to an empty repository...`)
55
+ await asyncExec(`git${repoPath ? ` -C "${repoPath}"` : ``} rm -rf .`)
56
+
57
+ logger.info(`Creating empty initial commit...`)
58
+ await asyncExec(`git${repoPath ? ` -C "${repoPath}"` : ``} commit --allow-empty -m "initialize empty repository"`)
59
+ logger.info(`Branch ${branchName} is ready for assembly.`)
60
+
61
+ return true
62
+ }
@@ -0,0 +1,23 @@
1
+ import { asyncExec } from './asyncExec.js'
2
+ import { logger } from '../../logger.js'
3
+
4
+ /**
5
+ * Cherry picks the commit onto the current branch.
6
+ *
7
+ * Returns `true` if successful.
8
+ */
9
+ export const cherryPick = async (commitHash: string, repoPath = ``, parameters = ``) => {
10
+ try {
11
+ const { stderr } = await asyncExec(`git${repoPath ? ` -C "${repoPath}"` : ``} cherry-pick ${commitHash} ${parameters}`)
12
+
13
+ if (stderr) {
14
+ throw new Error(stderr)
15
+ }
16
+
17
+ return true
18
+ } catch (error) {
19
+ logger.error(error)
20
+ }
21
+
22
+ return false
23
+ }
@@ -0,0 +1,10 @@
1
+ import { logger } from '../../logger.js'
2
+ import { asyncExec } from './asyncExec.js'
3
+
4
+ /**
5
+ * Clones a repository by URL to the specified path.
6
+ */
7
+ export const cloneRepo = (repoUrl: string, repoPath: string) => {
8
+ logger.info(`Cloning ${repoUrl} into ${repoPath}...`)
9
+ return asyncExec(`git clone ${repoUrl} ${repoPath}`)
10
+ }
@@ -0,0 +1,71 @@
1
+ import fs from 'fs'
2
+ import path from 'path'
3
+ import glob from 'glob'
4
+
5
+ /**
6
+ * A very quick and dirty hacked together script to convert an NPM codebase to a Yarn one.
7
+ */
8
+ export const convertNpmToYarn = async (cwd = `.`) => {
9
+ try {
10
+ // Add Yarn to prerequisites in README.
11
+ const readmePath = path.join(cwd, `README.md`)
12
+ let README = await fs.promises.readFile(readmePath, `utf8`)
13
+
14
+ README = README.replace(
15
+ `- [Node.js](https://nodejs.org/) (version 16)`,
16
+ `- [Node.js](https://nodejs.org/) (version 16)
17
+
18
+ - [Yarn](https://yarnpkg.com/getting-started/install)
19
+
20
+ - 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). `
21
+ )
22
+
23
+ await fs.promises.writeFile(readmePath, README)
24
+ } catch (error) {
25
+ }
26
+
27
+ try {
28
+ // Replace all "npm" descriptions/instructions with "yarn".
29
+ await new Promise<void>((resolve, reject) => {
30
+ glob(`{*.md,**!(node_modules)/*.md,src/**/*.{js,jsx,ts,tsx}}`, { cwd }, async (error, files) => {
31
+ if (error) {
32
+ reject(error)
33
+ return
34
+ }
35
+
36
+ const replace = async (file: string) => {
37
+ const filePath = path.join(cwd, file)
38
+ const npmContents = await fs.promises.readFile(filePath, `utf8`)
39
+ const yarnContents = npmContents
40
+ .replace(/npm run/g, `yarn run`)
41
+ .replace(/npm start/g, `yarn start`)
42
+ .replace(/npm install/g, `yarn install`)
43
+ .replace(/npm version/g, `yarn version`)
44
+ .replace(/npm test/g, `yarn test`)
45
+ .replace(/npx cap/g, `yarn run cap`)
46
+
47
+ if (npmContents !== yarnContents) {
48
+ await fs.promises.writeFile(filePath, yarnContents)
49
+ }
50
+ }
51
+
52
+ await replace(`package.json`)
53
+
54
+ try {
55
+ await fs.promises.access(path.join(cwd, `electron/package.json`), fs.constants.R_OK | fs.constants.W_OK)
56
+ await replace(`electron/package.json`)
57
+ } catch (error) {
58
+ }
59
+
60
+ await Promise.all(files.map(file => replace(file)))
61
+
62
+ // yarn install
63
+ // git add yarn.lock
64
+ // git add electron/yarn.lock
65
+
66
+ resolve()
67
+ })
68
+ })
69
+ } catch (error) {
70
+ }
71
+ }
@@ -0,0 +1,55 @@
1
+ import fs from 'fs'
2
+ import path from 'path'
3
+
4
+ /**
5
+ * A very quick and dirty hacked together script to convert TypeDoc usage to JSDoc.
6
+ */
7
+ export const convertTypeDocToJSDoc = async (cwd = `.`) => {
8
+ try {
9
+ // Replace `typedoc` with `jsdoc` in `package.json`.
10
+ const packageJsonPath = path.join(cwd, `package.json`)
11
+ const packageJson = JSON.parse(await fs.promises.readFile(packageJsonPath, `utf8`))
12
+
13
+ delete packageJson.devDependencies.typedoc
14
+ packageJson.devDependencies.jsdoc = `^3.6.10`
15
+ packageJson.scripts.docs = `jsdoc -r -c jsdoc.json && open-cli ./docs/index.html`
16
+
17
+ await fs.promises.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2))
18
+ } catch (error) {
19
+ }
20
+
21
+ try {
22
+ // Replace `typedoc.json` with `jsdoc.json`.
23
+ await fs.promises.rm(path.join(cwd, `typedoc.json`))
24
+ await fs.promises.writeFile(path.join(cwd, `jsdoc.json`), JSON.stringify({
25
+ "source": {
26
+ "include": "./src",
27
+ "includePattern": "\\.jsx?$",
28
+ "excludePattern": "(/|\\\\)__tests__(/|\\\\)|\\.(spec|test)\\.jsx?$"
29
+ },
30
+ "opts": {
31
+ "destination": "./docs",
32
+ "readme": "./README.md"
33
+ },
34
+ "plugins": [
35
+ "plugins/markdown"
36
+ ]
37
+ }, null, 2))
38
+ } catch (error) {
39
+ }
40
+
41
+ try {
42
+ // Replace all TypeDoc info with JSDoc.
43
+ const readmePath = path.join(cwd, `README.md`)
44
+ let README = await fs.promises.readFile(readmePath, `utf8`)
45
+
46
+ README = README
47
+ .replace(/typedoc\.org/g, `jsdoc.app`)
48
+ .replace(/TypeDoc\.org/g, `JSDoc.app`)
49
+ .replace(/typedoc/g, `jsdoc`)
50
+ .replace(/TypeDoc/g, `JSDoc`)
51
+
52
+ await fs.promises.writeFile(readmePath, README)
53
+ } catch (error) {
54
+ }
55
+ }