@plasmicapp/cli 0.1.178 → 0.1.181
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/dist/__mocks__/api.js +1 -0
- package/dist/actions/init.js +2 -1
- package/dist/actions/sync.js +9 -2
- package/dist/actions/watch.js +32 -2
- package/dist/api.d.ts +1 -0
- package/package.json +1 -1
- package/src/__mocks__/api.ts +1 -0
- package/src/actions/init.ts +2 -1
- package/src/actions/sync.ts +18 -4
- package/src/actions/watch.ts +63 -12
- package/src/api.ts +1 -0
package/dist/__mocks__/api.js
CHANGED
package/dist/actions/init.js
CHANGED
|
@@ -42,9 +42,10 @@ function initPlasmic(opts) {
|
|
|
42
42
|
if (!process.env.QUIET) {
|
|
43
43
|
deps_1.logger.info("Successfully created plasmic.json.\n");
|
|
44
44
|
}
|
|
45
|
-
const answer = yield user_utils_1.confirmWithUser("@plasmicapp/react-web
|
|
45
|
+
const answer = yield user_utils_1.confirmWithUser("@plasmicapp/host and @plasmicapp/react-web are small runtimes required by Plasmic-generated code.\n Do you want to add them now?", opts.yes);
|
|
46
46
|
if (answer) {
|
|
47
47
|
npm_utils_1.installUpgrade("@plasmicapp/react-web", opts.baseDir);
|
|
48
|
+
npm_utils_1.installUpgrade("@plasmicapp/host", opts.baseDir);
|
|
48
49
|
}
|
|
49
50
|
});
|
|
50
51
|
}
|
package/dist/actions/sync.js
CHANGED
|
@@ -88,6 +88,13 @@ function ensureRequiredPackages(context, baseDir, yes) {
|
|
|
88
88
|
semver.gt(requireds["@plasmicapp/react-web"], reactWebVersion)) {
|
|
89
89
|
yield confirmInstall("@plasmicapp/react-web", requireds["@plasmicapp/react-web"], { global: false, dev: false });
|
|
90
90
|
}
|
|
91
|
+
const hostVersion = npm_utils_1.findInstalledVersion(context, baseDir, "@plasmicapp/host");
|
|
92
|
+
if (!hostVersion || semver.gt(requireds["@plasmicapp/host"], hostVersion)) {
|
|
93
|
+
yield confirmInstall("@plasmicapp/host", requireds["@plasmicapp/host"], {
|
|
94
|
+
global: false,
|
|
95
|
+
dev: false,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
91
98
|
if (context.config.code.reactRuntime === "automatic") {
|
|
92
99
|
// Using automatic runtime requires installing the @plasmicapp/react-web-runtime package
|
|
93
100
|
const runtimeVersion = npm_utils_1.findInstalledVersion(context, baseDir, "@plasmicapp/react-web-runtime");
|
|
@@ -269,10 +276,10 @@ function sync(opts, metadataDefaults) {
|
|
|
269
276
|
}));
|
|
270
277
|
yield checkExternalPkgs(context, baseDir, opts, Array.from(externalNpmPackages.keys()));
|
|
271
278
|
if (!opts.quiet && externalCssImports.size > 0) {
|
|
272
|
-
deps_1.logger.info(`This project uses external packages and styles. Make sure to import the following global CSS: ` +
|
|
279
|
+
deps_1.logger.info(chalk_1.default.cyanBright.bold(`IMPORTANT: This project uses external packages and styles. Make sure to import the following global CSS: ` +
|
|
273
280
|
Array.from(externalCssImports.keys())
|
|
274
281
|
.map((stmt) => `"${stmt}"`)
|
|
275
|
-
.join(", "));
|
|
282
|
+
.join(", ")));
|
|
276
283
|
}
|
|
277
284
|
// Post-sync commands
|
|
278
285
|
if (!opts.ignorePostSync) {
|
package/dist/actions/watch.js
CHANGED
|
@@ -74,17 +74,47 @@ function watchProjects(opts, metadataDefaults, onProjectUpdate) {
|
|
|
74
74
|
socket.on("error", (data) => {
|
|
75
75
|
reject(new error_1.HandledError(data));
|
|
76
76
|
});
|
|
77
|
-
socket.on("update", (data) => __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
socket.on("update", asyncOneAtATime((data) => __awaiter(this, void 0, void 0, function* () {
|
|
78
78
|
// Just run syncProjects() for now when any project has been updated
|
|
79
79
|
// Note on the 'updated to revision' part: this is parsed by the
|
|
80
80
|
// loader package to know that we finished updating the components.
|
|
81
81
|
yield sync_1.sync(syncOpts, syncMetadata);
|
|
82
82
|
deps_1.logger.info(`[${moment_1.default().format("HH:mm:ss")}] Project ${data.projectId} updated to revision ${data.revisionNum}`);
|
|
83
83
|
onProjectUpdate === null || onProjectUpdate === void 0 ? void 0 : onProjectUpdate();
|
|
84
|
-
}));
|
|
84
|
+
}), true));
|
|
85
85
|
});
|
|
86
86
|
deps_1.logger.info(`Watching projects ${latestProjects} ...`);
|
|
87
87
|
return promise;
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
exports.watchProjects = watchProjects;
|
|
91
|
+
function asyncOneAtATime(f, bounceValue) {
|
|
92
|
+
let waitingCall = undefined, currentPromise = undefined;
|
|
93
|
+
function invoke({ args, resolve, reject }) {
|
|
94
|
+
const onCompletion = () => {
|
|
95
|
+
currentPromise = undefined;
|
|
96
|
+
if (waitingCall) {
|
|
97
|
+
invoke(waitingCall);
|
|
98
|
+
waitingCall = undefined;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
currentPromise = f(...args);
|
|
102
|
+
currentPromise.then(onCompletion, onCompletion);
|
|
103
|
+
currentPromise.then(resolve, reject);
|
|
104
|
+
}
|
|
105
|
+
return (...args) => {
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
if (!currentPromise) {
|
|
108
|
+
// Free to proceed.
|
|
109
|
+
invoke({ args, resolve, reject });
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
// Evict current waiter, and enqueue self.
|
|
113
|
+
if (waitingCall) {
|
|
114
|
+
waitingCall.resolve(bounceValue);
|
|
115
|
+
}
|
|
116
|
+
waitingCall = { args, resolve, reject };
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
}
|
package/dist/api.d.ts
CHANGED
package/package.json
CHANGED
package/src/__mocks__/api.ts
CHANGED
package/src/actions/init.ts
CHANGED
|
@@ -73,11 +73,12 @@ export async function initPlasmic(
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
const answer = await confirmWithUser(
|
|
76
|
-
"@plasmicapp/react-web
|
|
76
|
+
"@plasmicapp/host and @plasmicapp/react-web are small runtimes required by Plasmic-generated code.\n Do you want to add them now?",
|
|
77
77
|
opts.yes
|
|
78
78
|
);
|
|
79
79
|
if (answer) {
|
|
80
80
|
installUpgrade("@plasmicapp/react-web", opts.baseDir);
|
|
81
|
+
installUpgrade("@plasmicapp/host", opts.baseDir);
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
|
package/src/actions/sync.ts
CHANGED
|
@@ -143,6 +143,18 @@ async function ensureRequiredPackages(
|
|
|
143
143
|
);
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
+
const hostVersion = findInstalledVersion(
|
|
147
|
+
context,
|
|
148
|
+
baseDir,
|
|
149
|
+
"@plasmicapp/host"
|
|
150
|
+
);
|
|
151
|
+
if (!hostVersion || semver.gt(requireds["@plasmicapp/host"], hostVersion)) {
|
|
152
|
+
await confirmInstall("@plasmicapp/host", requireds["@plasmicapp/host"], {
|
|
153
|
+
global: false,
|
|
154
|
+
dev: false,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
146
158
|
if (context.config.code.reactRuntime === "automatic") {
|
|
147
159
|
// Using automatic runtime requires installing the @plasmicapp/react-web-runtime package
|
|
148
160
|
const runtimeVersion = findInstalledVersion(
|
|
@@ -440,10 +452,12 @@ export async function sync(
|
|
|
440
452
|
|
|
441
453
|
if (!opts.quiet && externalCssImports.size > 0) {
|
|
442
454
|
logger.info(
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
.
|
|
446
|
-
|
|
455
|
+
chalk.cyanBright.bold(
|
|
456
|
+
`IMPORTANT: This project uses external packages and styles. Make sure to import the following global CSS: ` +
|
|
457
|
+
Array.from(externalCssImports.keys())
|
|
458
|
+
.map((stmt) => `"${stmt}"`)
|
|
459
|
+
.join(", ")
|
|
460
|
+
)
|
|
447
461
|
);
|
|
448
462
|
}
|
|
449
463
|
|
package/src/actions/watch.ts
CHANGED
|
@@ -75,21 +75,72 @@ export async function watchProjects(
|
|
|
75
75
|
socket.on("error", (data: any) => {
|
|
76
76
|
reject(new HandledError(data));
|
|
77
77
|
});
|
|
78
|
-
socket.on(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
78
|
+
socket.on(
|
|
79
|
+
"update",
|
|
80
|
+
asyncOneAtATime(async (data: any) => {
|
|
81
|
+
// Just run syncProjects() for now when any project has been updated
|
|
82
|
+
// Note on the 'updated to revision' part: this is parsed by the
|
|
83
|
+
// loader package to know that we finished updating the components.
|
|
84
|
+
await sync(syncOpts, syncMetadata);
|
|
85
|
+
logger.info(
|
|
86
|
+
`[${moment().format("HH:mm:ss")}] Project ${
|
|
87
|
+
data.projectId
|
|
88
|
+
} updated to revision ${data.revisionNum}`
|
|
89
|
+
);
|
|
88
90
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
onProjectUpdate?.();
|
|
92
|
+
}, true)
|
|
93
|
+
);
|
|
91
94
|
});
|
|
92
95
|
|
|
93
96
|
logger.info(`Watching projects ${latestProjects} ...`);
|
|
94
97
|
return promise;
|
|
95
98
|
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Throttle invocations of a function to allow a single outstanding invocation
|
|
102
|
+
* at a time.
|
|
103
|
+
*
|
|
104
|
+
* But, has a buffer of size one, so that after the current invocation
|
|
105
|
+
* completes, it calls the last attempted invocation.
|
|
106
|
+
*
|
|
107
|
+
* Other invocations that get evicted from the buffer get returned bounceValue
|
|
108
|
+
* upon eviction.
|
|
109
|
+
*/
|
|
110
|
+
type AsyncCallable = (...args: any[]) => Promise<any>;
|
|
111
|
+
|
|
112
|
+
function asyncOneAtATime(f: AsyncCallable, bounceValue: any): AsyncCallable {
|
|
113
|
+
interface CallInfo {
|
|
114
|
+
args: any[];
|
|
115
|
+
resolve: any;
|
|
116
|
+
reject: any;
|
|
117
|
+
}
|
|
118
|
+
let waitingCall: CallInfo | undefined = undefined,
|
|
119
|
+
currentPromise: Promise<any> | undefined = undefined;
|
|
120
|
+
function invoke({ args, resolve, reject }: CallInfo) {
|
|
121
|
+
const onCompletion = () => {
|
|
122
|
+
currentPromise = undefined;
|
|
123
|
+
if (waitingCall) {
|
|
124
|
+
invoke(waitingCall);
|
|
125
|
+
waitingCall = undefined;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
currentPromise = f(...args);
|
|
129
|
+
currentPromise.then(onCompletion, onCompletion);
|
|
130
|
+
currentPromise.then(resolve, reject);
|
|
131
|
+
}
|
|
132
|
+
return (...args: any[]) => {
|
|
133
|
+
return new Promise((resolve, reject) => {
|
|
134
|
+
if (!currentPromise) {
|
|
135
|
+
// Free to proceed.
|
|
136
|
+
invoke({ args, resolve, reject });
|
|
137
|
+
} else {
|
|
138
|
+
// Evict current waiter, and enqueue self.
|
|
139
|
+
if (waitingCall) {
|
|
140
|
+
waitingCall.resolve(bounceValue);
|
|
141
|
+
}
|
|
142
|
+
waitingCall = { args, resolve, reject };
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
}
|
package/src/api.ts
CHANGED