flowershow 0.0.5 → 0.0.7

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/.babelrc ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "presets": [["@nrwl/web/babel", { "useBuiltIns": "usage" }]]
3
+ }
package/.eslintrc.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": ["../../.eslintrc.json"]
3
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Life Itself
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/jest.config.js ADDED
@@ -0,0 +1,16 @@
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/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "flowershow",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "Publish your digital garden",
5
5
  "bin": {
6
- "flowershow": "bin/flowershow.js"
6
+ "flowershow": "src/bin/cli.js"
7
7
  },
8
8
  "repository": {
9
9
  "type": "git",
@@ -14,9 +14,6 @@
14
14
  "flowershow",
15
15
  "cli"
16
16
  ],
17
- "scripts": {
18
- "test": "./e2e/bats/bin/bats ./e2e/test.bats --verbose-run"
19
- },
20
17
  "author": "Rufus Pollock",
21
18
  "license": "MIT",
22
19
  "bugs": {
@@ -32,11 +29,10 @@
32
29
  "degit": "^2.8.4",
33
30
  "execa": "^6.1.0",
34
31
  "inquirer": "^9.1.1",
35
- "ora": "^6.1.2",
36
- "validate-npm-package-name": "^4.0.0"
32
+ "ora": "^6.1.2"
37
33
  },
38
34
  "type": "module",
39
35
  "engines": {
40
36
  "node": ">=12.2.0 || >=14.13.0"
41
37
  }
42
- }
38
+ }
package/project.json ADDED
@@ -0,0 +1,42 @@
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
+ "implicitDependencies": ["template"]
42
+ }
package/src/bin/cli.js ADDED
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire } from "node:module";
3
+ const require = createRequire(import.meta.url);
4
+ import { warn } from "../lib/utils/index.js";
5
+
6
+ import os from "os";
7
+
8
+ if (os.platform() === "win32") {
9
+ warn(
10
+ "This may not work as expected. You're trying to run Flowreshow CLI on Windows, which is not supported yet..."
11
+ );
12
+ }
13
+
14
+ // TODO check current vs required node version (package.json engines)
15
+ // const requiredNodeVersion = require("../package.json").engines.node;
16
+
17
+ import { Command } from "commander";
18
+
19
+ const program = new Command();
20
+
21
+ program
22
+ .description(
23
+ "CLI tool for creating, publishing and upgrading Flowershow apps"
24
+ )
25
+ .version(require("../../package.json").version)
26
+ .usage("<command> [options]");
27
+
28
+ // choose template
29
+ program
30
+ .command("install")
31
+ .description("install Flowershow template in target directory")
32
+ .argument(
33
+ "[target-dir]",
34
+ "Path to the folder where you want Flowershow template to be installed",
35
+ "."
36
+ )
37
+ // .option('-t, --template [template-name]', 'Flowershow template name to use', 'default')
38
+ .action(async (targetDir, options) => {
39
+ const { default: install } = await import("../lib/install.js");
40
+ install(targetDir, options);
41
+ });
42
+
43
+ program
44
+ .command("build")
45
+ .description("build Flowershow website")
46
+ .argument(
47
+ "[project-dir]",
48
+ "Path to the folder where Flowershow template is installed (root folder of .flowershow)",
49
+ "."
50
+ )
51
+ .action(async (projectPath) => {
52
+ const { default: build } = await import("../lib/build.js");
53
+ build(projectPath);
54
+ });
55
+
56
+ program
57
+ .command("build-static")
58
+ .description("build static Flowershow website")
59
+ .argument(
60
+ "[project-dir]",
61
+ "Path to the folder where Flowershow template is installed (root folder of .flowershow)",
62
+ "."
63
+ )
64
+ .action(async (projectPath) => {
65
+ const { default: buildStatic } = await import("../lib/buildStatic.js");
66
+ buildStatic(projectPath);
67
+ });
68
+
69
+ program
70
+ .command("preview")
71
+ .description("preview your Flowershow site")
72
+ .argument(
73
+ "[project-dir]",
74
+ "Path to the folder where Flowershow template is installed (root folder of .flowershow)",
75
+ "."
76
+ )
77
+ .action(async (projectPath) => {
78
+ const { default: preview } = await import("../lib/preview.js");
79
+ preview(projectPath);
80
+ });
81
+
82
+ // TBD
83
+ program
84
+ .command("publish")
85
+ .description("publish files or directories")
86
+ .argument("[path]", "path to a file or a directory", ".")
87
+ .option("-g, --glob <pattern>", "glob pattern")
88
+ .action(async () => {
89
+ const { default: publish } = await import("../lib/publish.js");
90
+ publish();
91
+ });
92
+
93
+ // TBD
94
+ program
95
+ .command("upgrade")
96
+ .description("upgrade your Flowershow template to the latest version")
97
+ .action(async () => {
98
+ const { default: upgrade } = await import("../lib/upgrade.js");
99
+ upgrade();
100
+ });
101
+
102
+ program.parse();
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ // export * from './lib/cli';
@@ -0,0 +1,198 @@
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
+ success,
16
+ logWithSpinner,
17
+ stopSpinner,
18
+ } from "./utils/index.js";
19
+
20
+ import { FLOWERSHOW_FOLDER_NAME } from "./const.js";
21
+
22
+ export default class Creator {
23
+ constructor(context, targetDir) {
24
+ this.context = context;
25
+ this.targetDir = targetDir;
26
+ }
27
+
28
+ get templateRepo() {
29
+ const flowershowRepo = require("../../package.json").repository.url.replace(
30
+ "git+",
31
+ ""
32
+ );
33
+ return `${flowershowRepo}/packages/template`;
34
+ }
35
+
36
+ async install() {
37
+ const { context, targetDir, templateRepo } = this;
38
+ const flowershowDir = path.resolve(targetDir, FLOWERSHOW_FOLDER_NAME);
39
+
40
+ let existsAction;
41
+ if (fs.existsSync(flowershowDir)) {
42
+ let { action } = await inquirer.prompt([
43
+ {
44
+ name: "action",
45
+ type: "list",
46
+ message: `Flowershow template is already installed in directory ${chalk.magenta(
47
+ targetDir
48
+ )}. What do you want to do?:`,
49
+ choices: [
50
+ { name: "Overwrite", value: "overwrite" },
51
+ // { name: 'Merge', value: 'merge' },
52
+ { name: "Cancel", value: null },
53
+ ],
54
+ },
55
+ ]);
56
+
57
+ if (!action) {
58
+ exit(0);
59
+ }
60
+ existsAction = action;
61
+ }
62
+
63
+ let { contentPath } = await inquirer.prompt([
64
+ {
65
+ name: "contentPath",
66
+ type: "input",
67
+ message: "Path to the folder with your markdown files",
68
+ validate(input) {
69
+ const contentDir = path.resolve(context, input);
70
+ if (!fs.existsSync(contentDir)) {
71
+ error(`Directory ${contentDir} does not exist.`);
72
+ exit(1);
73
+ }
74
+ return true;
75
+ },
76
+ },
77
+ ]);
78
+
79
+ const contentDir = path.resolve(context, contentPath);
80
+ const assetFolderChoices = fs
81
+ .readdirSync(contentDir, { withFileTypes: true })
82
+ .filter((d) => d.isDirectory())
83
+ .map((d) => ({ name: d.name, value: d.name }));
84
+
85
+ let assetsFolder = "none";
86
+
87
+ if (!assetFolderChoices.length) {
88
+ const { foldersAction } = await inquirer.prompt([
89
+ {
90
+ name: "foldersAction",
91
+ type: "list",
92
+ message:
93
+ "There are no subfolders in your content folder, that could be used as assets folder",
94
+ choices: [
95
+ { name: "I don't need assets folder", value: "none" },
96
+ { name: "Cancel", value: null },
97
+ ],
98
+ },
99
+ ]);
100
+
101
+ assetsFolder = foldersAction;
102
+ } else {
103
+ const { assets } = await inquirer.prompt([
104
+ {
105
+ name: "assets",
106
+ type: "list",
107
+ message: "Select a folder with your assets (attachments)",
108
+ choices: [
109
+ ...assetFolderChoices,
110
+ new inquirer.Separator(),
111
+ { name: "I don't need assets folder", value: "none" },
112
+ { name: "Cancel", value: null },
113
+ ],
114
+ },
115
+ ]);
116
+
117
+ assetsFolder = assets;
118
+ }
119
+
120
+ if (!assetsFolder) {
121
+ exit(0);
122
+ }
123
+
124
+ // install flowershow template
125
+ logWithSpinner({
126
+ symbol: "🌷",
127
+ msg: `Installing Flowershow template in ${chalk.magenta(
128
+ flowershowDir
129
+ )}...`,
130
+ });
131
+
132
+ if (existsAction === "overwrite") {
133
+ fs.rmSync(flowershowDir, { recursive: true, force: true });
134
+ }
135
+
136
+ try {
137
+ const emitter = degit(templateRepo);
138
+ await emitter.clone(flowershowDir);
139
+ } catch {
140
+ error(`Failed to install Flowershow template in ${flowershowDir}.`);
141
+ exit(1);
142
+ }
143
+
144
+ // update content and assets symlinks
145
+ fs.unlinkSync(`${flowershowDir}/content`);
146
+ fs.symlinkSync(contentDir, `${flowershowDir}/content`);
147
+
148
+ fs.unlinkSync(`${flowershowDir}/public/assets`);
149
+ if (assetsFolder !== "none") {
150
+ fs.symlinkSync(
151
+ path.resolve(contentDir, assetsFolder),
152
+ `${flowershowDir}/public/${assetsFolder}`
153
+ );
154
+ }
155
+
156
+ // // if there is no index.md file, create one
157
+ if (!fs.existsSync(`${contentPath}/index.md`)) {
158
+ const homePageContent = "# Welcome to my Flowershow site!";
159
+ fs.writeFile(
160
+ `${contentPath}/index.md`,
161
+ homePageContent,
162
+ { flag: "a" },
163
+ (err) => {} // eslint-disable-line no-unused-vars
164
+ );
165
+ }
166
+
167
+ // // if there is no config.js file, create one
168
+ if (!fs.existsSync(`${contentPath}/config.js`)) {
169
+ fs.writeFile(
170
+ `${contentPath}/config.js`,
171
+ "{}",
172
+ { flag: "a" },
173
+ (err) => {} // eslint-disable-line no-unused-vars
174
+ );
175
+ }
176
+
177
+ // install flowershow dependencies
178
+ logWithSpinner({
179
+ symbol: "🌸",
180
+ msg: `Installing Flowershow dependencies...`,
181
+ });
182
+
183
+ try {
184
+ // TODO this can be removed after monorepo has been set up correctly
185
+ await execa("npm", ["set-script", "prepare", ""], { cwd: flowershowDir });
186
+ const { stdout, stderr } = await execa("npm", ["install"], {
187
+ cwd: flowershowDir,
188
+ });
189
+ log(stdout);
190
+ log(stderr);
191
+ stopSpinner();
192
+ success("Successfuly installed Flowershow!");
193
+ } catch (err) {
194
+ error(`Installing dependencies failed: ${err.message}`);
195
+ exit(err.exitCode);
196
+ }
197
+ }
198
+ }
@@ -0,0 +1,19 @@
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
+ }
@@ -0,0 +1,12 @@
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 buildStatic(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
+ }
@@ -0,0 +1 @@
1
+ export const FLOWERSHOW_FOLDER_NAME = ".flowershow";
@@ -1,26 +1,24 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import chalk from 'chalk';
4
- import inquirer from 'inquirer';
5
-
6
- import Installer from './Installer.js';
7
- import { error, log, exit } from './utils/index.js';
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import inquirer from "inquirer";
8
4
 
5
+ import Installer from "./Installer.js";
6
+ import { error, exit } from "./utils/index.js";
9
7
 
10
8
  export default async function install(dir, options) {
11
9
  const currentDir = process.cwd();
12
- const inCurrentDir = dir === '.';
10
+ const inCurrentDir = dir === ".";
13
11
 
14
12
  if (inCurrentDir) {
15
13
  const { ok } = await inquirer.prompt([
16
14
  {
17
15
  name: "ok",
18
16
  type: "confirm",
19
- message: "Create Flowershow project in current directory?"
20
- }
21
- ])
17
+ message: "Create Flowershow project in current directory?",
18
+ },
19
+ ]);
22
20
  if (!ok) {
23
- return
21
+ return;
24
22
  }
25
23
  }
26
24
 
@@ -0,0 +1,20 @@
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
+ }
@@ -0,0 +1,14 @@
1
+ import chalk from "chalk";
2
+
3
+ const log = console.log;
4
+
5
+ export default function publish() {
6
+ log(chalk.redBright.bold("Command under construction...\n"));
7
+ log(
8
+ chalk.blue(
9
+ "Check " +
10
+ 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
+ );
14
+ }
@@ -0,0 +1,14 @@
1
+ import chalk from "chalk";
2
+
3
+ const log = console.log;
4
+
5
+ export default function upgrade() {
6
+ log(chalk.redBright.bold("Command under construction...\n"));
7
+ log(
8
+ chalk.blue(
9
+ "Check " +
10
+ 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
+ );
14
+ }
@@ -1,3 +1,3 @@
1
1
  export const exit = (code) => {
2
2
  process.exit(code);
3
- }
3
+ };
@@ -0,0 +1,8 @@
1
+ export { error, info, log, success, warn } from "./logger.js";
2
+ export { exit } from "./exit.js";
3
+ export {
4
+ logWithSpinner,
5
+ stopSpinner,
6
+ pauseSpinner,
7
+ resumeSpinner,
8
+ } from "./spinner.js";
@@ -0,0 +1,24 @@
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,54 +1,54 @@
1
- import ora from 'ora';
2
- import chalk from 'chalk';
1
+ import ora from "ora";
2
+ import chalk from "chalk";
3
3
 
4
- const spinner = ora({ color: 'magenta' });
4
+ const spinner = ora({ color: "magenta" });
5
5
  let lastMsg = null;
6
- let isPaused = false
6
+ let isPaused = false;
7
7
 
8
8
  export const logWithSpinner = ({ msg, symbol }) => {
9
9
  if (!symbol) {
10
- symbol = chalk.green('')
10
+ symbol = chalk.green("");
11
11
  }
12
12
  if (lastMsg) {
13
13
  spinner.stopAndPersist({
14
14
  symbol: lastMsg.symbol,
15
- text: lastMsg.text
16
- })
15
+ text: lastMsg.text,
16
+ });
17
17
  }
18
- spinner.text = ' ' + msg
18
+ spinner.text = " " + msg;
19
19
  lastMsg = {
20
- symbol: symbol + ' ',
21
- text: msg
22
- }
23
- spinner.start()
24
- }
20
+ symbol: symbol + " ",
21
+ text: msg,
22
+ };
23
+ spinner.start();
24
+ };
25
25
 
26
26
  export const stopSpinner = () => {
27
27
  if (!spinner.isSpinning) {
28
- return
28
+ return;
29
29
  }
30
30
 
31
31
  if (lastMsg) {
32
32
  spinner.stopAndPersist({
33
33
  symbol: lastMsg.symbol,
34
- text: lastMsg.text
35
- })
34
+ text: lastMsg.text,
35
+ });
36
36
  } else {
37
- spinner.stop()
37
+ spinner.stop();
38
38
  }
39
- lastMsg = null
40
- }
39
+ lastMsg = null;
40
+ };
41
41
 
42
42
  export const pauseSpinner = () => {
43
43
  if (spinner.isSpinning) {
44
- spinner.stop()
45
- isPaused = true
44
+ spinner.stop();
45
+ isPaused = true;
46
46
  }
47
- }
47
+ };
48
48
 
49
49
  export const resumeSpinner = () => {
50
50
  if (isPaused) {
51
- spinner.start()
52
- isPaused = false
51
+ spinner.start();
52
+ isPaused = false;
53
53
  }
54
- }
54
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
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
+ }
@@ -0,0 +1,17 @@
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
+ }
@@ -0,0 +1,20 @@
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
+ }
package/bin/flowershow.js DELETED
@@ -1,77 +0,0 @@
1
- #!/usr/bin/env node
2
- import { createRequire } from 'node:module';
3
- const require = createRequire(import.meta.url);
4
-
5
- import { Command } from "commander";
6
-
7
-
8
- // TODO check current vs required node version (package.json engines)
9
- // const requiredNodeVersion = require("../package.json").engines.node;
10
-
11
- const program = new Command();
12
-
13
- program
14
- .description('(Package under development)\nCLI tool for creating, publishing and upgrading Flowershow apps')
15
- .version(require("../package.json").version)
16
- .usage('<command> [options]')
17
-
18
- // choose template
19
- program
20
- .command('install')
21
- .description('install Flowershow template in target directory')
22
- .argument('[target-dir]', 'Path to the folder where you want Flowershow template to be installed', '.')
23
- // .option('-t, --template [template-name]', 'Flowershow template name to use', 'default')
24
- .action(async (targetDir, options) => {
25
- const { default: install } = await import ('../lib/install.js');
26
- install(targetDir, options);
27
- })
28
-
29
- program
30
- .command('build')
31
- .description('build Flowershow website')
32
- .argument('[project-dir]', 'Path to the folder where Flowershow template is installed (root folder of .flowershow)', '.')
33
- .action(async (projectPath) => {
34
- const { default: build } = await import ('../lib/build.js');
35
- build(projectPath);
36
- })
37
-
38
-
39
- program
40
- .command('build-static')
41
- .description('build static Flowershow website')
42
- .argument('[project-dir]', 'Path to the folder where Flowershow template is installed (root folder of .flowershow)', '.')
43
- .action(async (projectPath) => {
44
- const { default: buildStatic } = await import ('../lib/buildStatic.js');
45
- buildStatic(projectPath);
46
- })
47
-
48
- program
49
- .command('preview')
50
- .description('preview your Flowershow site')
51
- .argument('[project-dir]', 'Path to the folder where Flowershow template is installed (root folder of .flowershow)', '.')
52
- .action(async (projectPath) => {
53
- const { default: preview } = await import ('../lib/preview.js');
54
- preview(projectPath);
55
- })
56
-
57
- // TBD
58
- program
59
- .command('publish')
60
- .description('publish files or directories')
61
- .argument('[path]', 'path to a file or a directory', '.')
62
- .option('-g, --glob <pattern>', 'glob pattern')
63
- .action(async () => {
64
- const { default: publish } = await import ('../lib/publish.js');
65
- publish();
66
- })
67
-
68
- // TBD
69
- program
70
- .command('upgrade')
71
- .description('upgrade your Flowershow template to the latest version')
72
- .action(async () => {
73
- const { default: upgrade } = await import ('../lib/upgrade.js');
74
- upgrade();
75
- })
76
-
77
- program.parse();
package/lib/Installer.js DELETED
@@ -1,167 +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 { exit, error, log, success, logWithSpinner, stopSpinner, pauseSpinner, resumeSpinner } from './utils/index.js';
12
-
13
- import { FLOWERSHOW_FOLDER_NAME } from './const.js';
14
-
15
-
16
- export default class Creator {
17
- constructor(context, targetDir, template = 'default') {
18
- this.context = context;
19
- this.targetDir = targetDir;
20
- this.template = template; // tb configurable via command option in the future
21
- }
22
-
23
- get templateRepo() {
24
- const flowershowRepo = require('../package.json').repository.url.replace("git+", "");
25
- return `${flowershowRepo}/templates/${this.template}`
26
- }
27
-
28
- async install(options) {
29
- const { context, targetDir, templateRepo } = this;
30
- const flowershowDir = path.resolve(targetDir, FLOWERSHOW_FOLDER_NAME)
31
-
32
- let existsAction;
33
- if (fs.existsSync(flowershowDir)) {
34
- let { action } = await inquirer.prompt([
35
- {
36
- name: 'action',
37
- type: 'list',
38
- message: `Flowershow template is already installed in directory ${chalk.magenta(targetDir)}. What do you want to do?:`,
39
- choices: [
40
- { name: 'Overwrite', value: 'overwrite' },
41
- // { name: 'Merge', value: 'merge' },
42
- { name: 'Cancel', value: null }
43
- ]
44
- }
45
- ])
46
-
47
- if (!action) {
48
- exit(0)
49
- }
50
- existsAction = action;
51
- }
52
-
53
- let { contentPath } = await inquirer.prompt([
54
- {
55
- name: 'contentPath',
56
- type: 'input',
57
- message: 'Path to the folder with your markdown files',
58
- validate(input) {
59
- const contentDir = path.resolve(context, input);
60
- if (!fs.existsSync(contentDir)) {
61
- error(`Directory ${contentDir} does not exist.`);
62
- exit(1);
63
- }
64
- return true;
65
- }
66
- }
67
- ])
68
-
69
-
70
- const contentDir = path.resolve(context, contentPath);
71
- const assetFolderChoices = fs.readdirSync(contentDir, { withFileTypes: true })
72
- .filter(d => d.isDirectory())
73
- .map(d => ({ name: d.name, value: d.name }))
74
-
75
- let assetsFolder = 'none';
76
-
77
- if (!assetFolderChoices.length) {
78
- const { foldersAction } = await inquirer.prompt([
79
- {
80
- name: 'foldersAction',
81
- type: 'list',
82
- message: 'There are no subfolders in your content folder, that could be used as assets folder',
83
- choices: [
84
- { name: "I don't need assets folder", value: 'none' },
85
- { name: 'Cancel', value: null }
86
- ]
87
- }
88
- ])
89
-
90
- assetsFolder = foldersAction;
91
-
92
- } else {
93
-
94
- const { assets } = await inquirer.prompt([
95
- {
96
- name: 'assets',
97
- type: 'list',
98
- message: 'Select a folder with your assets (attachments)',
99
- choices: [
100
- ...assetFolderChoices,
101
- new inquirer.Separator(),
102
- { name: "I don't need assets folder", value: 'none' },
103
- { name: 'Cancel', value: null }
104
- ]
105
- }
106
- ])
107
-
108
- assetsFolder = assets;
109
- }
110
-
111
- if (!assetsFolder) {
112
- exit(0)
113
- }
114
-
115
- // install flowershow template
116
- logWithSpinner({ symbol: '🌷', msg: `Installing Flowershow template in ${chalk.magenta(flowershowDir)}...` });
117
-
118
- if (existsAction === 'overwrite') {
119
- fs.rmSync(flowershowDir, { recursive: true, force: true });
120
- }
121
-
122
- try {
123
- const emitter = degit(templateRepo);
124
- await emitter.clone(flowershowDir);
125
- } catch {
126
- error(`Failed to install Flowershow template in ${flowershowDir}.`)
127
- exit(1);
128
- }
129
-
130
- // update content and assets symlinks
131
- fs.unlinkSync(`${flowershowDir}/content`);
132
- fs.symlinkSync(contentDir, `${flowershowDir}/content`);
133
-
134
- fs.unlinkSync(`${flowershowDir}/public/assets`);
135
- if (assetsFolder !== 'none') {
136
- fs.symlinkSync(path.resolve(contentDir, assetsFolder), `${flowershowDir}/public/${assetsFolder}`);
137
- }
138
-
139
- // // if there is no index.md file, create one
140
- if (!fs.existsSync(`${contentPath}/index.md`)) {
141
- const homePageContent = '# Welcome to my Flowershow site!';
142
- fs.writeFile(`${contentPath}/index.md`, homePageContent, { flag: 'a' }, err => {});
143
- }
144
-
145
- // // if there is no config.js file, create one
146
- if (!fs.existsSync(`${contentPath}/config.js`)) {
147
- fs.writeFile(`${contentPath}/config.js`, '{}', { flag: 'a' }, err => {});
148
- }
149
-
150
- // install flowershow dependencies
151
- logWithSpinner({ symbol: '🌸', msg: `Installing Flowershow dependencies...` });
152
-
153
- try {
154
- await execa('npm', [ 'set-script', 'prepare', '' ], { cwd: flowershowDir });
155
- const { stdout, stderr } = await execa('npm', [ 'install'], { cwd: flowershowDir });
156
- log(stdout);
157
- log(stderr);
158
- stopSpinner();
159
- success("Successfuly installed Flowershow!")
160
- } catch (err) {
161
- error(
162
- `Installing dependencies failed: ${err.message}`
163
- );
164
- exit(err.exitCode);
165
- }
166
- }
167
- }
package/lib/build.js DELETED
@@ -1,20 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { execa } from 'execa';
4
-
5
- import { exit, error, log } from './utils/index.js';
6
- import { FLOWERSHOW_FOLDER_NAME } from './const.js';
7
-
8
-
9
- export default async function build(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', 'build' ], { cwd: flowershowDir });
18
-
19
- subprocess.stdout.pipe(process.stdout);
20
- }
@@ -1,15 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { execa } from 'execa';
4
-
5
- import { exit, error, log } from './utils/index.js';
6
- import { FLOWERSHOW_FOLDER_NAME } from './const.js';
7
-
8
-
9
- export default async function buildStatic(dir) {
10
- const flowershowDir = path.resolve(dir, FLOWERSHOW_FOLDER_NAME);
11
-
12
- const subprocess = execa('npm', [ 'run', 'export' ], { cwd: flowershowDir });
13
-
14
- subprocess.stdout.pipe(process.stdout);
15
- }
package/lib/const.js DELETED
@@ -1 +0,0 @@
1
- export const FLOWERSHOW_FOLDER_NAME = '.flowershow';
package/lib/preview.js DELETED
@@ -1,21 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { execa } from 'execa';
4
-
5
- import { exit, error, log } from './utils/index.js';
6
-
7
-
8
- import { FLOWERSHOW_FOLDER_NAME } from './const.js';
9
-
10
- export default async function preview(dir) {
11
- const flowershowDir = path.resolve(dir, FLOWERSHOW_FOLDER_NAME);
12
-
13
- // check if flowershow is installed
14
- if (!fs.existsSync(flowershowDir)) {
15
- error(`Directory ${flowershowDir} does not exist.`)
16
- exit(1);
17
- }
18
- const subprocess = execa('npm', [ 'run', 'dev' ], { cwd: flowershowDir });
19
-
20
- subprocess.stdout.pipe(process.stdout);
21
- }
package/lib/publish.js DELETED
@@ -1,12 +0,0 @@
1
- import chalk from 'chalk';
2
-
3
-
4
- const log = console.log;
5
-
6
- export default function publish (path, { glob }) {
7
- log(chalk.redBright.bold('Command under construction...\n'));
8
- log(chalk.blue(
9
- 'Check ' +
10
- chalk.green.underline('https://flowershow.app') +
11
- ' to learn more about Flowershow development stage and subscribe to get notified when it\'s ready!'))
12
- }
package/lib/upgrade.js DELETED
@@ -1,12 +0,0 @@
1
- import chalk from 'chalk';
2
-
3
-
4
- const log = console.log;
5
-
6
- export default function upgrade () {
7
- log(chalk.redBright.bold('Command under construction...\n'));
8
- log(chalk.blue(
9
- 'Check ' +
10
- chalk.green.underline('https://flowershow.app') +
11
- ' to learn more about Flowershow development stage and subscribe to get notified when it\'s ready!'))
12
- }
@@ -1,3 +0,0 @@
1
- export { error, info, log, success } from './logger.js';
2
- export { exit } from './exit.js';
3
- export { logWithSpinner, stopSpinner, pauseSpinner, resumeSpinner } from './spinner.js';
@@ -1,20 +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
- }