flowershow 0.0.11 → 0.1.1

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.
@@ -1,5 +1,11 @@
1
1
  # flowershow
2
2
 
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 93b7911: Switch from JS to TS.
8
+
3
9
  ## 0.0.11
4
10
 
5
11
  ### Patch Changes
package/dist/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # Flowershow CLI
2
+
3
+ ```bash
4
+ npx flowershow --help
5
+ ```
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "flowershow",
3
+ "version": "0.1.1",
4
+ "description": "Publish your digital garden",
5
+ "bin": {
6
+ "flowershow": "src/bin/cli.js"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/flowershow/flowershow",
11
+ "directory": "packages/cli"
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "keywords": [
17
+ "flowershow",
18
+ "cli"
19
+ ],
20
+ "author": "Rufus Pollock",
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/flowershow/flowershow/issues"
24
+ },
25
+ "homepage": "https://github.com/flowershow/flowershow#readme",
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "dependencies": {
30
+ "chalk": "^5.0.1",
31
+ "commander": "^9.4.0",
32
+ "degit": "^2.8.4",
33
+ "execa": "^6.1.0",
34
+ "inquirer": "^9.1.1",
35
+ "ora": "^6.1.2",
36
+ "universal-analytics": "^0.5.3"
37
+ },
38
+ "type": "module",
39
+ "engines": {
40
+ "node": ">=16.3.0"
41
+ },
42
+ "main": "./src/bin/cli.js",
43
+ "types": "./src/bin/cli.d.ts"
44
+ }
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire } from "node:module";
3
+ const require = createRequire(import.meta.url);
4
+ import { warn, exit, sendEvent } from "../lib/utils/index.js";
5
+ import { Command } from "commander";
6
+ // TODO check current vs required node version (package.json engines)
7
+ // const requiredNodeVersion = require("../package.json").engines.node;
8
+ const { version: cli } = require("../../package.json");
9
+ // simplify importing data from package.json with this line after we no longer want to support node 16
10
+ // import packageJson from "#package.json" assert { type: "json" };
11
+ const { version: node, platform, argv } = process;
12
+ if (platform === "win32") {
13
+ warn("This may not work as expected. You're trying to run Flowreshow CLI on Windows, which is not thoroughly tested. Please submit an issue if you encounter any problems: https://github.com/flowershow/flowershow/issues");
14
+ }
15
+ const [, , cmd, ...args] = argv;
16
+ sendEvent({
17
+ event: "cli-usage",
18
+ action: cmd,
19
+ meta: {
20
+ args,
21
+ cli,
22
+ node,
23
+ platform,
24
+ },
25
+ });
26
+ process.on("uncaughtException", () => {
27
+ sendEvent({
28
+ event: "cli-error",
29
+ action: cmd,
30
+ meta: {
31
+ args,
32
+ cli,
33
+ node,
34
+ platform,
35
+ },
36
+ });
37
+ exit(1);
38
+ });
39
+ // CLI commands
40
+ const program = new Command();
41
+ program
42
+ .description("CLI tool for creating, publishing and upgrading Flowershow apps")
43
+ .version(require("../../package.json").version)
44
+ .usage("<command> [options]");
45
+ // choose template
46
+ program
47
+ .command("install")
48
+ .description("install Flowershow template in target directory")
49
+ .argument("[target-dir]", "Path to the folder where you want Flowershow template to be installed", ".")
50
+ // .option('-t, --template [template-name]', 'Flowershow template name to use', 'default')
51
+ .action(async (targetDir) => {
52
+ const { default: install } = await import("../lib/install.js");
53
+ install(targetDir);
54
+ });
55
+ program
56
+ .command("build")
57
+ .description("build Flowershow website")
58
+ .argument("[project-dir]", "Path to the folder where Flowershow template is installed (root folder of .flowershow)", ".")
59
+ .action(async (projectPath) => {
60
+ const { default: build } = await import("../lib/build.js");
61
+ build(projectPath);
62
+ });
63
+ program
64
+ .command("export")
65
+ .description("build a static Flowershow website")
66
+ .argument("[project-dir]", "Path to the folder where Flowershow template is installed (root folder of .flowershow)", ".")
67
+ .action(async (projectPath) => {
68
+ const { default: buildExport } = await import("../lib/buildExport.js");
69
+ buildExport(projectPath);
70
+ });
71
+ program
72
+ .command("preview")
73
+ .description("preview your Flowershow site")
74
+ .argument("[project-dir]", "Path to the folder where Flowershow template is installed (root folder of .flowershow)", ".")
75
+ .action(async (projectPath) => {
76
+ const { default: preview } = await import("../lib/preview.js");
77
+ preview(projectPath);
78
+ });
79
+ // TBD
80
+ program
81
+ .command("publish")
82
+ .description("publish files or directories")
83
+ .argument("[path]", "path to a file or a directory", ".")
84
+ .option("-g, --glob <pattern>", "glob pattern")
85
+ .action(async () => {
86
+ const { default: publish } = await import("../lib/publish.js");
87
+ publish();
88
+ });
89
+ // TBD
90
+ program
91
+ .command("upgrade")
92
+ .description("upgrade your Flowershow template to the latest version")
93
+ .action(async () => {
94
+ const { default: upgrade } = await import("../lib/upgrade.js");
95
+ upgrade();
96
+ });
97
+ program.parse();
File without changes
@@ -0,0 +1,161 @@
1
+ import { createRequire } from "node:module";
2
+ const require = createRequire(import.meta.url);
3
+ import * as fs from "fs";
4
+ import * as path from "path";
5
+ import chalk from "chalk";
6
+ import degit from "degit";
7
+ import { execa } from "execa";
8
+ import inquirer from "inquirer";
9
+ import { exit, error, log, info, success, logWithSpinner, stopSpinner, isSubdir, } from "./utils/index.js";
10
+ import { FLOWERSHOW_FOLDER_NAME } from "./const.js";
11
+ export default class Installer {
12
+ constructor(context, targetDir) {
13
+ this.context = context;
14
+ this.targetDir = targetDir;
15
+ }
16
+ get templateRepo() {
17
+ // simplify importing data from package.json with this line after we no longer want to support node 16
18
+ // import packageJson from "#package.json" assert { type: "json" };
19
+ const flowershowRepo = require("../../package.json").repository.url.replace("git+", "");
20
+ return `${flowershowRepo}/packages/template`;
21
+ }
22
+ async install() {
23
+ const { context, targetDir, templateRepo } = this;
24
+ const flowershowDir = path.resolve(targetDir, FLOWERSHOW_FOLDER_NAME);
25
+ let existsAction;
26
+ if (fs.existsSync(flowershowDir)) {
27
+ const { action } = await inquirer.prompt([
28
+ {
29
+ name: "action",
30
+ type: "list",
31
+ message: `Flowershow template is already installed in directory ${chalk.magenta(targetDir)}. What do you want to do?:`,
32
+ choices: [
33
+ { name: "Overwrite", value: "overwrite" },
34
+ // { name: 'Merge', value: 'merge' },
35
+ { name: "Cancel", value: null },
36
+ ],
37
+ },
38
+ ]);
39
+ if (!action) {
40
+ exit(0);
41
+ }
42
+ existsAction = action;
43
+ }
44
+ const { contentPath } = await inquirer.prompt([
45
+ {
46
+ name: "contentPath",
47
+ type: "input",
48
+ message: "Path to the folder with your markdown files",
49
+ validate(input) {
50
+ const contentDir = path.resolve(context, input);
51
+ if (!fs.existsSync(contentDir)) {
52
+ error(`Directory ${contentDir} does not exist.`);
53
+ exit(1);
54
+ }
55
+ return true;
56
+ },
57
+ },
58
+ ]);
59
+ const contentDir = path.resolve(context, contentPath);
60
+ // don't allow for installing the template anywhere within the content folder
61
+ // as it will break esbuild
62
+ if (isSubdir(flowershowDir, contentDir)) {
63
+ log(`Provided content directory: ${contentDir}`);
64
+ log(`Provided Flowershow template installation directory: ${flowershowDir}`);
65
+ error(`You can't install the Flowershow template inside your content folder.`);
66
+ exit(1);
67
+ }
68
+ const assetFolderChoices = fs
69
+ .readdirSync(contentDir, { withFileTypes: true })
70
+ .filter((d) => d.isDirectory())
71
+ .map((d) => ({ name: d.name, value: d.name }));
72
+ let assetsFolder;
73
+ if (!assetFolderChoices.length) {
74
+ const { foldersAction } = await inquirer.prompt([
75
+ {
76
+ name: "foldersAction",
77
+ type: "list",
78
+ message: "There are no subfolders in your content folder, that could be used as assets folder",
79
+ choices: [
80
+ { name: "I don't need assets folder", value: "none" },
81
+ { name: "Cancel", value: null },
82
+ ],
83
+ },
84
+ ]);
85
+ assetsFolder = foldersAction;
86
+ }
87
+ else {
88
+ const { assets } = await inquirer.prompt([
89
+ {
90
+ name: "assets",
91
+ type: "list",
92
+ message: "Select a folder with your assets (attachments)",
93
+ choices: [
94
+ ...assetFolderChoices,
95
+ new inquirer.Separator(),
96
+ { name: "I don't need assets folder", value: "none" },
97
+ { name: "Cancel", value: null },
98
+ ],
99
+ },
100
+ ]);
101
+ assetsFolder = assets;
102
+ }
103
+ if (!assetsFolder) {
104
+ exit(0);
105
+ }
106
+ // install flowershow template
107
+ // // if there is no index.md file, create one
108
+ if (!fs.existsSync(`${contentPath}/index.md`)) {
109
+ info(`No index.md file found in ${contentDir}. Flowershow will create one for you.`);
110
+ const homePageContent = "# Welcome to my Flowershow site!";
111
+ // eslint-disable-next-line no-unused-vars
112
+ fs.writeFile(`${contentPath}/index.md`, homePageContent, { flag: "a" }, (err) => { } // eslint-disable-line no-unused-vars
113
+ );
114
+ }
115
+ // // if there is no config.js file, create one
116
+ if (!fs.existsSync(`${contentPath}/config.js`)) {
117
+ info(`No config.js file found in ${contentDir}. Flowershow will create one for you.`);
118
+ fs.writeFile(`${contentPath}/config.js`, "{}", { flag: "a" }, (err) => { } // eslint-disable-line no-unused-vars
119
+ );
120
+ }
121
+ // create flowershow template
122
+ logWithSpinner({
123
+ symbol: "🌷",
124
+ msg: `Creating Flowershow template in ${chalk.magenta(flowershowDir)}`,
125
+ });
126
+ if (existsAction === "overwrite") {
127
+ fs.rmSync(flowershowDir, { recursive: true, force: true });
128
+ }
129
+ try {
130
+ const emitter = degit(templateRepo);
131
+ await emitter.clone(flowershowDir);
132
+ }
133
+ catch (err) {
134
+ error(`Failed to clone Flowershow template into ${flowershowDir}. This may be a problem with Flowershow. Please let us know about it by submitting an issue: https://github.com/flowershow/flowershow/issues.`);
135
+ log(err);
136
+ exit(1);
137
+ }
138
+ // update content and assets symlinks
139
+ const contentSymlinkPath = path.relative(`${flowershowDir}`, contentDir);
140
+ fs.symlinkSync(contentSymlinkPath, `${flowershowDir}/content`);
141
+ if (assetsFolder !== "none") {
142
+ const assetsSymlinkPath = path.relative(`${flowershowDir}/public`, `${contentDir}/${assetsFolder}`);
143
+ fs.symlinkSync(assetsSymlinkPath, `${flowershowDir}/public/${assetsFolder}`);
144
+ }
145
+ // install flowershow dependencies
146
+ logWithSpinner({ symbol: "🌸", msg: `Installing Flowershow dependencies` });
147
+ try {
148
+ const { stdout, stderr } = await execa("npm", ["install"], {
149
+ cwd: flowershowDir,
150
+ });
151
+ log(stdout);
152
+ log(stderr);
153
+ stopSpinner();
154
+ success("Successfuly installed Flowershow!");
155
+ }
156
+ catch (err) {
157
+ error(`Failed to install Flowershow dependencies: ${err.message}`);
158
+ exit(err.exitCode);
159
+ }
160
+ }
161
+ }
@@ -0,0 +1,15 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { execa } from "execa";
4
+ import { exit, error } from "./utils/index.js";
5
+ import { FLOWERSHOW_FOLDER_NAME } from "./const.js";
6
+ export default async function build(dir) {
7
+ const flowershowDir = path.resolve(dir, FLOWERSHOW_FOLDER_NAME);
8
+ // check if flowershow is installed
9
+ if (!fs.existsSync(flowershowDir)) {
10
+ error(`Directory ${flowershowDir} does not exist.`);
11
+ exit(1);
12
+ }
13
+ const subprocess = execa("npm", ["run", "build"], { cwd: flowershowDir });
14
+ subprocess.stdout.pipe(process.stdout);
15
+ }
@@ -0,0 +1,8 @@
1
+ import path from "path";
2
+ import { execa } from "execa";
3
+ import { FLOWERSHOW_FOLDER_NAME } from "./const.js";
4
+ export default async function buildExport(dir) {
5
+ const flowershowDir = path.resolve(dir, FLOWERSHOW_FOLDER_NAME);
6
+ const subprocess = execa("npm", ["run", "export"], { cwd: flowershowDir });
7
+ subprocess.stdout.pipe(process.stdout);
8
+ }
File without changes
@@ -0,0 +1,28 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import inquirer from "inquirer";
4
+ import Installer from "./Installer.js";
5
+ import { error, exit } from "./utils/index.js";
6
+ export default async function install(dir) {
7
+ const currentDir = process.cwd();
8
+ const inCurrentDir = dir === ".";
9
+ if (inCurrentDir) {
10
+ const { ok } = await inquirer.prompt([
11
+ {
12
+ name: "ok",
13
+ type: "confirm",
14
+ message: "Create Flowershow project in current directory?",
15
+ },
16
+ ]);
17
+ if (!ok) {
18
+ return;
19
+ }
20
+ }
21
+ const targetDir = path.resolve(dir);
22
+ if (!fs.existsSync(targetDir)) {
23
+ error(`Directory ${targetDir} does not exist.`);
24
+ exit(1);
25
+ }
26
+ const installer = new Installer(currentDir, targetDir);
27
+ await installer.install();
28
+ }
@@ -0,0 +1,15 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { execa } from "execa";
4
+ import { exit, error } from "./utils/index.js";
5
+ import { FLOWERSHOW_FOLDER_NAME } from "./const.js";
6
+ export default async function preview(dir) {
7
+ const flowershowDir = path.resolve(dir, FLOWERSHOW_FOLDER_NAME);
8
+ // check if flowershow is installed
9
+ if (!fs.existsSync(flowershowDir)) {
10
+ error(`Directory ${flowershowDir} does not exist.`);
11
+ exit(1);
12
+ }
13
+ const subprocess = execa("npm", ["run", "dev"], { cwd: flowershowDir });
14
+ subprocess.stdout.pipe(process.stdout);
15
+ }
@@ -1,14 +1,8 @@
1
1
  import chalk from "chalk";
2
-
3
2
  const log = console.log;
4
-
5
3
  export default function publish() {
6
- log(chalk.redBright.bold("Command under construction...\n"));
7
- log(
8
- chalk.blue(
9
- "Check " +
4
+ log(chalk.redBright.bold("Command under construction...\n"));
5
+ log(chalk.blue("Check " +
10
6
  chalk.green.underline("https://flowershow.app") +
11
- " to learn more about Flowershow development stage and subscribe to get notified when it's ready!"
12
- )
13
- );
7
+ " to learn more about Flowershow development stage and subscribe to get notified when it's ready!"));
14
8
  }
@@ -1,14 +1,8 @@
1
1
  import chalk from "chalk";
2
-
3
2
  const log = console.log;
4
-
5
3
  export default function upgrade() {
6
- log(chalk.redBright.bold("Command under construction...\n"));
7
- log(
8
- chalk.blue(
9
- "Check " +
4
+ log(chalk.redBright.bold("Command under construction...\n"));
5
+ log(chalk.blue("Check " +
10
6
  chalk.green.underline("https://flowershow.app") +
11
- " to learn more about Flowershow development stage and subscribe to get notified when it's ready!"
12
- )
13
- );
7
+ " to learn more about Flowershow development stage and subscribe to get notified when it's ready!"));
14
8
  }
@@ -1,3 +1,3 @@
1
1
  export const exit = (code) => {
2
- process.exit(code);
2
+ process.exit(code);
3
3
  };
@@ -2,9 +2,4 @@ export { error, info, log, success, warn } from "./logger.js";
2
2
  export { exit } from "./exit.js";
3
3
  export { isSubdir } from "./isSubdir.js";
4
4
  export { sendEvent } from "./sendEvent.js";
5
- export {
6
- logWithSpinner,
7
- stopSpinner,
8
- pauseSpinner,
9
- resumeSpinner,
10
- } from "./spinner.js";
5
+ export { logWithSpinner, stopSpinner, pauseSpinner, resumeSpinner, } from "./spinner.js";
@@ -0,0 +1,6 @@
1
+ import path from "path";
2
+ // test if dir is a subdirectory of or same as ofDir
3
+ export function isSubdir(dir, ofDir) {
4
+ const relative = path.relative(ofDir, dir);
5
+ return relative && !relative.startsWith("..") && !path.isAbsolute(relative);
6
+ }
@@ -0,0 +1,19 @@
1
+ import chalk from "chalk";
2
+ export const log = (msg = "") => {
3
+ console.log(msg);
4
+ };
5
+ export const info = (msg) => {
6
+ console.log(`${chalk.bgBlueBright.black(" INFO ")} ${msg}`);
7
+ };
8
+ export const error = (msg) => {
9
+ console.error(`\n${chalk.bgRed(" ERROR ")} ${chalk.red(msg)}`);
10
+ if (msg instanceof Error) {
11
+ console.error(msg.stack);
12
+ }
13
+ };
14
+ export const success = (msg) => {
15
+ console.log(`${chalk.blue("🎊")} ${msg}`);
16
+ };
17
+ export const warn = (msg) => {
18
+ console.log(`${chalk.red("⚠")} ${msg}`);
19
+ };
@@ -0,0 +1,5 @@
1
+ import ua from "universal-analytics";
2
+ const visitor = ua("UA-235099461-1");
3
+ export function sendEvent({ event, action, meta, }) {
4
+ visitor.event(event, action, JSON.stringify(meta)).send();
5
+ }
@@ -0,0 +1,49 @@
1
+ import ora from "ora";
2
+ import chalk from "chalk";
3
+ const spinner = ora({ color: "magenta" });
4
+ let lastMsg = null;
5
+ let isPaused = false;
6
+ export const logWithSpinner = ({ msg, symbol }) => {
7
+ if (!symbol) {
8
+ symbol = chalk.green("✔");
9
+ }
10
+ if (lastMsg) {
11
+ spinner.stopAndPersist({
12
+ symbol: lastMsg.symbol,
13
+ text: lastMsg.text,
14
+ });
15
+ }
16
+ spinner.text = " " + msg;
17
+ lastMsg = {
18
+ symbol: symbol + " ",
19
+ text: msg,
20
+ };
21
+ spinner.start();
22
+ };
23
+ export const stopSpinner = () => {
24
+ if (!spinner.isSpinning) {
25
+ return;
26
+ }
27
+ if (lastMsg) {
28
+ spinner.stopAndPersist({
29
+ symbol: lastMsg.symbol,
30
+ text: lastMsg.text,
31
+ });
32
+ }
33
+ else {
34
+ spinner.stop();
35
+ }
36
+ lastMsg = null;
37
+ };
38
+ export const pauseSpinner = () => {
39
+ if (spinner.isSpinning) {
40
+ spinner.stop();
41
+ isPaused = true;
42
+ }
43
+ };
44
+ export const resumeSpinner = () => {
45
+ if (isPaused) {
46
+ spinner.start();
47
+ isPaused = false;
48
+ }
49
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flowershow",
3
- "version": "0.0.11",
3
+ "version": "0.1.1",
4
4
  "description": "Publish your digital garden",
5
5
  "bin": {
6
6
  "flowershow": "src/bin/cli.js"
@@ -10,6 +10,9 @@
10
10
  "url": "git+https://github.com/flowershow/flowershow",
11
11
  "directory": "packages/cli"
12
12
  },
13
+ "files": [
14
+ "dist"
15
+ ],
13
16
  "keywords": [
14
17
  "flowershow",
15
18
  "cli"
@@ -34,6 +37,6 @@
34
37
  },
35
38
  "type": "module",
36
39
  "engines": {
37
- "node": ">=12.2.0 || >=14.13.0"
40
+ "node": ">=16.3.0"
38
41
  }
39
42
  }
package/.babelrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "presets": [["@nrwl/web/babel", { "useBuiltIns": "usage" }]]
3
- }
package/.eslintrc.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "extends": ["../../.eslintrc.json"]
3
- }
package/jest.config.js DELETED
@@ -1,16 +0,0 @@
1
- /* eslint-disable */
2
- export default {
3
- displayName: "cli",
4
- preset: "../../jest.preset.js",
5
- globals: {
6
- "ts-jest": {
7
- tsconfig: "<rootDir>/tsconfig.spec.json",
8
- },
9
- },
10
- testEnvironment: "node",
11
- transform: {
12
- "^.+\\.[tj]sx?$": "ts-jest",
13
- },
14
- moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
15
- coverageDirectory: "../../coverage/packages/cli",
16
- };
package/project.json DELETED
@@ -1,41 +0,0 @@
1
- {
2
- "name": "cli",
3
- "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "packages/cli/src",
5
- "projectType": "library",
6
- "targets": {
7
- "lint": {
8
- "executor": "@nrwl/linter:eslint",
9
- "options": {
10
- "fix": true,
11
- "lintFilePatterns": ["packages/cli/**/*.js"]
12
- }
13
- },
14
- "test": {
15
- "executor": "@nrwl/jest:jest",
16
- "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
17
- "options": {
18
- "jestConfig": "packages/cli/jest.config.js",
19
- "passWithNoTests": true
20
- }
21
- },
22
- "e2e": {
23
- "executor": "nx:run-commands",
24
- "options": {
25
- "commands": [
26
- "mkdir -p coverage/packages/cli-e2e",
27
- "packages/cli/src/e2e/bats/bin/bats packages/cli/src/e2e/test.bats -p --report-formatter pretty -o coverage/packages/cli-e2e --verbose-run"
28
- ]
29
- },
30
- "parallel": false,
31
- "inputs": [
32
- "default",
33
- "^production",
34
- "{projectRoot}/src/e2e/.env",
35
- { "env": "NETLIFY_TOKEN" }
36
- ],
37
- "outputs": ["coverage/packages/cli-e2e"]
38
- }
39
- },
40
- "tags": []
41
- }
package/src/bin/cli.js DELETED
@@ -1,130 +0,0 @@
1
- #!/usr/bin/env node
2
- import { createRequire } from "node:module";
3
- const require = createRequire(import.meta.url);
4
- import { warn, exit, sendEvent } from "../lib/utils/index.js";
5
- import { Command } from "commander";
6
-
7
- // TODO check current vs required node version (package.json engines)
8
- // const requiredNodeVersion = require("../package.json").engines.node;
9
-
10
- const { version: cli } = require("../../package.json");
11
- const { version: node, platform, argv } = process;
12
-
13
- if (platform === "win32") {
14
- warn(
15
- "This may not work as expected. You're trying to run Flowreshow CLI on Windows, which is not thoroughly tested. Please submit an issue if you encounter any problems: https://github.com/flowershow/flowershow/issues"
16
- );
17
- }
18
-
19
- const [, , cmd, ...args] = argv;
20
- sendEvent({
21
- event: "cli-usage",
22
- action: cmd,
23
- meta: {
24
- args,
25
- cli,
26
- node,
27
- platform,
28
- },
29
- });
30
-
31
- process.on("uncaughtException", () => {
32
- sendEvent({
33
- event: "cli-error",
34
- action: cmd,
35
- meta: {
36
- args,
37
- cli,
38
- node,
39
- platform,
40
- },
41
- });
42
- exit(1);
43
- });
44
-
45
- // CLI commands
46
-
47
- const program = new Command();
48
-
49
- program
50
- .description(
51
- "CLI tool for creating, publishing and upgrading Flowershow apps"
52
- )
53
- .version(require("../../package.json").version)
54
- .usage("<command> [options]");
55
-
56
- // choose template
57
- program
58
- .command("install")
59
- .description("install Flowershow template in target directory")
60
- .argument(
61
- "[target-dir]",
62
- "Path to the folder where you want Flowershow template to be installed",
63
- "."
64
- )
65
- // .option('-t, --template [template-name]', 'Flowershow template name to use', 'default')
66
- .action(async (targetDir, options) => {
67
- const { default: install } = await import("../lib/install.js");
68
- install(targetDir, options);
69
- });
70
-
71
- program
72
- .command("build")
73
- .description("build Flowershow website")
74
- .argument(
75
- "[project-dir]",
76
- "Path to the folder where Flowershow template is installed (root folder of .flowershow)",
77
- "."
78
- )
79
- .action(async (projectPath) => {
80
- const { default: build } = await import("../lib/build.js");
81
- build(projectPath);
82
- });
83
-
84
- program
85
- .command("export")
86
- .description("build a static Flowershow website")
87
- .argument(
88
- "[project-dir]",
89
- "Path to the folder where Flowershow template is installed (root folder of .flowershow)",
90
- "."
91
- )
92
- .action(async (projectPath) => {
93
- const { default: buildExport } = await import("../lib/buildExport.js");
94
- buildExport(projectPath);
95
- });
96
-
97
- program
98
- .command("preview")
99
- .description("preview your Flowershow site")
100
- .argument(
101
- "[project-dir]",
102
- "Path to the folder where Flowershow template is installed (root folder of .flowershow)",
103
- "."
104
- )
105
- .action(async (projectPath) => {
106
- const { default: preview } = await import("../lib/preview.js");
107
- preview(projectPath);
108
- });
109
-
110
- // TBD
111
- program
112
- .command("publish")
113
- .description("publish files or directories")
114
- .argument("[path]", "path to a file or a directory", ".")
115
- .option("-g, --glob <pattern>", "glob pattern")
116
- .action(async () => {
117
- const { default: publish } = await import("../lib/publish.js");
118
- publish();
119
- });
120
-
121
- // TBD
122
- program
123
- .command("upgrade")
124
- .description("upgrade your Flowershow template to the latest version")
125
- .action(async () => {
126
- const { default: upgrade } = await import("../lib/upgrade.js");
127
- upgrade();
128
- });
129
-
130
- program.parse();
@@ -1,219 +0,0 @@
1
- import { createRequire } from "node:module";
2
- const require = createRequire(import.meta.url);
3
-
4
- import fs from "fs";
5
- import path from "path";
6
- import chalk from "chalk";
7
- import degit from "degit";
8
- import { execa } from "execa";
9
- import inquirer from "inquirer";
10
-
11
- import {
12
- exit,
13
- error,
14
- log,
15
- info,
16
- success,
17
- logWithSpinner,
18
- stopSpinner,
19
- isSubdir,
20
- } from "./utils/index.js";
21
-
22
- import { FLOWERSHOW_FOLDER_NAME } from "./const.js";
23
-
24
- export default class Installer {
25
- constructor(context, targetDir) {
26
- this.context = context;
27
- this.targetDir = targetDir;
28
- }
29
-
30
- get templateRepo() {
31
- const flowershowRepo = require("../../package.json").repository.url.replace(
32
- "git+",
33
- ""
34
- );
35
- return `${flowershowRepo}/packages/template`;
36
- }
37
-
38
- async install() {
39
- const { context, targetDir, templateRepo } = this;
40
- const flowershowDir = path.resolve(targetDir, FLOWERSHOW_FOLDER_NAME);
41
-
42
- let existsAction;
43
- if (fs.existsSync(flowershowDir)) {
44
- let { action } = await inquirer.prompt([
45
- {
46
- name: "action",
47
- type: "list",
48
- message: `Flowershow template is already installed in directory ${chalk.magenta(
49
- targetDir
50
- )}. What do you want to do?:`,
51
- choices: [
52
- { name: "Overwrite", value: "overwrite" },
53
- // { name: 'Merge', value: 'merge' },
54
- { name: "Cancel", value: null },
55
- ],
56
- },
57
- ]);
58
-
59
- if (!action) {
60
- exit(0);
61
- }
62
- existsAction = action;
63
- }
64
-
65
- let { contentPath } = await inquirer.prompt([
66
- {
67
- name: "contentPath",
68
- type: "input",
69
- message: "Path to the folder with your markdown files",
70
- validate(input) {
71
- const contentDir = path.resolve(context, input);
72
- if (!fs.existsSync(contentDir)) {
73
- error(`Directory ${contentDir} does not exist.`);
74
- exit(1);
75
- }
76
- return true;
77
- },
78
- },
79
- ]);
80
-
81
- const contentDir = path.resolve(context, contentPath);
82
-
83
- // don't allow for installing the template anywhere within the content folder
84
- // as it will break esbuild
85
- if (isSubdir(flowershowDir, contentDir)) {
86
- log(`Provided content directory: ${contentDir}`);
87
- log(
88
- `Provided Flowershow template installation directory: ${flowershowDir}`
89
- );
90
- error(
91
- `You can't install the Flowershow template inside your content folder.`
92
- );
93
- exit(1);
94
- }
95
-
96
- const assetFolderChoices = fs
97
- .readdirSync(contentDir, { withFileTypes: true })
98
- .filter((d) => d.isDirectory())
99
- .map((d) => ({ name: d.name, value: d.name }));
100
-
101
- let assetsFolder;
102
-
103
- if (!assetFolderChoices.length) {
104
- const { foldersAction } = await inquirer.prompt([
105
- {
106
- name: "foldersAction",
107
- type: "list",
108
- message:
109
- "There are no subfolders in your content folder, that could be used as assets folder",
110
- choices: [
111
- { name: "I don't need assets folder", value: "none" },
112
- { name: "Cancel", value: null },
113
- ],
114
- },
115
- ]);
116
-
117
- assetsFolder = foldersAction;
118
- } else {
119
- const { assets } = await inquirer.prompt([
120
- {
121
- name: "assets",
122
- type: "list",
123
- message: "Select a folder with your assets (attachments)",
124
- choices: [
125
- ...assetFolderChoices,
126
- new inquirer.Separator(),
127
- { name: "I don't need assets folder", value: "none" },
128
- { name: "Cancel", value: null },
129
- ],
130
- },
131
- ]);
132
-
133
- assetsFolder = assets;
134
- }
135
-
136
- if (!assetsFolder) {
137
- exit(0);
138
- }
139
-
140
- // install flowershow template
141
- // // if there is no index.md file, create one
142
- if (!fs.existsSync(`${contentPath}/index.md`)) {
143
- info(
144
- `No index.md file found in ${contentDir}. Flowershow will create one for you.`
145
- );
146
- const homePageContent = "# Welcome to my Flowershow site!";
147
- // eslint-disable-next-line no-unused-vars
148
- fs.writeFile(
149
- `${contentPath}/index.md`,
150
- homePageContent,
151
- { flag: "a" },
152
- (err) => {} // eslint-disable-line no-unused-vars
153
- );
154
- }
155
-
156
- // // if there is no config.js file, create one
157
- if (!fs.existsSync(`${contentPath}/config.js`)) {
158
- info(
159
- `No config.js file found in ${contentDir}. Flowershow will create one for you.`
160
- );
161
- fs.writeFile(
162
- `${contentPath}/config.js`,
163
- "{}",
164
- { flag: "a" },
165
- (err) => {} // eslint-disable-line no-unused-vars
166
- );
167
- }
168
-
169
- // create flowershow template
170
- logWithSpinner({
171
- symbol: "🌷",
172
- msg: `Creating Flowershow template in ${chalk.magenta(flowershowDir)}`,
173
- });
174
-
175
- if (existsAction === "overwrite") {
176
- fs.rmSync(flowershowDir, { recursive: true, force: true });
177
- }
178
-
179
- try {
180
- const emitter = degit(templateRepo);
181
- await emitter.clone(flowershowDir);
182
- } catch {
183
- error(
184
- `Failed to clone Flowershow template into ${flowershowDir}. This may be a problem with Flowershow. Please let us know about it by submitting an issue: https://github.com/flowershow/flowershow/issues.`
185
- );
186
- exit(1);
187
- }
188
-
189
- // update content and assets symlinks
190
- const contentSymlinkPath = path.relative(`${flowershowDir}`, contentDir);
191
- fs.symlinkSync(contentSymlinkPath, `${flowershowDir}/content`);
192
-
193
- if (assetsFolder !== "none") {
194
- const assetsSymlinkPath = path.relative(
195
- `${flowershowDir}/public`,
196
- `${contentDir}/${assetsFolder}`
197
- );
198
- fs.symlinkSync(
199
- assetsSymlinkPath,
200
- `${flowershowDir}/public/${assetsFolder}`
201
- );
202
- }
203
-
204
- // install flowershow dependencies
205
- logWithSpinner({ symbol: "🌸", msg: `Installing Flowershow dependencies` });
206
- try {
207
- const { stdout, stderr } = await execa("npm", ["install"], {
208
- cwd: flowershowDir,
209
- });
210
- log(stdout);
211
- log(stderr);
212
- stopSpinner();
213
- success("Successfuly installed Flowershow!");
214
- } catch (err) {
215
- error(`Failed to install Flowershow dependencies: ${err.message}`);
216
- exit(err.exitCode);
217
- }
218
- }
219
- }
package/src/lib/build.js DELETED
@@ -1,19 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { execa } from "execa";
4
-
5
- import { exit, error } from "./utils/index.js";
6
- import { FLOWERSHOW_FOLDER_NAME } from "./const.js";
7
-
8
- export default async function build(dir) {
9
- const flowershowDir = path.resolve(dir, FLOWERSHOW_FOLDER_NAME);
10
-
11
- // check if flowershow is installed
12
- if (!fs.existsSync(flowershowDir)) {
13
- error(`Directory ${flowershowDir} does not exist.`);
14
- exit(1);
15
- }
16
- const subprocess = execa("npm", ["run", "build"], { cwd: flowershowDir });
17
-
18
- subprocess.stdout.pipe(process.stdout);
19
- }
@@ -1,12 +0,0 @@
1
- import path from "path";
2
- import { execa } from "execa";
3
-
4
- import { FLOWERSHOW_FOLDER_NAME } from "./const.js";
5
-
6
- export default async function buildExport(dir) {
7
- const flowershowDir = path.resolve(dir, FLOWERSHOW_FOLDER_NAME);
8
-
9
- const subprocess = execa("npm", ["run", "export"], { cwd: flowershowDir });
10
-
11
- subprocess.stdout.pipe(process.stdout);
12
- }
@@ -1,34 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import inquirer from "inquirer";
4
-
5
- import Installer from "./Installer.js";
6
- import { error, exit } from "./utils/index.js";
7
-
8
- export default async function install(dir, options) {
9
- const currentDir = process.cwd();
10
- const inCurrentDir = dir === ".";
11
-
12
- if (inCurrentDir) {
13
- const { ok } = await inquirer.prompt([
14
- {
15
- name: "ok",
16
- type: "confirm",
17
- message: "Create Flowershow project in current directory?",
18
- },
19
- ]);
20
- if (!ok) {
21
- return;
22
- }
23
- }
24
-
25
- const targetDir = path.resolve(dir);
26
-
27
- if (!fs.existsSync(targetDir)) {
28
- error(`Directory ${targetDir} does not exist.`);
29
- exit(1);
30
- }
31
-
32
- const installer = new Installer(currentDir, targetDir);
33
- await installer.install(options);
34
- }
@@ -1,20 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { execa } from "execa";
4
-
5
- import { exit, error } from "./utils/index.js";
6
-
7
- import { FLOWERSHOW_FOLDER_NAME } from "./const.js";
8
-
9
- export default async function preview(dir) {
10
- const flowershowDir = path.resolve(dir, FLOWERSHOW_FOLDER_NAME);
11
-
12
- // check if flowershow is installed
13
- if (!fs.existsSync(flowershowDir)) {
14
- error(`Directory ${flowershowDir} does not exist.`);
15
- exit(1);
16
- }
17
- const subprocess = execa("npm", ["run", "dev"], { cwd: flowershowDir });
18
-
19
- subprocess.stdout.pipe(process.stdout);
20
- }
@@ -1,7 +0,0 @@
1
- import path from "path";
2
-
3
- // test if dir is a subdirectory of or same as ofDir
4
- export function isSubdir(dir, ofDir) {
5
- const relative = path.relative(ofDir, dir);
6
- return relative && !relative.startsWith("..") && !path.isAbsolute(relative);
7
- }
@@ -1,24 +0,0 @@
1
- import chalk from "chalk";
2
-
3
- export const log = (msg = "") => {
4
- console.log(msg);
5
- };
6
-
7
- export const info = (msg) => {
8
- console.log(`${chalk.bgBlueBright.black(" INFO ")} ${msg}`);
9
- };
10
-
11
- export const error = (msg) => {
12
- console.error(`\n${chalk.bgRed(" ERROR ")} ${chalk.red(msg)}`);
13
- if (msg instanceof Error) {
14
- console.error(msg.stack);
15
- }
16
- };
17
-
18
- export const success = (msg) => {
19
- console.log(`${chalk.blue("🎊")} ${msg}`);
20
- };
21
-
22
- export const warn = (msg) => {
23
- console.log(`${chalk.red("⚠")} ${msg}`);
24
- };
@@ -1,7 +0,0 @@
1
- import ua from "universal-analytics";
2
-
3
- const visitor = ua("UA-235099461-1");
4
-
5
- export function sendEvent({ event, action, meta }) {
6
- visitor.event(event, action, JSON.stringify(meta)).send();
7
- }
@@ -1,54 +0,0 @@
1
- import ora from "ora";
2
- import chalk from "chalk";
3
-
4
- const spinner = ora({ color: "magenta" });
5
- let lastMsg = null;
6
- let isPaused = false;
7
-
8
- export const logWithSpinner = ({ msg, symbol }) => {
9
- if (!symbol) {
10
- symbol = chalk.green("✔");
11
- }
12
- if (lastMsg) {
13
- spinner.stopAndPersist({
14
- symbol: lastMsg.symbol,
15
- text: lastMsg.text,
16
- });
17
- }
18
- spinner.text = " " + msg;
19
- lastMsg = {
20
- symbol: symbol + " ",
21
- text: msg,
22
- };
23
- spinner.start();
24
- };
25
-
26
- export const stopSpinner = () => {
27
- if (!spinner.isSpinning) {
28
- return;
29
- }
30
-
31
- if (lastMsg) {
32
- spinner.stopAndPersist({
33
- symbol: lastMsg.symbol,
34
- text: lastMsg.text,
35
- });
36
- } else {
37
- spinner.stop();
38
- }
39
- lastMsg = null;
40
- };
41
-
42
- export const pauseSpinner = () => {
43
- if (spinner.isSpinning) {
44
- spinner.stop();
45
- isPaused = true;
46
- }
47
- };
48
-
49
- export const resumeSpinner = () => {
50
- if (isPaused) {
51
- spinner.start();
52
- isPaused = false;
53
- }
54
- };
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "allowJs": true
5
- },
6
- "files": [],
7
- "include": [],
8
- "references": [
9
- {
10
- "path": "./tsconfig.lib.json"
11
- },
12
- {
13
- "path": "./tsconfig.spec.json"
14
- }
15
- ]
16
- }
package/tsconfig.lib.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "module": "commonjs",
5
- "outDir": "../../dist/out-tsc",
6
- "declaration": true,
7
- "types": ["node"]
8
- },
9
- "exclude": [
10
- "jest.config.ts",
11
- "**/*.spec.ts",
12
- "**/*.test.ts",
13
- "**/*.spec.js",
14
- "**/*.test.js"
15
- ],
16
- "include": ["**/*.ts", "**/*.js"]
17
- }
@@ -1,20 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "module": "commonjs",
6
- "types": ["jest", "node"]
7
- },
8
- "include": [
9
- "jest.config.ts",
10
- "**/*.test.ts",
11
- "**/*.spec.ts",
12
- "**/*.test.tsx",
13
- "**/*.spec.tsx",
14
- "**/*.test.js",
15
- "**/*.spec.js",
16
- "**/*.test.jsx",
17
- "**/*.spec.jsx",
18
- "**/*.d.ts"
19
- ]
20
- }