flowershow 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,5 @@
1
1
  # Flowershow CLI
2
2
 
3
- CLI tool for creating, publishing and upgrading Flowershow apps.
4
-
5
- 🚧 Under development...
6
- 💻 See how you can contribute [here](https://github.com/flowershow/flowershow#contributing).
7
-
3
+ ```bash
4
+ npx flowershow --help
5
+ ```
@@ -0,0 +1,67 @@
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
+ program
39
+ .command('preview')
40
+ .description('preview your Flowershow site')
41
+ .argument('[project-dir]', 'Path to the folder where Flowershow template is installed (root folder of .flowershow)', '.')
42
+ .action(async (projectPath) => {
43
+ const { default: preview } = await import ('../lib/preview.js');
44
+ preview(projectPath);
45
+ })
46
+
47
+ // TBD
48
+ program
49
+ .command('publish')
50
+ .description('publish files or directories')
51
+ .argument('[path]', 'path to a file or a directory', '.')
52
+ .option('-g, --glob <pattern>', 'glob pattern')
53
+ .action(async () => {
54
+ const { default: publish } = await import ('../lib/publish.js');
55
+ publish();
56
+ })
57
+
58
+ // TBD
59
+ program
60
+ .command('upgrade')
61
+ .description('upgrade your Flowershow template to the latest version')
62
+ .action(async () => {
63
+ const { default: upgrade } = await import ('../lib/upgrade.js');
64
+ upgrade();
65
+ })
66
+
67
+ program.parse();
@@ -0,0 +1,147 @@
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, logWithSpinner, stopSpinner, pauseSpinner, resumeSpinner } from './utils/index.js';
12
+
13
+
14
+ import { FLOWERSHOW_RELATIVE_PATH } from './const.js';
15
+
16
+ export default class Creator {
17
+ constructor(context, template = 'default') {
18
+ this.context = context;
19
+ this.template = template; // tb configurable via command option in the future
20
+ }
21
+
22
+ get flowershowDir() {
23
+ return path.resolve(this.context, FLOWERSHOW_RELATIVE_PATH);
24
+ }
25
+
26
+ get templateRepo() {
27
+ const flowershowRepo = require('../package.json').repository.url.replace("git+", "");
28
+ return `${flowershowRepo}/templates/${this.template}`
29
+ }
30
+
31
+ async install(options) {
32
+ const { context, flowershowDir, templateRepo } = this;
33
+
34
+ logWithSpinner({ symbol: '🌷', msg: `Installing Flowershow template in ${chalk.magenta(flowershowDir)}...` });
35
+
36
+ if (fs.existsSync(flowershowDir)) {
37
+ pauseSpinner();
38
+
39
+ const { action } = await inquirer.prompt([
40
+ {
41
+ name: 'action',
42
+ type: 'list',
43
+ message: `Flowershow template is already installed in directory ${chalk.magenta(context)}. What do you want to do?:`,
44
+ choices: [
45
+ { name: 'Overwrite', value: 'overwrite' },
46
+ // { name: 'Merge', value: 'merge' },
47
+ { name: 'Cancel', value: false }
48
+ ]
49
+ }
50
+ ])
51
+
52
+ if (!action) {
53
+ return
54
+ } else {
55
+ fs.rmSync(flowershowDir, { recursive: true, force: true });
56
+ }
57
+ resumeSpinner();
58
+ }
59
+
60
+ // clone flowershow template
61
+ try {
62
+ const emitter = degit(templateRepo);
63
+ await emitter.clone(flowershowDir);
64
+ } catch {
65
+ // TODO better error message
66
+ error(`Failed to clone Flowershow template.`)
67
+ exit(1);
68
+ }
69
+
70
+ // symlink content folder
71
+ pauseSpinner();
72
+
73
+ let { contentPath } = await inquirer.prompt([
74
+ {
75
+ name: 'contentPath',
76
+ type: 'input',
77
+ message: 'Path to the folder with your content files',
78
+ validate(input) {
79
+ const contentPathAbsolute = path.resolve(context, input);
80
+ if (!fs.existsSync(contentPathAbsolute)) {
81
+ error(`Directory ${contentPathAbsolute} does not exist.`);
82
+ exit(1);
83
+ }
84
+ resumeSpinner();
85
+ return true;
86
+ }
87
+ }
88
+ ])
89
+
90
+ contentPath = path.resolve(context, contentPath);
91
+
92
+ fs.unlinkSync(`${flowershowDir}/content`);
93
+ fs.symlinkSync(contentPath, `${flowershowDir}/content`);
94
+
95
+
96
+ // // if there is no index.md file, create one
97
+ if (!fs.existsSync(`${contentPath}/index.md`)) {
98
+ const homePageContent = '# Welcome to my Flowershow site!';
99
+ fs.writeFile(`${contentPath}/index.md`, homePageContent, { flag: 'a' }, err => {});
100
+ }
101
+
102
+ // // if there is no config.js file, create one
103
+ if (!fs.existsSync(`${contentPath}/config.js`)) {
104
+ fs.writeFile(`${contentPath}/config.js`, '{}', { flag: 'a' }, err => {});
105
+ }
106
+
107
+ // symlink assets folder
108
+ pauseSpinner();
109
+
110
+ const { assetsFolder } = await inquirer.prompt([
111
+ {
112
+ name: 'assetsFolder',
113
+ type: 'input',
114
+ message: 'Name of your assets (attachements) folder',
115
+ validate(input) {
116
+ const assetsPathAbsolute = path.resolve(contentPath, input);
117
+ if (!fs.existsSync(assetsPathAbsolute)) {
118
+ error(`Directory ${assetsPathAbsolute} does not exist.`);
119
+ exit(1);
120
+ }
121
+ resumeSpinner();
122
+ return true;
123
+ }
124
+ }
125
+ ])
126
+
127
+ fs.unlinkSync(`${flowershowDir}/public/assets`);
128
+ fs.symlinkSync(path.resolve(contentPath, assetsFolder), `${flowershowDir}/public/assets`);
129
+
130
+
131
+ // // install flowershow dependencies
132
+ logWithSpinner({ symbol: '🌸', msg: `Installing Flowershow dependencies...` });
133
+
134
+ try {
135
+ const { stdout, stderr } = await execa('npm', [ 'install' ], { cwd: flowershowDir });
136
+ log(stdout);
137
+ log(stderr);
138
+ } catch (err) {
139
+ error(
140
+ `Installing dependencies failed: ${err.message}`
141
+ );
142
+ exit(err.exitCode);
143
+ }
144
+
145
+ stopSpinner();
146
+ }
147
+ }
package/lib/build.js ADDED
@@ -0,0 +1,21 @@
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_RELATIVE_PATH } from './const.js';
9
+
10
+ export default async function build(dir) {
11
+ const flowershowDir = path.resolve(dir, FLOWERSHOW_RELATIVE_PATH);
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', 'build' ], { cwd: flowershowDir });
19
+
20
+ subprocess.stdout.pipe(process.stdout);
21
+ }
package/lib/const.js ADDED
@@ -0,0 +1 @@
1
+ export const FLOWERSHOW_RELATIVE_PATH = '.flowershow';
package/lib/install.js ADDED
@@ -0,0 +1,34 @@
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';
8
+
9
+
10
+ export default async function install(targetDir, options) {
11
+ const currentDir = process.cwd();
12
+ const inCurrentDir = targetDir === '.';
13
+ const targetDirAbsolute = path.resolve(currentDir, targetDir);
14
+
15
+ if (fs.existsSync(targetDirAbsolute)) {
16
+ if (inCurrentDir) {
17
+ const { ok } = await inquirer.prompt([
18
+ {
19
+ name: "ok",
20
+ type: "confirm",
21
+ message: "Create Flowershow project in current directory?"
22
+ }
23
+ ])
24
+ if (!ok) {
25
+ return
26
+ }
27
+ }
28
+ } else {
29
+ fs.mkdirSync(targetDirAbsolute);
30
+ }
31
+
32
+ const installer = new Installer(targetDirAbsolute);
33
+ await installer.install(options);
34
+ }
package/lib/preview.js ADDED
@@ -0,0 +1,21 @@
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_RELATIVE_PATH } from './const.js';
9
+
10
+ export default async function preview(dir) {
11
+ const flowershowDir = path.resolve(dir, FLOWERSHOW_RELATIVE_PATH);
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
+ }
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ export const exit = (code) => {
2
+ process.exit(code);
3
+ }
@@ -0,0 +1,3 @@
1
+ export { error, info, log } from './logger.js';
2
+ export { exit } from './exit.js';
3
+ export { logWithSpinner, stopSpinner, pauseSpinner, resumeSpinner } from './spinner.js';
@@ -0,0 +1,16 @@
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
+ }
@@ -0,0 +1,54 @@
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/package.json CHANGED
@@ -1,31 +1,39 @@
1
1
  {
2
2
  "name": "flowershow",
3
- "version": "0.0.3",
4
- "engines": {
5
- "node": ">=14.16"
6
- },
7
- "author": "Rufus Pollock",
3
+ "version": "0.0.4",
8
4
  "description": "Publish your digital garden",
9
- "keywords": ["markdown", "MDX", "mdx", "publish", "obsidian"],
10
- "exports": "./index.js",
11
- "bin": "./index.js",
12
- "scripts": {
13
- "test": "echo \"Error: no test specified\" && exit 1"
5
+ "bin": {
6
+ "flowershow": "bin/flowershow.js"
14
7
  },
15
8
  "repository": {
16
9
  "type": "git",
17
10
  "url": "git+https://github.com/flowershow/flowershow",
18
- "directory": "packages/flowershow"
11
+ "directory": "packages/cli"
19
12
  },
13
+ "keywords": [
14
+ "flowershow",
15
+ "cli"
16
+ ],
17
+ "author": "Rufus Pollock",
20
18
  "license": "MIT",
21
19
  "bugs": {
22
20
  "url": "https://github.com/flowershow/flowershow/issues"
23
21
  },
24
22
  "homepage": "https://github.com/flowershow/flowershow#readme",
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
25
26
  "dependencies": {
26
- "chalk": "^4.1.2",
27
+ "chalk": "^5.0.1",
27
28
  "commander": "^9.4.0",
28
- "inquirer": "^9.1.1"
29
+ "degit": "^2.8.4",
30
+ "execa": "^6.1.0",
31
+ "inquirer": "^9.1.1",
32
+ "ora": "^6.1.2",
33
+ "validate-npm-package-name": "^4.0.0"
29
34
  },
30
- "type": "module"
35
+ "type": "module",
36
+ "engines": {
37
+ "node": ">=12.2.0"
38
+ }
31
39
  }
package/commands/build.js DELETED
@@ -1,12 +0,0 @@
1
- import chalk from 'chalk';
2
-
3
-
4
- const log = console.log;
5
-
6
- export default function build () {
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,12 +0,0 @@
1
- import chalk from 'chalk';
2
-
3
-
4
- const log = console.log;
5
-
6
- export default function create () {
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/index.js DELETED
@@ -1,39 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- import { Command } from "commander";
4
-
5
- import publish from './commands/publish.js';
6
- import create from './commands/create.js';
7
- import build from './commands/build.js';
8
- import upgrade from './commands/upgrade.js';
9
-
10
- const program = new Command();
11
-
12
- program
13
- .name('flowershow')
14
- .description('(Package under development)\nCLI tool for creating, publishing and upgrading Flowershow apps')
15
- .version('0.0.1');
16
-
17
- program
18
- .command('publish')
19
- .description('Publish files or directories')
20
- .argument('[path]', 'path to a file or a directory', '.')
21
- .option('-g, --glob <pattern>', 'glob pattern')
22
- .action(publish);
23
-
24
- program
25
- .command('create')
26
- .description('Create a new app template')
27
- .action(create);
28
-
29
- program
30
- .command('build')
31
- .description('Build Flowershow website')
32
- .action(build);
33
-
34
- program
35
- .command('upgrade')
36
- .description('Upgrade your Flowershow template to the latest version')
37
- .action(upgrade);
38
-
39
- program.parse();