@ossy/cli 0.0.4-alpha → 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,6 +1,21 @@
1
1
  # @ossy/cli
2
2
 
3
- Command line tool that makes it easier to interact with our APIs
3
+ Command line tool that makes it easier to interact with our services
4
+
5
+ ## App
6
+
7
+ ### build
8
+
9
+ Builds a production version of the app
10
+ ```
11
+ npx @ossy/cli app build
12
+ ```
13
+
14
+ ### serve
15
+ Serves the app
16
+ ```
17
+ npx @ossy/cli app serve
18
+ ```
4
19
 
5
20
  ## Cms
6
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ossy/cli",
3
- "version": "0.0.4-alpha",
3
+ "version": "0.0.4",
4
4
  "description": "Command line tool that makes it easier to interact with our APIs",
5
5
  "source": "./src/index.js",
6
6
  "main": "./src/index.js",
@@ -0,0 +1,95 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+ import { rollup } from 'rollup';
4
+ import babel from '@rollup/plugin-babel';
5
+ import { nodeResolve as resolveDependencies } from '@rollup/plugin-node-resolve'
6
+ import resolveCommonJsDependencies from '@rollup/plugin-commonjs'
7
+ import removeOwnPeerDependencies from 'rollup-plugin-peer-deps-external'
8
+ import minifyJS from '@rollup/plugin-terser'
9
+ // import typescript from '@rollup/plugin-typescript'
10
+ import preserveDirectives from "rollup-plugin-preserve-directives"
11
+ import json from "@rollup/plugin-json"
12
+ import copy from 'rollup-plugin-copy';
13
+ import replace from '@rollup/plugin-replace';
14
+ import remove from 'rollup-plugin-delete';
15
+
16
+ // export const build = async ({
17
+ // source = 'src/index.jsx',
18
+ // destination = 'build',
19
+ // }) => {
20
+ // console.log('[@ossy/app][Build] Starting build...')
21
+
22
+ // const sourcePath = path.resolve(source);
23
+ // const destinationDir = path.resolve(destination);
24
+
25
+ // if (!fs.existsSync(sourcePath)) {
26
+ // throw new Error(`[@ossy/app][Build] Source path does not exist: ${sourcePath}`);
27
+ // }
28
+
29
+ // const sourceData = fs.readFileSync(sourcePath, 'utf8');
30
+
31
+ // fs.mkdirSync(destinationDir, { recursive: true });
32
+ // fs.writeFileSync(path.join(destinationDir, 'index.js'), sourceData, { encoding: 'utf8', flag: 'w' });
33
+
34
+ // console.log('[@ossy/app][Build] Build finished')
35
+ // }
36
+
37
+
38
+
39
+ // Build folder structure
40
+ // build/server.js (provided by script)
41
+ // build/pages.js (manifest of pages and their entry points)
42
+ // build/<page-id>.page.js (for each page)
43
+ // build/static/index.js
44
+ // build/static/*.js
45
+
46
+
47
+ export const build = async ({
48
+ source = 'src/App.jsx',
49
+ destination = 'build',
50
+ } = {}) => {
51
+ console.log('[@ossy/cli][app][build] Starting...')
52
+
53
+ const sourcePath = path.resolve(source);
54
+ const buildPath = path.resolve(destination);
55
+
56
+ if (!fs.existsSync(sourcePath)) {
57
+ throw new Error(`[@ossy/cli][app][build] Source path does not exist: ${sourcePath}`);
58
+ }
59
+
60
+ const inputOptions = {
61
+ input: sourcePath,
62
+ plugins: [
63
+ remove({ targets: buildPath }),
64
+ replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
65
+ json(),
66
+ removeOwnPeerDependencies(),
67
+ resolveCommonJsDependencies(),
68
+ resolveDependencies({ preferBuiltins: true }),
69
+ babel({
70
+ babelHelpers: 'bundled',
71
+ exclude: ['**/node_modules/**/*'],
72
+ presets: ['@babel/preset-env', '@babel/preset-react']
73
+ }),
74
+ preserveDirectives(),
75
+ minifyJS(),
76
+ ],
77
+ };
78
+
79
+ const outputOptions = [
80
+ {
81
+ dir: 'build',
82
+ entryFileNames: ({ name }) => name === 'server' ? '[name].js' : 'static/[name].js',
83
+ chunkFileNames: 'static/[name]-[hash].js',
84
+ format: 'esm',
85
+ }
86
+ ];
87
+
88
+ const bundle = await rollup(inputOptions);
89
+
90
+ for (const options of outputOptions) {
91
+ await bundle.write(options);
92
+ }
93
+
94
+ console.log('[@ossy/cli][app][build] Finished');
95
+ };
package/src/app/cli.js ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+
3
+ const [_, __, handlerName, ...restArgs] = process.argv
4
+ import { build } from './cli/build.js'
5
+
6
+ export const handler = ([command, ...options]) => {
7
+
8
+ if (!command) {
9
+ logError({ message: '[@ossy/cli][app] No command provided' })
10
+ }
11
+
12
+ const commandHandler = {
13
+ 'build': build,
14
+ }[command]
15
+
16
+ if (!commandHandler) {
17
+ logError({ message: `[@ossy/cli][app] Unknown command: ${command}` })
18
+ }
19
+
20
+ commandHandler(options)
21
+
22
+ }
package/src/index.js CHANGED
@@ -4,6 +4,7 @@
4
4
  const [_, __, handlerName, ...restArgs] = process.argv
5
5
 
6
6
  const loadHandler = {
7
+ app: () => import('./app/cli.js'),
7
8
  cms: () => import('./cms/cli.js')
8
9
  }[handlerName]
9
10