@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
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Basic Options */
|
|
4
|
+
// "incremental": true, /* Enable incremental compilation */
|
|
5
|
+
"target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
|
|
6
|
+
"module": "es2015" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
|
|
7
|
+
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
8
|
+
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
9
|
+
// "checkJs": true, /* Report errors in .js files. */
|
|
10
|
+
"jsx": "preserve" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
|
|
11
|
+
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
12
|
+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
13
|
+
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
14
|
+
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
15
|
+
// "outDir": "./dist", /* Redirect output structure to the directory. */
|
|
16
|
+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
17
|
+
// "composite": true, /* Enable project compilation */
|
|
18
|
+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
19
|
+
"removeComments": false /* Do not emit comments to output. */
|
|
20
|
+
// "noEmit": true, /* Do not emit outputs. */
|
|
21
|
+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
22
|
+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
23
|
+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
24
|
+
|
|
25
|
+
//"importsNotUsedAsValues": "preserve",
|
|
26
|
+
|
|
27
|
+
/* Strict Type-Checking Options */
|
|
28
|
+
//"strict": true, /* Enable all strict type-checking options. */
|
|
29
|
+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
30
|
+
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
31
|
+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
32
|
+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
33
|
+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
34
|
+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
35
|
+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
36
|
+
|
|
37
|
+
/* Additional Checks */
|
|
38
|
+
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
39
|
+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
40
|
+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
41
|
+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
42
|
+
|
|
43
|
+
/* Module Resolution Options */
|
|
44
|
+
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
45
|
+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
46
|
+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
47
|
+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
48
|
+
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
49
|
+
// "types": [], /* Type declaration files to be included in compilation. */
|
|
50
|
+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
51
|
+
//"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
52
|
+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
53
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
54
|
+
|
|
55
|
+
/* Source Map Options */
|
|
56
|
+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
57
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
58
|
+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
59
|
+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
60
|
+
|
|
61
|
+
/* Experimental Options */
|
|
62
|
+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
63
|
+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
64
|
+
|
|
65
|
+
/* Advanced Options */
|
|
66
|
+
//"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CommonArgs } from "../index";
|
|
2
|
+
import { AuthConfig } from "./config-utils";
|
|
3
|
+
export declare type AuthData = {
|
|
4
|
+
user: string;
|
|
5
|
+
token: string;
|
|
6
|
+
};
|
|
7
|
+
export declare type CancellablePromise<T> = {
|
|
8
|
+
promise: Promise<T>;
|
|
9
|
+
cancel: () => void;
|
|
10
|
+
};
|
|
11
|
+
export declare function authByPolling(host: string, initToken: string): CancellablePromise<AuthData>;
|
|
12
|
+
export declare function startAuth(opts: Partial<CommonArgs> & {
|
|
13
|
+
host: string;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
export declare function readAuth(authFile: string): {
|
|
16
|
+
host: string;
|
|
17
|
+
user: string;
|
|
18
|
+
token: string;
|
|
19
|
+
basicAuthUser?: string | undefined;
|
|
20
|
+
basicAuthPassword?: string | undefined;
|
|
21
|
+
};
|
|
22
|
+
export declare function getEnvAuth(): AuthConfig | undefined;
|
|
23
|
+
export declare function getCurrentAuth(authPath?: string): Promise<AuthConfig | undefined>;
|
|
24
|
+
export declare function getOrStartAuth(opts: CommonArgs & {
|
|
25
|
+
host: string;
|
|
26
|
+
enableSkipAuth?: boolean;
|
|
27
|
+
}): Promise<AuthConfig | undefined>;
|
|
28
|
+
export declare function findAuthFile(dir: string, opts: {
|
|
29
|
+
traverseParents?: boolean;
|
|
30
|
+
}): string | undefined;
|
|
31
|
+
export declare function writeAuth(authFile: string, config: AuthConfig): Promise<void>;
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.writeAuth = exports.findAuthFile = exports.getOrStartAuth = exports.getCurrentAuth = exports.getEnvAuth = exports.readAuth = exports.startAuth = exports.authByPolling = void 0;
|
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
|
17
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
18
|
+
const open_1 = __importDefault(require("open"));
|
|
19
|
+
const os_1 = __importDefault(require("os"));
|
|
20
|
+
const socket_io_client_1 = __importDefault(require("socket.io-client"));
|
|
21
|
+
const upath_1 = __importDefault(require("upath"));
|
|
22
|
+
const uuid_1 = require("uuid");
|
|
23
|
+
const api_1 = require("../api");
|
|
24
|
+
const deps_1 = require("../deps");
|
|
25
|
+
const error_1 = require("../utils/error");
|
|
26
|
+
const config_utils_1 = require("./config-utils");
|
|
27
|
+
const file_utils_1 = require("./file-utils");
|
|
28
|
+
function authByPolling(host, initToken) {
|
|
29
|
+
const socket = socket_io_client_1.default.connect(host, {
|
|
30
|
+
path: `/api/v1/init-token`,
|
|
31
|
+
transportOptions: {
|
|
32
|
+
polling: {
|
|
33
|
+
extraHeaders: {
|
|
34
|
+
"x-plasmic-init-token": initToken,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
const promise = new Promise((resolve, reject) => {
|
|
40
|
+
socket.on("connect", (reason) => {
|
|
41
|
+
deps_1.logger.info("Waiting for token...");
|
|
42
|
+
});
|
|
43
|
+
socket.on("token", (data) => {
|
|
44
|
+
resolve(data);
|
|
45
|
+
socket.close();
|
|
46
|
+
});
|
|
47
|
+
socket.on("error", (error) => {
|
|
48
|
+
deps_1.logger.warn(error);
|
|
49
|
+
reject(error);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
const cancel = () => {
|
|
53
|
+
socket.close();
|
|
54
|
+
};
|
|
55
|
+
return { promise, cancel };
|
|
56
|
+
}
|
|
57
|
+
exports.authByPolling = authByPolling;
|
|
58
|
+
function authByPrompt(host) {
|
|
59
|
+
const promise = inquirer_1.default.prompt([
|
|
60
|
+
{
|
|
61
|
+
name: "user",
|
|
62
|
+
message: "Your Plasmic user email",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "token",
|
|
66
|
+
message: `Your personal access token (create one at ${host}/self/settings)`,
|
|
67
|
+
},
|
|
68
|
+
]);
|
|
69
|
+
const cancel = () => {
|
|
70
|
+
deps_1.logger.info("Cancelling prompt...");
|
|
71
|
+
process.stdin.pause();
|
|
72
|
+
};
|
|
73
|
+
return { promise, cancel };
|
|
74
|
+
}
|
|
75
|
+
function startAuth(opts) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
if (opts.yes) {
|
|
78
|
+
throw new error_1.HandledError("Plasmic credentials could not be found.");
|
|
79
|
+
}
|
|
80
|
+
const auth = yield new Promise((resolve, reject) => {
|
|
81
|
+
let prompt;
|
|
82
|
+
const initToken = uuid_1.v4();
|
|
83
|
+
const url = `${opts.host}/auth/plasmic-init/${initToken}`;
|
|
84
|
+
open_1.default(url);
|
|
85
|
+
deps_1.logger.info(`\nIf your browser doesn't automatically open, enter the following URL:\n${url}\n`);
|
|
86
|
+
deps_1.logger.info(`Please log in and authorize Plasmic CLI.`);
|
|
87
|
+
const polling = authByPolling(opts.host, initToken);
|
|
88
|
+
polling.promise.then((auth) => {
|
|
89
|
+
if (prompt) {
|
|
90
|
+
prompt.cancel();
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
clearTimeout(timeout);
|
|
94
|
+
}
|
|
95
|
+
resolve(auth);
|
|
96
|
+
});
|
|
97
|
+
// Default to 1 minute.
|
|
98
|
+
const authPollTimeout = Number(process.env.PLASMIC_AUTH_POLL_TIMEOUT) || 60 * 1000;
|
|
99
|
+
if (authPollTimeout === -1) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const timeout = setTimeout(() => {
|
|
103
|
+
deps_1.logger.info(`We haven't received an auth token from Plasmic yet.`);
|
|
104
|
+
prompt = authByPrompt(opts.host);
|
|
105
|
+
prompt.promise
|
|
106
|
+
.then((auth) => {
|
|
107
|
+
polling.cancel();
|
|
108
|
+
resolve(auth);
|
|
109
|
+
})
|
|
110
|
+
.catch(reject);
|
|
111
|
+
}, authPollTimeout);
|
|
112
|
+
});
|
|
113
|
+
if (!auth.user || !auth.token) {
|
|
114
|
+
deps_1.logger.error(`Could not get auth token.`);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const newAuthFile = opts.auth || upath_1.default.join(os_1.default.homedir(), config_utils_1.AUTH_FILE_NAME);
|
|
118
|
+
yield writeAuth(newAuthFile, {
|
|
119
|
+
host: opts.host,
|
|
120
|
+
user: auth.user,
|
|
121
|
+
token: auth.token,
|
|
122
|
+
});
|
|
123
|
+
deps_1.logger.info(`Successfully created Plasmic credentials file at ${newAuthFile}`);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
exports.startAuth = startAuth;
|
|
127
|
+
function readAuth(authFile) {
|
|
128
|
+
if (!file_utils_1.existsBuffered(authFile)) {
|
|
129
|
+
throw new error_1.HandledError(`No Plasmic auth file found at ${authFile}`);
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
const parsed = JSON.parse(file_utils_1.readFileText(authFile));
|
|
133
|
+
// Strip trailing slashes.
|
|
134
|
+
return Object.assign(Object.assign({}, parsed), { host: parsed.host.replace(/\/+$/, "") });
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
deps_1.logger.error(`Error encountered reading plasmic credentials at ${authFile}: ${e}`);
|
|
138
|
+
throw e;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.readAuth = readAuth;
|
|
142
|
+
function getEnvAuth() {
|
|
143
|
+
const host = process.env[config_utils_1.ENV_AUTH_HOST];
|
|
144
|
+
const user = process.env[config_utils_1.ENV_AUTH_USER];
|
|
145
|
+
const token = process.env[config_utils_1.ENV_AUTH_TOKEN];
|
|
146
|
+
// both user and token are required
|
|
147
|
+
if (!user || !token) {
|
|
148
|
+
// Try to give a hint if they partially entered a credential
|
|
149
|
+
if (user || token) {
|
|
150
|
+
deps_1.logger.warn(`Your Plasmic credentials were only partially set via environment variables. Try both ${config_utils_1.ENV_AUTH_USER} and ${config_utils_1.ENV_AUTH_TOKEN}`);
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
host: host !== null && host !== void 0 ? host : config_utils_1.DEFAULT_HOST,
|
|
156
|
+
user,
|
|
157
|
+
token,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
exports.getEnvAuth = getEnvAuth;
|
|
161
|
+
function readCurrentAuth(authPath) {
|
|
162
|
+
const authFromEnv = getEnvAuth();
|
|
163
|
+
if (authFromEnv)
|
|
164
|
+
return authFromEnv;
|
|
165
|
+
if (!authPath && !process.env.PLASMIC_DISABLE_AUTH_SEARCH) {
|
|
166
|
+
authPath = findAuthFile(process.cwd(), { traverseParents: true });
|
|
167
|
+
}
|
|
168
|
+
if (!authPath) {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
return readAuth(authPath);
|
|
172
|
+
}
|
|
173
|
+
function getCurrentAuth(authPath) {
|
|
174
|
+
var _a;
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
const auth = readCurrentAuth(authPath);
|
|
177
|
+
if (!auth) {
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
const api = new api_1.PlasmicApi(auth);
|
|
181
|
+
try {
|
|
182
|
+
yield api.getCurrentUser();
|
|
183
|
+
return auth;
|
|
184
|
+
}
|
|
185
|
+
catch (e) {
|
|
186
|
+
if (((_a = e.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
|
|
187
|
+
deps_1.logger.error(`The current credentials expired or are not valid.`);
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
throw e;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
exports.getCurrentAuth = getCurrentAuth;
|
|
195
|
+
function failAuth() {
|
|
196
|
+
throw new error_1.HandledError(`Unable to authenticate Plasmic. Please run 'plasmic auth'.`);
|
|
197
|
+
}
|
|
198
|
+
function getOrStartAuth(opts) {
|
|
199
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
200
|
+
let auth = yield getCurrentAuth(opts.auth);
|
|
201
|
+
if (!auth && opts.enableSkipAuth) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (!auth && opts.yes) {
|
|
205
|
+
failAuth();
|
|
206
|
+
}
|
|
207
|
+
if (!auth) {
|
|
208
|
+
yield startAuth(opts);
|
|
209
|
+
auth = yield getCurrentAuth(opts.auth);
|
|
210
|
+
}
|
|
211
|
+
if (!auth) {
|
|
212
|
+
failAuth();
|
|
213
|
+
}
|
|
214
|
+
return auth;
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
exports.getOrStartAuth = getOrStartAuth;
|
|
218
|
+
function findAuthFile(dir, opts) {
|
|
219
|
+
let file = file_utils_1.findFile(dir, (f) => f === config_utils_1.AUTH_FILE_NAME, opts);
|
|
220
|
+
if (!file) {
|
|
221
|
+
file = file_utils_1.findFile(os_1.default.homedir(), (f) => f === config_utils_1.AUTH_FILE_NAME, {
|
|
222
|
+
traverseParents: false,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
return file;
|
|
226
|
+
}
|
|
227
|
+
exports.findAuthFile = findAuthFile;
|
|
228
|
+
function writeAuth(authFile, config) {
|
|
229
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
230
|
+
yield file_utils_1.writeFileContentRaw(authFile, JSON.stringify(config, undefined, 2), {
|
|
231
|
+
force: true,
|
|
232
|
+
});
|
|
233
|
+
fs_1.default.chmodSync(authFile, "600");
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
exports.writeAuth = writeAuth;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SyncArgs } from "../actions/sync";
|
|
2
|
+
import { ChecksumBundle } from "../api";
|
|
3
|
+
import { PlasmicContext } from "./config-utils";
|
|
4
|
+
export declare function getChecksums(context: PlasmicContext, opts: SyncArgs, projectId: string, componentIds: string[]): ChecksumBundle;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getChecksums = void 0;
|
|
4
|
+
const lang_utils_1 = require("./lang-utils");
|
|
5
|
+
function getChecksums(context, opts, projectId, componentIds) {
|
|
6
|
+
const projectConfig = context.config.projects.find((p) => p.projectId === projectId);
|
|
7
|
+
const projectLock = context.lock.projects.find((projectLock) => projectLock.projectId === projectId);
|
|
8
|
+
if (!projectConfig || !projectLock || opts.allFiles) {
|
|
9
|
+
return {
|
|
10
|
+
imageChecksums: [],
|
|
11
|
+
iconChecksums: [],
|
|
12
|
+
renderModuleChecksums: [],
|
|
13
|
+
cssRulesChecksums: [],
|
|
14
|
+
globalVariantChecksums: [],
|
|
15
|
+
projectCssChecksum: "",
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const fileLocks = projectLock.fileLocks;
|
|
19
|
+
const knownImages = new Set(projectConfig.images.map((i) => i.id));
|
|
20
|
+
const knownIcons = new Set(projectConfig.icons.map((i) => i.id));
|
|
21
|
+
const knownComponents = new Set(projectConfig.components.map((c) => c.id));
|
|
22
|
+
const knownGlobalVariants = new Set(context.config.globalVariants.variantGroups
|
|
23
|
+
.filter((vg) => vg.projectId === projectId)
|
|
24
|
+
.map((vg) => vg.id));
|
|
25
|
+
const knownThemes = new Set((projectConfig.jsBundleThemes || []).map((theme) => theme.bundleName));
|
|
26
|
+
const toBeSyncedComponents = new Set(componentIds);
|
|
27
|
+
const imageChecksums = fileLocks
|
|
28
|
+
.filter((fileLock) => fileLock.type === "image" && knownImages.has(fileLock.assetId))
|
|
29
|
+
.map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
30
|
+
const iconChecksums = fileLocks
|
|
31
|
+
.filter((fileLock) => projectLock.lang === context.config.code.lang &&
|
|
32
|
+
fileLock.type === "icon" &&
|
|
33
|
+
knownIcons.has(fileLock.assetId))
|
|
34
|
+
.map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
35
|
+
const renderModuleChecksums = fileLocks
|
|
36
|
+
.filter((fileLock) => projectLock.lang === context.config.code.lang &&
|
|
37
|
+
fileLock.type === "renderModule" &&
|
|
38
|
+
toBeSyncedComponents.has(fileLock.assetId) &&
|
|
39
|
+
knownComponents.has(fileLock.assetId))
|
|
40
|
+
.map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
41
|
+
const cssRulesChecksums = fileLocks
|
|
42
|
+
.filter((fileLock) => fileLock.type === "cssRules" &&
|
|
43
|
+
toBeSyncedComponents.has(fileLock.assetId) &&
|
|
44
|
+
knownComponents.has(fileLock.assetId))
|
|
45
|
+
.map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
46
|
+
const globalVariantChecksums = fileLocks
|
|
47
|
+
.filter((fileLock) => projectLock.lang === context.config.code.lang &&
|
|
48
|
+
fileLock.type === "globalVariant" &&
|
|
49
|
+
knownGlobalVariants.has(fileLock.assetId))
|
|
50
|
+
.map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
51
|
+
const projectCssChecksums = fileLocks.filter((fileLock) => fileLock.type === "projectCss");
|
|
52
|
+
lang_utils_1.assert(projectCssChecksums.length < 2);
|
|
53
|
+
const projectCssChecksum = projectCssChecksums.length > 0 ? projectCssChecksums[0].checksum : "";
|
|
54
|
+
return {
|
|
55
|
+
imageChecksums,
|
|
56
|
+
iconChecksums,
|
|
57
|
+
renderModuleChecksums,
|
|
58
|
+
cssRulesChecksums,
|
|
59
|
+
globalVariantChecksums,
|
|
60
|
+
projectCssChecksum,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
exports.getChecksums = getChecksums;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ImportDeclaration } from "@babel/types";
|
|
2
|
+
import L from "lodash";
|
|
3
|
+
import { Options } from "prettier";
|
|
4
|
+
import { CodeComponentConfig, ComponentConfig, GlobalVariantGroupConfig, IconConfig, ImageConfig, PlasmicConfig, PlasmicContext, ProjectConfig } from "./config-utils";
|
|
5
|
+
export declare const formatAsLocal: (content: string, filePath: string, baseDir: string, defaultOpts?: Options) => string;
|
|
6
|
+
export declare function ensureImportSpecifierWithAlias(decl: ImportDeclaration, imported: string, alias: string): void;
|
|
7
|
+
export declare function ensureImportDefaultSpecifier(decl: ImportDeclaration, defaultExport: string): void;
|
|
8
|
+
/**
|
|
9
|
+
* Given the argument `code` string, for module at `fromPath`, replaces all Plasmic imports
|
|
10
|
+
* for modules found in `compConfigsMap`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function replaceImports(context: PlasmicContext, code: string, fromPath: string, fixImportContext: FixImportContext, removeImportDirective: boolean, baseDir: string, changed?: boolean): string;
|
|
13
|
+
/**
|
|
14
|
+
* Returns true if the argument ComponentConfig.importSpec.modulePath is referencing
|
|
15
|
+
* a local file
|
|
16
|
+
*/
|
|
17
|
+
export declare function isLocalModulePath(modulePath: string): boolean;
|
|
18
|
+
export interface ComponentUpdateSummary {
|
|
19
|
+
skeletonModuleModified: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface FixImportContext {
|
|
22
|
+
config: PlasmicConfig;
|
|
23
|
+
components: Record<string, ComponentConfig>;
|
|
24
|
+
codeComponentMetas: Record<string, CodeComponentConfig>;
|
|
25
|
+
globalVariants: Record<string, GlobalVariantGroupConfig>;
|
|
26
|
+
icons: Record<string, IconConfig>;
|
|
27
|
+
images: Record<string, ImageConfig>;
|
|
28
|
+
projects: Record<string, ProjectConfig>;
|
|
29
|
+
}
|
|
30
|
+
export declare const mkFixImportContext: (config: PlasmicConfig) => {
|
|
31
|
+
config: PlasmicConfig;
|
|
32
|
+
components: L.Dictionary<ComponentConfig>;
|
|
33
|
+
codeComponentMetas: L.Dictionary<CodeComponentConfig>;
|
|
34
|
+
globalVariants: L.Dictionary<GlobalVariantGroupConfig>;
|
|
35
|
+
icons: L.Dictionary<IconConfig>;
|
|
36
|
+
images: L.Dictionary<ImageConfig>;
|
|
37
|
+
projects: L.Dictionary<ProjectConfig>;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Assuming that all the files referenced in PlasmicConfig are correct, fixes import statements using PlasmicConfig
|
|
41
|
+
* file locations as the source of truth.
|
|
42
|
+
*/
|
|
43
|
+
export declare function fixAllImportStatements(context: PlasmicContext, baseDir: string, summary?: Map<string, ComponentUpdateSummary>): Promise<void>;
|
|
44
|
+
export declare const tsxToJsx: (code: string) => string;
|
|
45
|
+
export declare function maybeConvertTsxToJsx(fileName: string, content: string, baseDir: string): string[];
|
|
46
|
+
export declare const formatScript: (code: string, baseDir: string) => string;
|