@plasmicapp/cli 0.1.162
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/.eslintrc.js +61 -0
- package/.idea/cli.iml +11 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README +16 -0
- package/README.internal +46 -0
- package/README.md +17 -0
- package/build.sh +8 -0
- package/dist/__mocks__/api.d.ts +16 -0
- package/dist/__mocks__/api.js +297 -0
- package/dist/__tests__/code-utils-spec.d.ts +1 -0
- package/dist/__tests__/code-utils-spec.js +838 -0
- package/dist/__tests__/ftue-spec.d.ts +1 -0
- package/dist/__tests__/ftue-spec.js +39 -0
- package/dist/__tests__/project-api-token-spec.d.ts +1 -0
- package/dist/__tests__/project-api-token-spec.js +147 -0
- package/dist/__tests__/versioned-sync-spec.d.ts +1 -0
- package/dist/__tests__/versioned-sync-spec.js +145 -0
- package/dist/actions/auth.d.ts +8 -0
- package/dist/actions/auth.js +47 -0
- package/dist/actions/fix-imports.d.ts +4 -0
- package/dist/actions/fix-imports.js +25 -0
- package/dist/actions/init.d.ts +62 -0
- package/dist/actions/init.js +460 -0
- package/dist/actions/project-token.d.ts +6 -0
- package/dist/actions/project-token.js +42 -0
- package/dist/actions/sync-components.d.ts +10 -0
- package/dist/actions/sync-components.js +242 -0
- package/dist/actions/sync-global-variants.d.ts +3 -0
- package/dist/actions/sync-global-variants.js +89 -0
- package/dist/actions/sync-icons.d.ts +7 -0
- package/dist/actions/sync-icons.js +92 -0
- package/dist/actions/sync-images.d.ts +6 -0
- package/dist/actions/sync-images.js +137 -0
- package/dist/actions/sync-styles.d.ts +3 -0
- package/dist/actions/sync-styles.js +58 -0
- package/dist/actions/sync.d.ts +25 -0
- package/dist/actions/sync.js +417 -0
- package/dist/actions/upload-bundle.d.ts +15 -0
- package/dist/actions/upload-bundle.js +28 -0
- package/dist/actions/watch.d.ts +14 -0
- package/dist/actions/watch.js +90 -0
- package/dist/api.d.ts +182 -0
- package/dist/api.js +202 -0
- package/dist/deps.d.ts +2 -0
- package/dist/deps.js +20 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +247 -0
- package/dist/lib.d.ts +10 -0
- package/dist/lib.js +23 -0
- package/dist/migrations/0.1.110-fileLocks.d.ts +2 -0
- package/dist/migrations/0.1.110-fileLocks.js +15 -0
- package/dist/migrations/0.1.143-ensureImportModuleType.d.ts +2 -0
- package/dist/migrations/0.1.143-ensureImportModuleType.js +12 -0
- package/dist/migrations/0.1.146-addReactRuntime.d.ts +2 -0
- package/dist/migrations/0.1.146-addReactRuntime.js +10 -0
- package/dist/migrations/0.1.27-migrateInit.d.ts +1 -0
- package/dist/migrations/0.1.27-migrateInit.js +8 -0
- package/dist/migrations/0.1.28-tsToTsx.d.ts +3 -0
- package/dist/migrations/0.1.28-tsToTsx.js +33 -0
- package/dist/migrations/0.1.31-ensureProjectIcons.d.ts +2 -0
- package/dist/migrations/0.1.31-ensureProjectIcons.js +12 -0
- package/dist/migrations/0.1.42-ensureVersion.d.ts +2 -0
- package/dist/migrations/0.1.42-ensureVersion.js +12 -0
- package/dist/migrations/0.1.57-ensureJsBundleThemes.d.ts +2 -0
- package/dist/migrations/0.1.57-ensureJsBundleThemes.js +12 -0
- package/dist/migrations/0.1.64-imageFiles.d.ts +2 -0
- package/dist/migrations/0.1.64-imageFiles.js +17 -0
- package/dist/migrations/0.1.95-componentType.d.ts +2 -0
- package/dist/migrations/0.1.95-componentType.js +16 -0
- package/dist/migrations/migrations.d.ts +10 -0
- package/dist/migrations/migrations.js +119 -0
- package/dist/plasmic.schema.json +463 -0
- package/dist/test-common/fixtures.d.ts +13 -0
- package/dist/test-common/fixtures.js +165 -0
- package/dist/tsconfig-transform.json +68 -0
- package/dist/utils/auth-utils.d.ts +31 -0
- package/dist/utils/auth-utils.js +236 -0
- package/dist/utils/checksum.d.ts +4 -0
- package/dist/utils/checksum.js +63 -0
- package/dist/utils/code-utils.d.ts +46 -0
- package/dist/utils/code-utils.js +457 -0
- package/dist/utils/config-utils.d.ts +271 -0
- package/dist/utils/config-utils.js +178 -0
- package/dist/utils/envdetect.d.ts +4 -0
- package/dist/utils/envdetect.js +42 -0
- package/dist/utils/error.d.ts +14 -0
- package/dist/utils/error.js +42 -0
- package/dist/utils/file-utils.d.ts +71 -0
- package/dist/utils/file-utils.js +433 -0
- package/dist/utils/get-context.d.ts +40 -0
- package/dist/utils/get-context.js +339 -0
- package/dist/utils/help.d.ts +2 -0
- package/dist/utils/help.js +56 -0
- package/dist/utils/lang-utils.d.ts +10 -0
- package/dist/utils/lang-utils.js +52 -0
- package/dist/utils/npm-utils.d.ts +28 -0
- package/dist/utils/npm-utils.js +215 -0
- package/dist/utils/prompts.d.ts +6 -0
- package/dist/utils/prompts.js +23 -0
- package/dist/utils/resolve-utils.d.ts +13 -0
- package/dist/utils/resolve-utils.js +198 -0
- package/dist/utils/semver.d.ts +34 -0
- package/dist/utils/semver.js +61 -0
- package/dist/utils/test-utils.d.ts +22 -0
- package/dist/utils/test-utils.js +106 -0
- package/dist/utils/user-utils.d.ts +7 -0
- package/dist/utils/user-utils.js +48 -0
- package/jest.config.js +6 -0
- package/package.json +80 -0
- package/src/__mocks__/api.ts +394 -0
- package/src/__tests__/code-utils-spec.ts +881 -0
- package/src/__tests__/ftue-spec.ts +43 -0
- package/src/__tests__/project-api-token-spec.ts +208 -0
- package/src/__tests__/versioned-sync-spec.ts +176 -0
- package/src/actions/auth.ts +43 -0
- package/src/actions/fix-imports.ts +13 -0
- package/src/actions/init.ts +638 -0
- package/src/actions/project-token.ts +36 -0
- package/src/actions/sync-components.ts +405 -0
- package/src/actions/sync-global-variants.ts +129 -0
- package/src/actions/sync-icons.ts +135 -0
- package/src/actions/sync-images.ts +191 -0
- package/src/actions/sync-styles.ts +71 -0
- package/src/actions/sync.ts +747 -0
- package/src/actions/upload-bundle.ts +38 -0
- package/src/actions/watch.ts +95 -0
- package/src/api.ts +407 -0
- package/src/deps.ts +18 -0
- package/src/index.ts +300 -0
- package/src/lib.ts +10 -0
- package/src/migrations/0.1.110-fileLocks.ts +16 -0
- package/src/migrations/0.1.146-addReactRuntime.ts +8 -0
- package/src/migrations/0.1.27-migrateInit.ts +4 -0
- package/src/migrations/0.1.28-tsToTsx.ts +37 -0
- package/src/migrations/0.1.31-ensureProjectIcons.ts +10 -0
- package/src/migrations/0.1.42-ensureVersion.ts +10 -0
- package/src/migrations/0.1.57-ensureJsBundleThemes.ts +10 -0
- package/src/migrations/0.1.64-imageFiles.ts +15 -0
- package/src/migrations/0.1.95-componentType.ts +14 -0
- package/src/migrations/migrations.ts +147 -0
- package/src/test-common/fixtures.ts +178 -0
- package/src/utils/auth-utils.ts +276 -0
- package/src/utils/checksum.ts +106 -0
- package/src/utils/code-utils.ts +656 -0
- package/src/utils/config-utils.ts +551 -0
- package/src/utils/envdetect.ts +39 -0
- package/src/utils/error.ts +36 -0
- package/src/utils/file-utils.ts +526 -0
- package/src/utils/get-context.ts +451 -0
- package/src/utils/help.ts +75 -0
- package/src/utils/lang-utils.ts +52 -0
- package/src/utils/npm-utils.ts +223 -0
- package/src/utils/prompts.ts +22 -0
- package/src/utils/resolve-utils.ts +245 -0
- package/src/utils/semver.ts +67 -0
- package/src/utils/test-utils.ts +116 -0
- package/src/utils/user-utils.ts +37 -0
- package/testData/fixImports_plasmic.json +66 -0
- package/tsconfig-transform.json +68 -0
- package/tsconfig.json +67 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
// Make sure we don't end up using .eslintrc.js from our cicd repo
|
|
3
|
+
root: true,
|
|
4
|
+
env: {
|
|
5
|
+
browser: true,
|
|
6
|
+
es2020: true,
|
|
7
|
+
},
|
|
8
|
+
extends: [
|
|
9
|
+
// "eslint:recommended",
|
|
10
|
+
// "plugin:@typescript-eslint/recommended"
|
|
11
|
+
],
|
|
12
|
+
parser: "@typescript-eslint/parser",
|
|
13
|
+
parserOptions: {
|
|
14
|
+
ecmaVersion: 11,
|
|
15
|
+
sourceType: "module",
|
|
16
|
+
},
|
|
17
|
+
plugins: ["@typescript-eslint"],
|
|
18
|
+
rules: {
|
|
19
|
+
"no-restricted-properties": [
|
|
20
|
+
"error",
|
|
21
|
+
{
|
|
22
|
+
property: "readFileSync",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
property: "writeFileSync",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
property: "existsSync",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
property: "unlinkSync",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
property: "renameSync",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
object: "process",
|
|
38
|
+
property: "exit",
|
|
39
|
+
message:
|
|
40
|
+
"CLI can be used as a library. Please throw Error or HandledError instead.",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
object: "console",
|
|
44
|
+
message:
|
|
45
|
+
"Please use `logger` so that consumers of the library can control logging.",
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
"no-restricted-syntax": [
|
|
49
|
+
"error",
|
|
50
|
+
{
|
|
51
|
+
selector: "CallExpression[callee.name='readFileSync']",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
selector: "CallExpression[callee.name='writeFileSync']",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
selector: "CallExpression[callee.name='existsSync']",
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
};
|
package/.idea/cli.iml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="JAVA_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
+
<exclude-output />
|
|
5
|
+
<content url="file://$MODULE_DIR$">
|
|
6
|
+
<excludeFolder url="file://$MODULE_DIR$/dist" />
|
|
7
|
+
</content>
|
|
8
|
+
<orderEntry type="inheritedJdk" />
|
|
9
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
10
|
+
</component>
|
|
11
|
+
</module>
|
package/.idea/misc.xml
ADDED
package/.idea/vcs.xml
ADDED
package/README
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Public plasmic cli for syncing designs to local code.
|
|
2
|
+
|
|
3
|
+
Install
|
|
4
|
+
=======
|
|
5
|
+
|
|
6
|
+
`yarn global add @plasmicapp/cli`
|
|
7
|
+
|
|
8
|
+
Usage
|
|
9
|
+
=====
|
|
10
|
+
|
|
11
|
+
`plasmic init` creates the initial plasmic.json file, pointing to your local dev host.
|
|
12
|
+
|
|
13
|
+
`plasmic sync --projects ...` allows you to sync all components in the specified projects
|
|
14
|
+
down as code files to your current folder. Once you've run `plasmic init`, you can run
|
|
15
|
+
`plasmic sync` from any subfolder of the folder with the `plasmic.json` file.
|
|
16
|
+
|
package/README.internal
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Dev Setup
|
|
2
|
+
=========
|
|
3
|
+
|
|
4
|
+
To use in development, you should first:
|
|
5
|
+
|
|
6
|
+
yarn install
|
|
7
|
+
yarn build
|
|
8
|
+
|
|
9
|
+
Which generates the js file in dist/. Then, you should do
|
|
10
|
+
|
|
11
|
+
yarn link
|
|
12
|
+
|
|
13
|
+
Which adds the bin file to the yarn global bin (the location of the global bin is
|
|
14
|
+
at `yarn global bin`.)
|
|
15
|
+
|
|
16
|
+
If you see the symlink there but can't execute it, you'll need to set the permission
|
|
17
|
+
correctly
|
|
18
|
+
|
|
19
|
+
chmod +x `yarn global bin`/plasmic
|
|
20
|
+
|
|
21
|
+
Debugging
|
|
22
|
+
=========
|
|
23
|
+
|
|
24
|
+
Example invocation:
|
|
25
|
+
|
|
26
|
+
DEBUG_CHDIR=/path/to/target/project \
|
|
27
|
+
PLASMIC_DEFAULT_HOST=http://localhost:3003 \
|
|
28
|
+
PLASMIC_DISABLE_AUTH_SEARCH=1 \
|
|
29
|
+
node --inspect -r ts-node/register src/index.ts \
|
|
30
|
+
--auth ~/.plasmic.dev.auth \
|
|
31
|
+
sync
|
|
32
|
+
|
|
33
|
+
This runs the source in-place from the .ts files so that you can debug the unmangled source code in Chrome devtools.
|
|
34
|
+
|
|
35
|
+
- `DEBUG_CHDIR`: First cd's into the target directory (which typically has its own node_modules etc., so it's tricky to try to run the source from there).
|
|
36
|
+
- `PLASMIC_DEFAULT_HOST`: Point to your localhost app server (even if you don't already have an auth file set up).
|
|
37
|
+
- `--auth`: Reference your own alternate auth file, if you already have one.
|
|
38
|
+
- `PLASMIC_DISABLE_AUTH_SEARCH`: Prevent auto-searching home and parent dirs for a `.plasmic.auth` file. Useful if you want to not provide any `--auth` (you probably won't use both `--auth` and this together).
|
|
39
|
+
|
|
40
|
+
Extra hidden API
|
|
41
|
+
================
|
|
42
|
+
|
|
43
|
+
Additional environment variables, primarily used by PlasmicLoader.
|
|
44
|
+
|
|
45
|
+
- `PLASMIC_LOADER`: runs in "PlasmicLoader mode."
|
|
46
|
+
- `QUIET`: suppress various output, especially confirmations and subprocesses.
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Turn your Plasmic designs into components with the plasmic CLI!
|
|
2
|
+
|
|
3
|
+
### Quickstart
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
# Install the CLI globally:
|
|
7
|
+
npm install -g @plasmicapp/cli # Or: yarn global add @plasmicapp/cli
|
|
8
|
+
|
|
9
|
+
# Run it!
|
|
10
|
+
plasmic sync --projects yourPlasmicProjectId
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Resources
|
|
14
|
+
|
|
15
|
+
For end-to-end examples, please check our docs: https://www.plasmic.app/learn/.
|
|
16
|
+
|
|
17
|
+
For more information about the CLI, run `plasmic -h` or visit: https://www.plasmic.app/learn/cli/.
|
package/build.sh
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface MockProject {
|
|
2
|
+
projectId: string;
|
|
3
|
+
projectApiToken: string;
|
|
4
|
+
version: string;
|
|
5
|
+
projectName: string;
|
|
6
|
+
components: MockComponent[];
|
|
7
|
+
dependencies: {
|
|
8
|
+
[projectId: string]: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface MockComponent {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
projectId?: string;
|
|
15
|
+
version?: string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
35
|
+
const lang_utils_1 = require("../utils/lang-utils");
|
|
36
|
+
const semver = __importStar(require("../utils/semver"));
|
|
37
|
+
const api = jest.genMockFromModule("../api");
|
|
38
|
+
/**
|
|
39
|
+
* Store a simplified data model for use with testing
|
|
40
|
+
*/
|
|
41
|
+
// Keyed by (projectId, version)
|
|
42
|
+
const PROJECTS = [];
|
|
43
|
+
function clear() {
|
|
44
|
+
while (PROJECTS.length > 0) {
|
|
45
|
+
PROJECTS.shift();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function mockProjectToProjectVersionMeta(mock, componentIdOrNames) {
|
|
49
|
+
return Object.assign(Object.assign({}, mock), { componentIds: mock.components
|
|
50
|
+
.filter((c) => !componentIdOrNames ||
|
|
51
|
+
componentIdOrNames.includes(c.name) ||
|
|
52
|
+
componentIdOrNames.includes(c.id))
|
|
53
|
+
.map((c) => c.id) });
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Call this in test to setup the data model
|
|
57
|
+
* @param id componentId
|
|
58
|
+
* @param comp MockComponent
|
|
59
|
+
*/
|
|
60
|
+
function addMockProject(proj) {
|
|
61
|
+
const projectId = proj.projectId;
|
|
62
|
+
const version = proj.version;
|
|
63
|
+
// Populate projectId and version into each component
|
|
64
|
+
// will be useful when reading / writing components to files
|
|
65
|
+
proj.components = proj.components.map((c) => {
|
|
66
|
+
return Object.assign(Object.assign({}, c), { projectId,
|
|
67
|
+
version });
|
|
68
|
+
});
|
|
69
|
+
const existing = getMockProject(projectId, version);
|
|
70
|
+
if (!existing) {
|
|
71
|
+
PROJECTS.push(proj);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
existing.components = proj.components;
|
|
75
|
+
existing.dependencies = proj.dependencies;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Used to interpret data that's stored in the "codegen" files from the Mock server
|
|
80
|
+
* @param data
|
|
81
|
+
*/
|
|
82
|
+
function stringToMockComponent(data) {
|
|
83
|
+
if (!data) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const withoutComments = data.startsWith("//") ? data.slice(2) : data;
|
|
87
|
+
const cleaned = withoutComments.trim();
|
|
88
|
+
return JSON.parse(cleaned);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Used to write mock data into files for testing.
|
|
92
|
+
* Useful to see what version was written
|
|
93
|
+
* Need to prefix with a comment to satisfy the parser used in `fixAllImports`
|
|
94
|
+
* @param component
|
|
95
|
+
*/
|
|
96
|
+
function mockComponentToString(component) {
|
|
97
|
+
return "// " + JSON.stringify(component);
|
|
98
|
+
}
|
|
99
|
+
function getMockProject(projectId, version) {
|
|
100
|
+
return PROJECTS.find((m) => m.projectId === projectId && m.version === version);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Only fetch top-level components that match the projectId (optionally also componentIdOrNames + version)
|
|
104
|
+
* Does not crawl the dependency tree
|
|
105
|
+
* @param projectId
|
|
106
|
+
* @param componentIdOrNames
|
|
107
|
+
* @param versionRange
|
|
108
|
+
*/
|
|
109
|
+
function getMockComponents(projectId, version, componentIdOrNames) {
|
|
110
|
+
const project = getMockProject(projectId, version);
|
|
111
|
+
return !project
|
|
112
|
+
? []
|
|
113
|
+
: project.components.filter((c) => !componentIdOrNames ||
|
|
114
|
+
componentIdOrNames.includes(c.id) ||
|
|
115
|
+
componentIdOrNames.includes(c.name));
|
|
116
|
+
}
|
|
117
|
+
function genFilename(base, suffix) {
|
|
118
|
+
return "Plasmic" + base + "." + suffix;
|
|
119
|
+
}
|
|
120
|
+
function genComponentBundle(component) {
|
|
121
|
+
return {
|
|
122
|
+
renderModule: mockComponentToString(component),
|
|
123
|
+
skeletonModule: mockComponentToString(component),
|
|
124
|
+
cssRules: `theClass {color: blue;}`,
|
|
125
|
+
renderModuleFileName: genFilename(component.name, "tsx"),
|
|
126
|
+
skeletonModuleFileName: component.name + ".tsx",
|
|
127
|
+
cssFileName: genFilename(component.name, "css"),
|
|
128
|
+
componentName: component.name,
|
|
129
|
+
id: component.id,
|
|
130
|
+
scheme: "blackbox",
|
|
131
|
+
nameInIdToUuid: [],
|
|
132
|
+
isPage: false,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function genEmptyStyleTokensMap() {
|
|
136
|
+
return {
|
|
137
|
+
props: [],
|
|
138
|
+
global: {
|
|
139
|
+
meta: {
|
|
140
|
+
source: "plasmic.app",
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function genProjectMetaBundle(projectId) {
|
|
146
|
+
return {
|
|
147
|
+
projectId,
|
|
148
|
+
projectName: projectId,
|
|
149
|
+
cssFileName: genFilename(projectId, "css"),
|
|
150
|
+
cssRules: `theClass {color: green;}`,
|
|
151
|
+
jsBundleThemes: [],
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function* getDeps(projects) {
|
|
155
|
+
const queue = [...projects];
|
|
156
|
+
while (queue.length > 0) {
|
|
157
|
+
const curr = lang_utils_1.ensure(queue.shift());
|
|
158
|
+
for (const [projectId, version] of lodash_1.default.toPairs(curr.dependencies)) {
|
|
159
|
+
const mockProject = lang_utils_1.ensure(getMockProject(projectId, version));
|
|
160
|
+
const projectMeta = mockProjectToProjectVersionMeta(mockProject);
|
|
161
|
+
yield projectMeta;
|
|
162
|
+
queue.push(projectMeta);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
class PlasmicApi {
|
|
167
|
+
constructor(auth) {
|
|
168
|
+
this.auth = auth;
|
|
169
|
+
this.lastProjectIdsAndTokens = [];
|
|
170
|
+
}
|
|
171
|
+
genStyleConfig() {
|
|
172
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
const result = {
|
|
174
|
+
defaultStyleCssFileName: genFilename("default", "css"),
|
|
175
|
+
defaultStyleCssRules: `theClass {color: red;}`,
|
|
176
|
+
};
|
|
177
|
+
return result;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
resolveSync(projects, recursive) {
|
|
181
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
182
|
+
const results = {
|
|
183
|
+
projects: [],
|
|
184
|
+
dependencies: [],
|
|
185
|
+
conflicts: [],
|
|
186
|
+
};
|
|
187
|
+
// Get top level projects
|
|
188
|
+
projects.forEach((proj) => {
|
|
189
|
+
const availableProjects = Array.from(PROJECTS.values()).filter((p) => p.projectId === proj.projectId);
|
|
190
|
+
if (!((this.auth.user && this.auth.token) ||
|
|
191
|
+
availableProjects.every((p) => p.projectApiToken === proj.projectApiToken))) {
|
|
192
|
+
throw new Error("No user+token, and project API tokens don't match");
|
|
193
|
+
}
|
|
194
|
+
const availableVersions = availableProjects.map((p) => p.version);
|
|
195
|
+
const version = semver.maxSatisfying(availableVersions, proj.versionRange);
|
|
196
|
+
if (version) {
|
|
197
|
+
const mockProject = lang_utils_1.ensure(getMockProject(proj.projectId, version));
|
|
198
|
+
const projectMeta = mockProjectToProjectVersionMeta(mockProject, proj.componentIdOrNames);
|
|
199
|
+
results.projects.push(projectMeta);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
// Get dependencies
|
|
203
|
+
if (!!recursive) {
|
|
204
|
+
const deps = [...getDeps(results.projects)];
|
|
205
|
+
results.dependencies.push(...deps);
|
|
206
|
+
}
|
|
207
|
+
return results;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
getCurrentUser() {
|
|
211
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
+
return true;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
projectComponents(projectId, opts) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
const { componentIdOrNames, version } = opts;
|
|
218
|
+
if (PROJECTS.length <= 0) {
|
|
219
|
+
throw new Error("Remember to call __addMockProject first!");
|
|
220
|
+
}
|
|
221
|
+
const maybeTokenPair = this.lastProjectIdsAndTokens.find((pair) => pair.projectId === projectId);
|
|
222
|
+
const project = lang_utils_1.ensure(PROJECTS.find((p) => p.projectId === projectId));
|
|
223
|
+
if (!((this.auth.user && this.auth.token) ||
|
|
224
|
+
project.projectApiToken === (maybeTokenPair === null || maybeTokenPair === void 0 ? void 0 : maybeTokenPair.projectApiToken))) {
|
|
225
|
+
throw new Error("No user+token and project API tokens don't match");
|
|
226
|
+
}
|
|
227
|
+
// Server also require tokens for the dependencies.
|
|
228
|
+
const deps = [...getDeps([mockProjectToProjectVersionMeta(project)])];
|
|
229
|
+
if (!deps.every((dep) => this.lastProjectIdsAndTokens.find((p) => p.projectId === dep.projectId))) {
|
|
230
|
+
throw new Error("No user+token and project API tokens don't match on a dependency");
|
|
231
|
+
}
|
|
232
|
+
const mockComponents = getMockComponents(projectId, version, componentIdOrNames);
|
|
233
|
+
if (mockComponents.length <= 0) {
|
|
234
|
+
throw new Error(`Code gen failed: no components match the parameters ${JSON.stringify({ projectId, version, componentIdOrNames }, undefined, 2)}`);
|
|
235
|
+
}
|
|
236
|
+
const components = mockComponents.map((c) => genComponentBundle(c));
|
|
237
|
+
const result = {
|
|
238
|
+
components,
|
|
239
|
+
codeComponentMetas: [],
|
|
240
|
+
projectConfig: genProjectMetaBundle(projectId),
|
|
241
|
+
globalVariants: [],
|
|
242
|
+
usedTokens: genEmptyStyleTokensMap(),
|
|
243
|
+
iconAssets: [],
|
|
244
|
+
imageAssets: [],
|
|
245
|
+
checksums: {
|
|
246
|
+
renderModuleChecksums: components.map((c) => [c.id, c.renderModule]),
|
|
247
|
+
cssRulesChecksums: components.map((c) => [c.id, c.cssRules]),
|
|
248
|
+
imageChecksums: [],
|
|
249
|
+
iconChecksums: [],
|
|
250
|
+
globalVariantChecksums: [],
|
|
251
|
+
projectCssChecksum: "",
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
return result;
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
uploadBundle(projectId, bundleName, bundleJs, css, metaJson) {
|
|
258
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
259
|
+
throw new Error("Unimplemented");
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
projectStyleTokens(projectId) {
|
|
263
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
264
|
+
throw new Error("Unimplemented");
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
projectIcons(projectId) {
|
|
268
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
269
|
+
throw new Error("Unimplemented");
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
projectSyncMetadata(projectId, revision, rethrowAppError) {
|
|
273
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
274
|
+
throw new Error("Unimplemented");
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
requiredPackages() {
|
|
278
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
279
|
+
return {
|
|
280
|
+
"@plasmicapp/loader": "0.0.1",
|
|
281
|
+
"@plasmicapp/cli": "0.0.1",
|
|
282
|
+
"@plasmicapp/react-web": "0.0.1",
|
|
283
|
+
"@plasmicapp/react-web-runtime": "0.0.1",
|
|
284
|
+
};
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
connectSocket() { }
|
|
288
|
+
attachProjectIdsAndTokens(idsAndTokens) {
|
|
289
|
+
this.lastProjectIdsAndTokens = idsAndTokens;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
api.PlasmicApi = PlasmicApi;
|
|
293
|
+
api.clear = clear;
|
|
294
|
+
api.getMockProject = getMockProject;
|
|
295
|
+
api.addMockProject = addMockProject;
|
|
296
|
+
api.stringToMockComponent = stringToMockComponent;
|
|
297
|
+
module.exports = api;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|