@vueless/storybook 0.0.16 → 0.0.18
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/README.md +2 -0
- package/index.js +32 -7
- package/package.json +1 -1
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import fs from "fs";
|
|
3
|
+
import fs, { promises } from "fs";
|
|
4
4
|
import path from "path";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const __dirname = path.dirname(new URL(import.meta.url).pathname);
|
|
7
|
+
|
|
8
|
+
const source = path.join(__dirname, ".storybook");
|
|
9
|
+
const target = path.join(__dirname, "..", "..", "..", ".storybook");
|
|
10
|
+
|
|
11
|
+
copyStorybookPreset(source, target);
|
|
12
|
+
|
|
13
|
+
await addStorybookCommands();
|
|
14
|
+
|
|
15
|
+
function copyStorybookPreset(source, target) {
|
|
7
16
|
if (fs.existsSync(target)) {
|
|
8
17
|
const timestamp = new Date().valueOf();
|
|
9
18
|
const renamedTarget = `${target}-${timestamp}`;
|
|
@@ -21,13 +30,29 @@ function copyFolderSync(source, target) {
|
|
|
21
30
|
const destFile = path.join(target, file);
|
|
22
31
|
const stat = fs.lstatSync(srcFile);
|
|
23
32
|
|
|
24
|
-
stat.isDirectory()
|
|
33
|
+
stat.isDirectory()
|
|
34
|
+
? copyStorybookPreset(srcFile, destFile)
|
|
35
|
+
: fs.copyFileSync(srcFile, destFile);
|
|
25
36
|
});
|
|
26
37
|
}
|
|
27
38
|
|
|
28
|
-
|
|
39
|
+
async function addStorybookCommands() {
|
|
40
|
+
try {
|
|
41
|
+
const storybookCommands = {
|
|
42
|
+
"sb:dev-full": "STORYBOOK_FULL=1 storybook dev -p 6006 --no-open",
|
|
43
|
+
"sb:dev": "storybook dev -p 6006 --docs --no-open",
|
|
44
|
+
"sb:build": "NO_PWA=1 storybook build --docs",
|
|
45
|
+
"sb:preview": "vite preview --host --outDir=storybook-static",
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const packageJsonPath = path.resolve(__dirname, "../../../package.json");
|
|
49
|
+
const data = await promises.readFile(packageJsonPath, "utf8");
|
|
50
|
+
const packageJson = JSON.parse(data);
|
|
29
51
|
|
|
30
|
-
|
|
31
|
-
const targetFolder = path.join(__dirname, "..", "..", "..", ".storybook");
|
|
52
|
+
packageJson.scripts = { ...packageJson.scripts, ...storybookCommands };
|
|
32
53
|
|
|
33
|
-
|
|
54
|
+
await promises.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), "utf8");
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error("Error:", error);
|
|
57
|
+
}
|
|
58
|
+
}
|