@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,271 @@
|
|
|
1
|
+
import { DeepPartial } from "utility-types";
|
|
2
|
+
import { PlasmicApi, ProjectIdAndToken } from "../api";
|
|
3
|
+
export declare const DEFAULT_HOST: string;
|
|
4
|
+
export declare const AUTH_FILE_NAME = ".plasmic.auth";
|
|
5
|
+
export declare const CONFIG_FILE_NAME = "plasmic.json";
|
|
6
|
+
export declare const LOCK_FILE_NAME = "plasmic.lock";
|
|
7
|
+
export declare const LOADER_CONFIG_FILE_NAME = "plasmic-loader.json";
|
|
8
|
+
export declare const CONFIG_SCHEMA_FILE_NAME = "plasmic.schema.json";
|
|
9
|
+
export declare const ENV_AUTH_HOST = "PLASMIC_AUTH_HOST";
|
|
10
|
+
export declare const ENV_AUTH_USER = "PLASMIC_AUTH_USER";
|
|
11
|
+
export declare const ENV_AUTH_TOKEN = "PLASMIC_AUTH_TOKEN";
|
|
12
|
+
export interface PlasmicLoaderConfig {
|
|
13
|
+
projects: ProjectIdAndToken[];
|
|
14
|
+
aboutThisFile: string;
|
|
15
|
+
dir: string;
|
|
16
|
+
plasmicDir: string;
|
|
17
|
+
pageDir: string;
|
|
18
|
+
initArgs: Record<string, string>;
|
|
19
|
+
substitutions?: Record<string, any>;
|
|
20
|
+
}
|
|
21
|
+
export interface PlasmicConfig {
|
|
22
|
+
/** Target platform to generate code for */
|
|
23
|
+
platform: "react" | "nextjs" | "gatsby";
|
|
24
|
+
/**
|
|
25
|
+
* The folder containing the component source files; this is the default place where
|
|
26
|
+
* all files are generated and stored.
|
|
27
|
+
*/
|
|
28
|
+
srcDir: string;
|
|
29
|
+
/**
|
|
30
|
+
* The default folder where Plasmic-managed files will be stored. These include
|
|
31
|
+
* blackbox component files, svg component files, style files, etc. The path
|
|
32
|
+
* is relative to the srcDir.
|
|
33
|
+
*/
|
|
34
|
+
defaultPlasmicDir: string;
|
|
35
|
+
/**
|
|
36
|
+
* Next.js specific config
|
|
37
|
+
*/
|
|
38
|
+
nextjsConfig?: {
|
|
39
|
+
/** The folder containing page components source files. */
|
|
40
|
+
pagesDir?: string;
|
|
41
|
+
};
|
|
42
|
+
/** Gatsby-specific config */
|
|
43
|
+
gatsbyConfig?: {
|
|
44
|
+
/** The folder containing page components source files. */
|
|
45
|
+
pagesDir?: string;
|
|
46
|
+
};
|
|
47
|
+
/** Config for code generation */
|
|
48
|
+
code: CodeConfig;
|
|
49
|
+
/** Config for pictures */
|
|
50
|
+
images: ImagesConfig;
|
|
51
|
+
/** Config for style generation */
|
|
52
|
+
style: StyleConfig;
|
|
53
|
+
/** Config for style tokens */
|
|
54
|
+
tokens: TokensConfig;
|
|
55
|
+
/** Metadata for global variant groups */
|
|
56
|
+
globalVariants: GlobalVariantsConfig;
|
|
57
|
+
/** Metadata for each project that has been synced */
|
|
58
|
+
projects: ProjectConfig[];
|
|
59
|
+
/** The version of cli when this file was written */
|
|
60
|
+
cliVersion?: string;
|
|
61
|
+
/** Arbitrary command to run after `plasmic sync` has run; useful for linting and code formatting synced files */
|
|
62
|
+
postSyncCommands?: string[];
|
|
63
|
+
}
|
|
64
|
+
export interface CodeConfig {
|
|
65
|
+
/** Language to generate code in */
|
|
66
|
+
lang: "ts" | "js";
|
|
67
|
+
/** The default code generation scheme. Each component can override the scheme. */
|
|
68
|
+
scheme: "blackbox" | "direct";
|
|
69
|
+
reactRuntime: "classic" | "automatic";
|
|
70
|
+
}
|
|
71
|
+
export interface StyleConfig {
|
|
72
|
+
/** Styling framework to use */
|
|
73
|
+
scheme: "css" | "css-modules";
|
|
74
|
+
/** File location for global css styles shared by all components. Relative to srcDir */
|
|
75
|
+
defaultStyleCssFilePath: string;
|
|
76
|
+
}
|
|
77
|
+
export interface ImagesConfig {
|
|
78
|
+
/**
|
|
79
|
+
* How image files should be referenced from generated React components. The choices are:
|
|
80
|
+
* * "files" - imported as relative files, like "import img from './image.png'". Not all bundlers support this.
|
|
81
|
+
* * "public-files" - images are stored in a public folder, and referenced from some url prefix, like `<img src="/static/image.png"/>`.
|
|
82
|
+
* * "inlined" - inlined directly into React files and css files as base64-encoded data-URIs.
|
|
83
|
+
* * "cdn" - images are served from Plasmic's CDN. Allows for dynamic resizing of images for
|
|
84
|
+
* serving the optimal file size given browser viewport.
|
|
85
|
+
*/
|
|
86
|
+
scheme: "inlined" | "files" | "public-files" | "cdn";
|
|
87
|
+
/**
|
|
88
|
+
* The folder where "public" static files are stored. Plasmic-managed image files will be stored as "plasmic/project-name/image-name" under this folder. Relative to srcDir; for example, "../public"
|
|
89
|
+
*/
|
|
90
|
+
publicDir?: string;
|
|
91
|
+
/**
|
|
92
|
+
* The url prefix where "public" static files are stored. For example, if publicDir is "public", publicUrlPrefix is "/static", then a file at public/test.png will be served at /static/test.png.
|
|
93
|
+
*/
|
|
94
|
+
publicUrlPrefix?: string;
|
|
95
|
+
}
|
|
96
|
+
export interface JsBundleThemeConfig {
|
|
97
|
+
themeFilePath: string;
|
|
98
|
+
bundleName: string;
|
|
99
|
+
}
|
|
100
|
+
export interface CodeComponentConfig {
|
|
101
|
+
id: string;
|
|
102
|
+
name: string;
|
|
103
|
+
componentImportPath: string;
|
|
104
|
+
}
|
|
105
|
+
export interface ProjectConfig {
|
|
106
|
+
/** Project ID */
|
|
107
|
+
projectId: string;
|
|
108
|
+
/** Project API token. Grants read-only sync access to just this specific project and its dependencies. */
|
|
109
|
+
projectApiToken?: string;
|
|
110
|
+
/** Project name synced down from Studio */
|
|
111
|
+
projectName: string;
|
|
112
|
+
/**
|
|
113
|
+
* A version range for syncing this project. Can be:
|
|
114
|
+
* * "latest" - always syncs down whatever has been saved in the project.
|
|
115
|
+
* * ">0" - always syncs down the latest published version of the project.
|
|
116
|
+
* * any other semver string you'd like
|
|
117
|
+
*/
|
|
118
|
+
version: string;
|
|
119
|
+
/** File location for the project-wide css styles. Relative to srcDir */
|
|
120
|
+
cssFilePath: string;
|
|
121
|
+
jsBundleThemes?: JsBundleThemeConfig[];
|
|
122
|
+
codeComponents?: CodeComponentConfig[];
|
|
123
|
+
/** Metadata for each synced component in this project. */
|
|
124
|
+
components: ComponentConfig[];
|
|
125
|
+
/** Metadata for each synced icon in this project */
|
|
126
|
+
icons: IconConfig[];
|
|
127
|
+
/** Metadata for each synced image in this project */
|
|
128
|
+
images: ImageConfig[];
|
|
129
|
+
}
|
|
130
|
+
export declare function createProjectConfig(base: {
|
|
131
|
+
projectId: string;
|
|
132
|
+
projectApiToken: string;
|
|
133
|
+
projectName: string;
|
|
134
|
+
version: string;
|
|
135
|
+
cssFilePath: string;
|
|
136
|
+
}): ProjectConfig;
|
|
137
|
+
export interface TokensConfig {
|
|
138
|
+
scheme: "theo";
|
|
139
|
+
tokensFilePath: string;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Describes how to import a Component
|
|
143
|
+
*/
|
|
144
|
+
export interface ImportSpec {
|
|
145
|
+
/**
|
|
146
|
+
* The import path to use to instantiate this Component. The modulePath can be:
|
|
147
|
+
* * An external npm module, like "antd/lib/button"
|
|
148
|
+
* * A local file, like "components/Button.tsx" (path is relative to srcDir, and file extension is fully specified). If local file is specified, then the module is imported via relative path.
|
|
149
|
+
*
|
|
150
|
+
* For this to be an external npm module, the ComponentConfig.type must be "mapped".
|
|
151
|
+
*/
|
|
152
|
+
modulePath: string;
|
|
153
|
+
/**
|
|
154
|
+
* If the Component is a named export of the module, then this is the name. If the Component
|
|
155
|
+
* is the default export, then this is undefined.
|
|
156
|
+
*/
|
|
157
|
+
exportName?: string;
|
|
158
|
+
}
|
|
159
|
+
export interface ComponentConfig {
|
|
160
|
+
/** Component ID */
|
|
161
|
+
id: string;
|
|
162
|
+
/** Javascript name of component */
|
|
163
|
+
name: string;
|
|
164
|
+
/** Plasmic project that this component belongs in */
|
|
165
|
+
projectId: string;
|
|
166
|
+
/** Whether this component is managed by Plasmic -- with Plasmic* files generated -- or mapped to an external library */
|
|
167
|
+
type: "managed" | "mapped";
|
|
168
|
+
/** How to import this Component from another component file */
|
|
169
|
+
importSpec: ImportSpec;
|
|
170
|
+
/** The file path for the blackbox render module, relative to srcDir. */
|
|
171
|
+
renderModuleFilePath: string;
|
|
172
|
+
/** The file path for the component css file, relative to srcDir. */
|
|
173
|
+
cssFilePath: string;
|
|
174
|
+
/** Code generation scheme used for this component */
|
|
175
|
+
scheme: "blackbox" | "direct";
|
|
176
|
+
componentType: "page" | "component";
|
|
177
|
+
/** Plume type if component is a Plume component */
|
|
178
|
+
plumeType?: string;
|
|
179
|
+
}
|
|
180
|
+
export interface IconConfig {
|
|
181
|
+
/** ID of icon */
|
|
182
|
+
id: string;
|
|
183
|
+
/** Javascript name of the React component for this icon */
|
|
184
|
+
name: string;
|
|
185
|
+
/** The file path for the React component file for this icon, relative to srcDir. */
|
|
186
|
+
moduleFilePath: string;
|
|
187
|
+
}
|
|
188
|
+
export interface ImageConfig {
|
|
189
|
+
/** ID of image */
|
|
190
|
+
id: string;
|
|
191
|
+
/** name of image */
|
|
192
|
+
name: string;
|
|
193
|
+
/** File path for the image file, relative to srcDir */
|
|
194
|
+
filePath: string;
|
|
195
|
+
}
|
|
196
|
+
export interface GlobalVariantsConfig {
|
|
197
|
+
variantGroups: GlobalVariantGroupConfig[];
|
|
198
|
+
}
|
|
199
|
+
export interface GlobalVariantGroupConfig {
|
|
200
|
+
/** ID of the global variant group */
|
|
201
|
+
id: string;
|
|
202
|
+
/** Javascript name of the global variant group */
|
|
203
|
+
name: string;
|
|
204
|
+
/** Plasmic project this global variant group belongs to */
|
|
205
|
+
projectId: string;
|
|
206
|
+
/** File path for the global variant group React context definition, relative to srcDir */
|
|
207
|
+
contextFilePath: string;
|
|
208
|
+
}
|
|
209
|
+
export interface FileLock {
|
|
210
|
+
type: "renderModule" | "cssRules" | "icon" | "image" | "projectCss" | "globalVariant";
|
|
211
|
+
checksum: string;
|
|
212
|
+
assetId: string;
|
|
213
|
+
}
|
|
214
|
+
export interface ProjectLock {
|
|
215
|
+
projectId: string;
|
|
216
|
+
version: string;
|
|
217
|
+
dependencies: {
|
|
218
|
+
[projectId: string]: string;
|
|
219
|
+
};
|
|
220
|
+
lang: "ts" | "js";
|
|
221
|
+
fileLocks: FileLock[];
|
|
222
|
+
}
|
|
223
|
+
export interface PlasmicLock {
|
|
224
|
+
projects: ProjectLock[];
|
|
225
|
+
cliVersion?: string;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* PlasmicContext is the PlasmicConfig plus context in which the PlasmicConfig was
|
|
229
|
+
* created.
|
|
230
|
+
*/
|
|
231
|
+
export interface PlasmicContext {
|
|
232
|
+
configFile: string;
|
|
233
|
+
lockFile: string;
|
|
234
|
+
rootDir: string;
|
|
235
|
+
absoluteSrcDir: string;
|
|
236
|
+
config: PlasmicConfig;
|
|
237
|
+
lock: PlasmicLock;
|
|
238
|
+
auth: AuthConfig;
|
|
239
|
+
api: PlasmicApi;
|
|
240
|
+
cliArgs: any;
|
|
241
|
+
}
|
|
242
|
+
export interface AuthConfig {
|
|
243
|
+
host: string;
|
|
244
|
+
user: string;
|
|
245
|
+
token: string;
|
|
246
|
+
basicAuthUser?: string;
|
|
247
|
+
basicAuthPassword?: string;
|
|
248
|
+
}
|
|
249
|
+
export declare const DEFAULT_CONFIG: PlasmicConfig;
|
|
250
|
+
export declare const DEFAULT_PUBLIC_FILES_CONFIG: ImagesConfig;
|
|
251
|
+
/**
|
|
252
|
+
* Finds the full path to the plasmic.json file in `dir`. If
|
|
253
|
+
* `opts.traverseParents` is set to true, then will also look in ancestor
|
|
254
|
+
* directories until the plasmic.json file is found. If none is found,
|
|
255
|
+
* returns undefined.
|
|
256
|
+
*/
|
|
257
|
+
export declare function findConfigFile(dir: string, opts: {
|
|
258
|
+
traverseParents?: boolean;
|
|
259
|
+
}): string | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* Given some partial configs for PlasmicConfig, fills in all required fields
|
|
262
|
+
* with default values.
|
|
263
|
+
*/
|
|
264
|
+
export declare function fillDefaults(config: DeepPartial<PlasmicConfig>): PlasmicConfig;
|
|
265
|
+
export declare function readConfig(configFile: string, autoFillDefaults: boolean): PlasmicConfig;
|
|
266
|
+
export declare function writeConfig(configFile: string, config: PlasmicConfig, baseDir: string): Promise<void>;
|
|
267
|
+
export declare function writeLock(lockFile: string, lock: PlasmicLock, baseDir: string): Promise<void>;
|
|
268
|
+
export declare function updateConfig(context: PlasmicContext, newConfig: PlasmicConfig, baseDir: string): Promise<void>;
|
|
269
|
+
export declare function getOrAddProjectConfig(context: PlasmicContext, projectId: string, base?: ProjectConfig): ProjectConfig;
|
|
270
|
+
export declare function getOrAddProjectLock(context: PlasmicContext, projectId: string, base?: ProjectLock): ProjectLock;
|
|
271
|
+
export declare function isPageAwarePlatform(platform: string): boolean;
|
|
@@ -0,0 +1,178 @@
|
|
|
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.isPageAwarePlatform = exports.getOrAddProjectLock = exports.getOrAddProjectConfig = exports.updateConfig = exports.writeLock = exports.writeConfig = exports.readConfig = exports.fillDefaults = exports.findConfigFile = exports.DEFAULT_PUBLIC_FILES_CONFIG = exports.DEFAULT_CONFIG = exports.createProjectConfig = exports.ENV_AUTH_TOKEN = exports.ENV_AUTH_USER = exports.ENV_AUTH_HOST = exports.CONFIG_SCHEMA_FILE_NAME = exports.LOADER_CONFIG_FILE_NAME = exports.LOCK_FILE_NAME = exports.CONFIG_FILE_NAME = exports.AUTH_FILE_NAME = exports.DEFAULT_HOST = void 0;
|
|
16
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
17
|
+
const deps_1 = require("../deps");
|
|
18
|
+
const error_1 = require("../utils/error");
|
|
19
|
+
const code_utils_1 = require("./code-utils");
|
|
20
|
+
const file_utils_1 = require("./file-utils");
|
|
21
|
+
exports.DEFAULT_HOST = process.env.PLASMIC_DEFAULT_HOST || "https://studio.plasmic.app";
|
|
22
|
+
// Default filenames
|
|
23
|
+
exports.AUTH_FILE_NAME = ".plasmic.auth";
|
|
24
|
+
exports.CONFIG_FILE_NAME = "plasmic.json";
|
|
25
|
+
exports.LOCK_FILE_NAME = "plasmic.lock";
|
|
26
|
+
exports.LOADER_CONFIG_FILE_NAME = "plasmic-loader.json";
|
|
27
|
+
exports.CONFIG_SCHEMA_FILE_NAME = "plasmic.schema.json";
|
|
28
|
+
// Default environment variable names
|
|
29
|
+
exports.ENV_AUTH_HOST = "PLASMIC_AUTH_HOST";
|
|
30
|
+
exports.ENV_AUTH_USER = "PLASMIC_AUTH_USER";
|
|
31
|
+
exports.ENV_AUTH_TOKEN = "PLASMIC_AUTH_TOKEN";
|
|
32
|
+
function createProjectConfig(base) {
|
|
33
|
+
return {
|
|
34
|
+
projectId: base.projectId,
|
|
35
|
+
projectApiToken: base.projectApiToken,
|
|
36
|
+
projectName: base.projectName,
|
|
37
|
+
version: base.version,
|
|
38
|
+
cssFilePath: base.cssFilePath,
|
|
39
|
+
components: [],
|
|
40
|
+
icons: [],
|
|
41
|
+
images: [],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
exports.createProjectConfig = createProjectConfig;
|
|
45
|
+
exports.DEFAULT_CONFIG = {
|
|
46
|
+
platform: "react",
|
|
47
|
+
code: {
|
|
48
|
+
lang: "ts",
|
|
49
|
+
scheme: "blackbox",
|
|
50
|
+
reactRuntime: "classic",
|
|
51
|
+
},
|
|
52
|
+
style: {
|
|
53
|
+
scheme: "css-modules",
|
|
54
|
+
// We set it to empty to compile. In reality, it will be provided the by
|
|
55
|
+
// the server.
|
|
56
|
+
defaultStyleCssFilePath: "",
|
|
57
|
+
},
|
|
58
|
+
images: {
|
|
59
|
+
scheme: "inlined",
|
|
60
|
+
},
|
|
61
|
+
tokens: {
|
|
62
|
+
scheme: "theo",
|
|
63
|
+
tokensFilePath: "plasmic-tokens.theo.json",
|
|
64
|
+
},
|
|
65
|
+
srcDir: "./src/components",
|
|
66
|
+
defaultPlasmicDir: "./plasmic",
|
|
67
|
+
projects: [],
|
|
68
|
+
globalVariants: {
|
|
69
|
+
variantGroups: [],
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
exports.DEFAULT_PUBLIC_FILES_CONFIG = {
|
|
73
|
+
scheme: "public-files",
|
|
74
|
+
publicDir: "../public",
|
|
75
|
+
publicUrlPrefix: "/static/",
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Finds the full path to the plasmic.json file in `dir`. If
|
|
79
|
+
* `opts.traverseParents` is set to true, then will also look in ancestor
|
|
80
|
+
* directories until the plasmic.json file is found. If none is found,
|
|
81
|
+
* returns undefined.
|
|
82
|
+
*/
|
|
83
|
+
function findConfigFile(dir, opts) {
|
|
84
|
+
return file_utils_1.findFile(dir, (f) => f === exports.CONFIG_FILE_NAME, opts);
|
|
85
|
+
}
|
|
86
|
+
exports.findConfigFile = findConfigFile;
|
|
87
|
+
/**
|
|
88
|
+
* Given some partial configs for PlasmicConfig, fills in all required fields
|
|
89
|
+
* with default values.
|
|
90
|
+
*/
|
|
91
|
+
function fillDefaults(config) {
|
|
92
|
+
return lodash_1.default.merge({}, exports.DEFAULT_CONFIG, config);
|
|
93
|
+
}
|
|
94
|
+
exports.fillDefaults = fillDefaults;
|
|
95
|
+
function readConfig(configFile, autoFillDefaults) {
|
|
96
|
+
if (!file_utils_1.existsBuffered(configFile)) {
|
|
97
|
+
const err = new error_1.HandledError(`No Plasmic config file found at ${configFile}`);
|
|
98
|
+
throw err;
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
const result = JSON.parse(file_utils_1.readFileText(configFile));
|
|
102
|
+
return autoFillDefaults ? fillDefaults(result) : result;
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
deps_1.logger.error(`Error encountered reading ${exports.CONFIG_FILE_NAME} at ${configFile}: ${e}`);
|
|
106
|
+
throw e;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.readConfig = readConfig;
|
|
110
|
+
function writeConfig(configFile, config, baseDir) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
yield file_utils_1.writeFileContentRaw(configFile, code_utils_1.formatAsLocal(JSON.stringify(Object.assign(Object.assign({}, config), { $schema: `https://unpkg.com/@plasmicapp/cli@${config.cliVersion}/dist/plasmic.schema.json` }), undefined, 2), configFile, baseDir), {
|
|
113
|
+
force: true,
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
exports.writeConfig = writeConfig;
|
|
118
|
+
function writeLock(lockFile, lock, baseDir) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
yield file_utils_1.writeFileContentRaw(lockFile, code_utils_1.formatAsLocal(JSON.stringify(lock, undefined, 2), "/tmp/x.json", baseDir), {
|
|
121
|
+
force: true,
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
exports.writeLock = writeLock;
|
|
126
|
+
function updateConfig(context, newConfig, baseDir) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
// plasmic.json
|
|
129
|
+
yield writeConfig(context.configFile, newConfig, baseDir);
|
|
130
|
+
context.config = newConfig;
|
|
131
|
+
// plasmic.lock
|
|
132
|
+
yield writeLock(context.lockFile, context.lock, baseDir);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
exports.updateConfig = updateConfig;
|
|
136
|
+
function getOrAddProjectConfig(context, projectId, base // if one doesn't exist, start with this
|
|
137
|
+
) {
|
|
138
|
+
let project = context.config.projects.find((p) => p.projectId === projectId);
|
|
139
|
+
if (!project) {
|
|
140
|
+
project = !!base
|
|
141
|
+
? lodash_1.default.cloneDeep(base)
|
|
142
|
+
: {
|
|
143
|
+
projectId,
|
|
144
|
+
projectName: "",
|
|
145
|
+
version: "latest",
|
|
146
|
+
cssFilePath: "",
|
|
147
|
+
components: [],
|
|
148
|
+
icons: [],
|
|
149
|
+
images: [],
|
|
150
|
+
jsBundleThemes: [],
|
|
151
|
+
};
|
|
152
|
+
context.config.projects.push(project);
|
|
153
|
+
}
|
|
154
|
+
return project;
|
|
155
|
+
}
|
|
156
|
+
exports.getOrAddProjectConfig = getOrAddProjectConfig;
|
|
157
|
+
function getOrAddProjectLock(context, projectId, base // if one doesn't exist, start with this
|
|
158
|
+
) {
|
|
159
|
+
let project = context.lock.projects.find((p) => p.projectId === projectId);
|
|
160
|
+
if (!project) {
|
|
161
|
+
project = !!base
|
|
162
|
+
? lodash_1.default.cloneDeep(base)
|
|
163
|
+
: {
|
|
164
|
+
projectId,
|
|
165
|
+
version: "",
|
|
166
|
+
dependencies: {},
|
|
167
|
+
lang: context.config.code.lang,
|
|
168
|
+
fileLocks: [],
|
|
169
|
+
};
|
|
170
|
+
context.lock.projects.push(project);
|
|
171
|
+
}
|
|
172
|
+
return project;
|
|
173
|
+
}
|
|
174
|
+
exports.getOrAddProjectLock = getOrAddProjectLock;
|
|
175
|
+
function isPageAwarePlatform(platform) {
|
|
176
|
+
return platform === "nextjs" || platform === "gatsby";
|
|
177
|
+
}
|
|
178
|
+
exports.isPageAwarePlatform = isPageAwarePlatform;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.detectCreateReactApp = exports.detectGatsby = exports.detectNextJs = exports.detectTypescript = void 0;
|
|
7
|
+
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
8
|
+
const npm_utils_1 = require("./npm-utils");
|
|
9
|
+
function detectTypescript() {
|
|
10
|
+
return findup_sync_1.default("tsconfig.json");
|
|
11
|
+
}
|
|
12
|
+
exports.detectTypescript = detectTypescript;
|
|
13
|
+
function detectNextJs() {
|
|
14
|
+
if (findup_sync_1.default("next.config.js") ||
|
|
15
|
+
findup_sync_1.default(".next") ||
|
|
16
|
+
findup_sync_1.default("next-env.d.ts")) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const packageJsonContent = npm_utils_1.getParsedPackageJson();
|
|
21
|
+
return (packageJsonContent.scripts.build === "next build" ||
|
|
22
|
+
"next" in packageJsonContent.dependencies);
|
|
23
|
+
}
|
|
24
|
+
catch (_a) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.detectNextJs = detectNextJs;
|
|
29
|
+
function detectGatsby() {
|
|
30
|
+
return findup_sync_1.default("gatsby-config.js");
|
|
31
|
+
}
|
|
32
|
+
exports.detectGatsby = detectGatsby;
|
|
33
|
+
function detectCreateReactApp() {
|
|
34
|
+
try {
|
|
35
|
+
const packageJsonContent = npm_utils_1.getParsedPackageJson();
|
|
36
|
+
return "react-scripts" in packageJsonContent.dependencies;
|
|
37
|
+
}
|
|
38
|
+
catch (_a) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.detectCreateReactApp = detectCreateReactApp;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an error that doesn't need to be forwarded to Sentry.
|
|
3
|
+
* These are errors that are user-fault, for example:
|
|
4
|
+
* - Using an old version of CLI
|
|
5
|
+
*/
|
|
6
|
+
export declare class HandledError extends Error {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Catches HandledErrors and just exits
|
|
10
|
+
* Forwards all other errors along.
|
|
11
|
+
* @param p
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export declare const handleError: <T>(p: Promise<T>) => Promise<T>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.handleError = exports.HandledError = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const deps_1 = require("../deps");
|
|
9
|
+
const npm_utils_1 = require("./npm-utils");
|
|
10
|
+
/**
|
|
11
|
+
* Represents an error that doesn't need to be forwarded to Sentry.
|
|
12
|
+
* These are errors that are user-fault, for example:
|
|
13
|
+
* - Using an old version of CLI
|
|
14
|
+
*/
|
|
15
|
+
class HandledError extends Error {
|
|
16
|
+
}
|
|
17
|
+
exports.HandledError = HandledError;
|
|
18
|
+
/**
|
|
19
|
+
* Catches HandledErrors and just exits
|
|
20
|
+
* Forwards all other errors along.
|
|
21
|
+
* @param p
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
exports.handleError = (p) => {
|
|
25
|
+
return p.catch((e) => {
|
|
26
|
+
if (e.message) {
|
|
27
|
+
deps_1.logger.error(chalk_1.default.bold(chalk_1.default.redBright("\nPlasmic error: ")) + e.message);
|
|
28
|
+
}
|
|
29
|
+
// Check if we satisfy the engine policy first
|
|
30
|
+
if (npm_utils_1.checkEngineStrict()) {
|
|
31
|
+
// eslint-disable-next-line
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
else if (e instanceof HandledError) {
|
|
35
|
+
// eslint-disable-next-line
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
throw e;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ProjectMetaBundle } from "../api";
|
|
3
|
+
import { PlasmicContext, ProjectConfig } from "./config-utils";
|
|
4
|
+
export declare function stripExtension(filename: string, removeComposedPath?: boolean): string;
|
|
5
|
+
export declare function writeFileContentRaw(filePath: string, content: string | Buffer, opts?: {
|
|
6
|
+
force?: boolean;
|
|
7
|
+
yes?: boolean;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
export declare function defaultResourcePath(context: PlasmicContext, project: ProjectConfig | ProjectMetaBundle | string, ...subpaths: string[]): string;
|
|
10
|
+
export declare function defaultPublicResourcePath(context: PlasmicContext, project: ProjectConfig, ...subpaths: string[]): string;
|
|
11
|
+
export declare function defaultPagePath(context: PlasmicContext, fileName: string): string;
|
|
12
|
+
export declare function writeFileContent(context: PlasmicContext, srcDirFilePath: string, content: string | Buffer, opts?: {
|
|
13
|
+
force?: boolean;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
export declare function readFileContent(context: PlasmicContext, srcDirFilePath: string): string;
|
|
16
|
+
export declare function deleteFile(context: PlasmicContext, srcDirFilePath: string): void;
|
|
17
|
+
export declare function fileExists(context: PlasmicContext, srcDirFilePath: string): boolean;
|
|
18
|
+
export declare function makeFilePath(context: PlasmicContext, filePath: string): string;
|
|
19
|
+
export declare function renameFile(context: PlasmicContext, oldPath: string, newPath: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Returns absolute paths of all Plasmic managed files found, grouped by each basename
|
|
22
|
+
* for example:
|
|
23
|
+
* {
|
|
24
|
+
* "file.txt": [ "/path1/file.txt", "/path2.txt" ]
|
|
25
|
+
* ...
|
|
26
|
+
* }
|
|
27
|
+
* @param {PlasmicContext} context
|
|
28
|
+
* @returns {Record<string, string[]>}
|
|
29
|
+
**/
|
|
30
|
+
export declare function buildBaseNameToFiles(context: PlasmicContext): Record<string, string[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Tries to find the file at `srcDir/expectedPath`. If it's not there, tries to detect if it has
|
|
33
|
+
* been moved to a different location. Returns the found location relative to the `srcDir`.
|
|
34
|
+
*
|
|
35
|
+
* If `expectedPath` doesn't exist, but there's more than one file of that name in `baseNameToFiles`, then
|
|
36
|
+
* error and quit. If no file of that name can be found, `expectedPath` is returned.
|
|
37
|
+
*/
|
|
38
|
+
export declare function findSrcDirPath(absoluteSrcDir: string, expectedPath: string, baseNameToFiles: Record<string, string[]>): string;
|
|
39
|
+
/**
|
|
40
|
+
* Finds the full path to the first file satisfying `pred` in `dir`. If
|
|
41
|
+
* `opts.traverseParents` is set to true, then will also look in ancestor
|
|
42
|
+
* directories until the plasmic.json file is found. If none is found,
|
|
43
|
+
* returns undefined.
|
|
44
|
+
*/
|
|
45
|
+
export declare function findFile(dir: string, pred: (name: string) => boolean, opts: {
|
|
46
|
+
traverseParents?: boolean;
|
|
47
|
+
}): string | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Fixes all src-relative file paths in PlasmicConfig by detecting file
|
|
50
|
+
* movement on disk.
|
|
51
|
+
*/
|
|
52
|
+
export declare function fixAllFilePaths(context: PlasmicContext, baseDir: string): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Throws an error if some file in PlasmicConfig is not inside the root
|
|
55
|
+
* directory (i.e., the directory containing plasmic.json).
|
|
56
|
+
*/
|
|
57
|
+
export declare function assertAllPathsInRootDir(context: PlasmicContext): void;
|
|
58
|
+
/**
|
|
59
|
+
* This turns on buffering of file writes/reads.
|
|
60
|
+
*
|
|
61
|
+
* This is useful for reducing the extent to which our file updates are scattered over time, which can cause webpack
|
|
62
|
+
* dev server to trip up.
|
|
63
|
+
*
|
|
64
|
+
* This also has the side benefit of making our CLI commands more atomic, in case of failure partway through a sync.
|
|
65
|
+
*/
|
|
66
|
+
export declare function withBufferedFs(f: () => Promise<void>): Promise<void>;
|
|
67
|
+
export declare function writeFileText(path: string, content: string | Buffer): void;
|
|
68
|
+
export declare function readFileText(path: string): string;
|
|
69
|
+
export declare function renameFileBuffered(oldPath: string, newPath: string): void;
|
|
70
|
+
export declare function deleteFileBuffered(path: string): void;
|
|
71
|
+
export declare function existsBuffered(path: string): boolean;
|