@ossy/cli 0.0.3-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 +16 -1
- package/package.json +1 -1
- package/src/app/build.js +95 -0
- package/src/app/cli.js +22 -0
- package/src/cms/cli.js +14 -15
- package/src/index.js +1 -0
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
|
|
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
package/src/app/build.js
ADDED
|
@@ -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/cms/cli.js
CHANGED
|
@@ -3,16 +3,11 @@ import { resolve } from 'path'
|
|
|
3
3
|
import { readFileSync } from 'fs'
|
|
4
4
|
import arg from 'arg'
|
|
5
5
|
import fetch from 'node-fetch'
|
|
6
|
-
import { logInfo, logErrorAndReject, logDebug } from '../log.js'
|
|
7
|
-
|
|
8
|
-
const config = {
|
|
9
|
-
apiUrl: 'https://api.ossy.se/api/v0',
|
|
10
|
-
// apiUrl: 'http://localhost:3001/api/v0'
|
|
11
|
-
}
|
|
6
|
+
import { logInfo, logError, logErrorAndReject, logDebug } from '../log.js'
|
|
12
7
|
|
|
13
8
|
const Api = {
|
|
14
|
-
uploadResourceTemplates: (token, workspaceId, resourceTemplates) => {
|
|
15
|
-
const endpoint = `${
|
|
9
|
+
uploadResourceTemplates: (apiUrl, token, workspaceId, resourceTemplates) => {
|
|
10
|
+
const endpoint = `${apiUrl}/workspaces/${workspaceId}/resource-templates`
|
|
16
11
|
|
|
17
12
|
const fetchOptions = {
|
|
18
13
|
method: 'POST',
|
|
@@ -34,19 +29,20 @@ const importResourceTemplates = options => {
|
|
|
34
29
|
'--authentication': String,
|
|
35
30
|
'--a': '--authentication',
|
|
36
31
|
|
|
37
|
-
'--
|
|
38
|
-
'-
|
|
32
|
+
'--config': String,
|
|
33
|
+
'-c': '--config',
|
|
39
34
|
}, { argv: options })
|
|
40
35
|
|
|
41
36
|
logInfo({ message: '[CMS] reading files' })
|
|
42
|
-
const token = parsedArgs['--authentication']
|
|
43
|
-
const filePath = resolve(parsedArgs['--
|
|
37
|
+
const token = parsedArgs['--authentication'];
|
|
38
|
+
const filePath = resolve(parsedArgs['--config'])
|
|
44
39
|
|
|
45
40
|
if (!token) return logErrorAndReject({ message: '[CMS] No token provided with --authentication'})
|
|
46
41
|
|
|
47
42
|
return resolveConfigImport(filePath)
|
|
48
43
|
.then(module => {
|
|
49
44
|
const config = module?.default
|
|
45
|
+
const apiUrl = config?.apiUrl || 'https://api.ossy.se/api/v0'
|
|
50
46
|
const workspaceId = config?.workspaceId
|
|
51
47
|
const resourceTemplates = config?.resourceTemplates
|
|
52
48
|
|
|
@@ -54,9 +50,12 @@ const importResourceTemplates = options => {
|
|
|
54
50
|
if (!resourceTemplates) return logErrorAndReject({ message: '[CMS] No resource templates provided in ossy.json'})
|
|
55
51
|
|
|
56
52
|
logInfo({ message: '[CMS] uploading resource templates' })
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
.
|
|
53
|
+
|
|
54
|
+
Api.uploadResourceTemplates(apiUrl, token, workspaceId, resourceTemplates)
|
|
55
|
+
.then(response => {
|
|
56
|
+
logInfo({ message: '[CMS] Done' })
|
|
57
|
+
})
|
|
58
|
+
.catch(error => logError({ message: '[CMS] Error', error }))
|
|
60
59
|
})
|
|
61
60
|
|
|
62
61
|
}
|