@stackable-labs/cli-app-extension 2.3.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +45 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@ import { createRequire } from 'module';
|
|
|
3
3
|
import { program, InvalidArgumentError } from 'commander';
|
|
4
4
|
import { render, useApp, Box, Text, useInput, useFocus, useFocusManager } from 'ink';
|
|
5
5
|
import { SURFACE_TARGET, TEMPLATE_FLAVORS } from '@stackable-labs/sdk-extension-contracts';
|
|
6
|
-
import { unlink, readFile, writeFile, mkdir, readdir,
|
|
7
|
-
import { join, dirname } from 'path';
|
|
6
|
+
import { unlink, readFile, writeFile, mkdir, rm, readdir, rmdir } from 'fs/promises';
|
|
7
|
+
import { join, dirname, relative } from 'path';
|
|
8
8
|
import Spinner5 from 'ink-spinner';
|
|
9
9
|
import { useState, useCallback, useEffect, useRef, useMemo } from 'react';
|
|
10
10
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
@@ -1959,6 +1959,44 @@ var walkFiles = async (rootDir) => {
|
|
|
1959
1959
|
}
|
|
1960
1960
|
return files;
|
|
1961
1961
|
};
|
|
1962
|
+
var STUDIO_OVERLAY_PRESERVE = /* @__PURE__ */ new Set([]);
|
|
1963
|
+
var removeEmptyDirs = async (rootDir) => {
|
|
1964
|
+
let entries;
|
|
1965
|
+
try {
|
|
1966
|
+
entries = await readdir(rootDir, { withFileTypes: true });
|
|
1967
|
+
} catch {
|
|
1968
|
+
return;
|
|
1969
|
+
}
|
|
1970
|
+
for (const entry of entries) {
|
|
1971
|
+
if (entry.isDirectory()) {
|
|
1972
|
+
await removeEmptyDirs(join(rootDir, entry.name));
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
try {
|
|
1976
|
+
await rmdir(rootDir);
|
|
1977
|
+
} catch {
|
|
1978
|
+
}
|
|
1979
|
+
};
|
|
1980
|
+
var cleanupTemplateOnlyFiles = async (extensionSrcDir, studioFiles) => {
|
|
1981
|
+
const studioPaths = new Set(Object.keys(studioFiles));
|
|
1982
|
+
const existingFiles = await walkFiles(extensionSrcDir);
|
|
1983
|
+
for (const filePath of existingFiles) {
|
|
1984
|
+
const rel = relative(extensionSrcDir, filePath);
|
|
1985
|
+
if (studioPaths.has(rel)) {
|
|
1986
|
+
continue;
|
|
1987
|
+
}
|
|
1988
|
+
if (STUDIO_OVERLAY_PRESERVE.has(rel)) {
|
|
1989
|
+
continue;
|
|
1990
|
+
}
|
|
1991
|
+
await rm(filePath, { force: true });
|
|
1992
|
+
}
|
|
1993
|
+
const entries = await readdir(extensionSrcDir, { withFileTypes: true });
|
|
1994
|
+
for (const entry of entries) {
|
|
1995
|
+
if (entry.isDirectory()) {
|
|
1996
|
+
await removeEmptyDirs(join(extensionSrcDir, entry.name));
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
};
|
|
1962
2000
|
var replacePlaceholders = async (rootDir, replacements) => {
|
|
1963
2001
|
const files = await walkFiles(rootDir);
|
|
1964
2002
|
for (const filePath of files) {
|
|
@@ -2233,8 +2271,11 @@ var scaffold = async (options) => {
|
|
|
2233
2271
|
previewPort: options.previewPort});
|
|
2234
2272
|
if (options.projectFiles) {
|
|
2235
2273
|
const extensionSrcDir = join(dir, "packages/extension/src");
|
|
2274
|
+
await cleanupTemplateOnlyFiles(extensionSrcDir, options.projectFiles);
|
|
2236
2275
|
for (const [filename, content] of Object.entries(options.projectFiles)) {
|
|
2237
|
-
|
|
2276
|
+
const fullPath = join(extensionSrcDir, filename);
|
|
2277
|
+
await mkdir(dirname(fullPath), { recursive: true });
|
|
2278
|
+
await writeFile(fullPath, content);
|
|
2238
2279
|
}
|
|
2239
2280
|
}
|
|
2240
2281
|
if (options.projectManifest) {
|
|
@@ -2335,6 +2376,7 @@ var App = ({ command, token, userId, orgId, initialName, initialExtensionId, opt
|
|
|
2335
2376
|
setStudioProject(project);
|
|
2336
2377
|
setName(project.name);
|
|
2337
2378
|
setTargets(project.manifest.targets);
|
|
2379
|
+
setTemplateFlavor("minimal");
|
|
2338
2380
|
if (project.extensionId) {
|
|
2339
2381
|
setExtensionId(project.extensionId);
|
|
2340
2382
|
}
|