flowershow 0.0.2 → 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 +5 -0
- package/bin/flowershow.js +67 -0
- package/lib/Installer.js +147 -0
- package/lib/build.js +21 -0
- package/lib/const.js +1 -0
- package/lib/install.js +34 -0
- package/lib/preview.js +21 -0
- package/lib/publish.js +12 -0
- package/lib/upgrade.js +12 -0
- package/lib/utils/exit.js +3 -0
- package/lib/utils/index.js +3 -0
- package/lib/utils/logger.js +16 -0
- package/lib/utils/spinner.js +54 -0
- package/package.json +27 -6
- package/upgrade.sh +28 -0
package/README.md
ADDED
|
@@ -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();
|
package/lib/Installer.js
ADDED
|
@@ -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
|
+
}
|
package/lib/publish.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
}
|
|
@@ -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,18 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flowershow",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"author": "Rufus Pollock",
|
|
3
|
+
"version": "0.0.4",
|
|
5
4
|
"description": "Publish your digital garden",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
5
|
+
"bin": {
|
|
6
|
+
"flowershow": "bin/flowershow.js"
|
|
8
7
|
},
|
|
9
8
|
"repository": {
|
|
10
9
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/flowershow/flowershow
|
|
10
|
+
"url": "git+https://github.com/flowershow/flowershow",
|
|
11
|
+
"directory": "packages/cli"
|
|
12
12
|
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"flowershow",
|
|
15
|
+
"cli"
|
|
16
|
+
],
|
|
17
|
+
"author": "Rufus Pollock",
|
|
13
18
|
"license": "MIT",
|
|
14
19
|
"bugs": {
|
|
15
20
|
"url": "https://github.com/flowershow/flowershow/issues"
|
|
16
21
|
},
|
|
17
|
-
"homepage": "https://github.com/flowershow/flowershow#readme"
|
|
22
|
+
"homepage": "https://github.com/flowershow/flowershow#readme",
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"chalk": "^5.0.1",
|
|
28
|
+
"commander": "^9.4.0",
|
|
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"
|
|
34
|
+
},
|
|
35
|
+
"type": "module",
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=12.2.0"
|
|
38
|
+
}
|
|
18
39
|
}
|
package/upgrade.sh
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# upgrade an existing standard nextjs site
|
|
2
|
+
|
|
3
|
+
npx degit flowershow/flowershow/templates/default --force
|
|
4
|
+
|
|
5
|
+
# files that we should keep the original (probably)
|
|
6
|
+
git checkout README.md
|
|
7
|
+
git checkout .gitignore
|
|
8
|
+
|
|
9
|
+
# stuff that shouldn't be there
|
|
10
|
+
rm .env.example
|
|
11
|
+
rm -Rf tests
|
|
12
|
+
rm netlify.toml
|
|
13
|
+
rm netlify.toml
|
|
14
|
+
# data seems to be exampleData
|
|
15
|
+
rm -Rf data
|
|
16
|
+
rm -Rf components/TempCallout.jsx
|
|
17
|
+
|
|
18
|
+
# set up custom components
|
|
19
|
+
rm -Rf components/custom
|
|
20
|
+
|
|
21
|
+
# set up assets
|
|
22
|
+
mkdir -p content/assets
|
|
23
|
+
rm public/assets
|
|
24
|
+
ln -s content/assets public/assets
|
|
25
|
+
|
|
26
|
+
# notes
|
|
27
|
+
echo "You may need to hand merge the following files:"
|
|
28
|
+
echo "pacakge.json, package-lock.json"
|