@ossy/app 0.3.1 → 0.4.1

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/cli/build.js CHANGED
@@ -53,7 +53,7 @@ export const build = async (cliArgs) => {
53
53
  }
54
54
 
55
55
  if (!fs.existsSync(middlewareSourcePath)) {
56
- apiSourcePath = path.resolve(scriptDir, 'Middleware.js')
56
+ middlewareSourcePath = path.resolve(scriptDir, 'Middleware.js')
57
57
  }
58
58
 
59
59
  if (fs.existsSync(configPath)) {
package/cli/dev.js ADDED
@@ -0,0 +1,137 @@
1
+ import path from 'path';
2
+ import url from 'url';
3
+ import fs from 'fs';
4
+ import { rollup } from 'rollup';
5
+ import babel from '@rollup/plugin-babel';
6
+ import { nodeResolve as resolveDependencies } from '@rollup/plugin-node-resolve'
7
+ import resolveCommonJsDependencies from '@rollup/plugin-commonjs'
8
+ import removeOwnPeerDependencies from 'rollup-plugin-peer-deps-external'
9
+ import minifyJS from '@rollup/plugin-terser'
10
+ // import typescript from '@rollup/plugin-typescript'
11
+ import preserveDirectives from "rollup-plugin-preserve-directives"
12
+ import json from "@rollup/plugin-json"
13
+ import copy from 'rollup-plugin-copy';
14
+ import replace from '@rollup/plugin-replace';
15
+ import remove from 'rollup-plugin-delete';
16
+ import arg from 'arg'
17
+ // import inject from '@rollup/plugin-inject'
18
+
19
+ export const dev = async (cliArgs) => {
20
+ console.log('[@ossy/cli][app][build] Starting...')
21
+
22
+ const options = arg({
23
+ '--source': String,
24
+ '--s': '--source',
25
+
26
+ '--destination': String,
27
+ '--d': '--destination',
28
+
29
+ '--config': String,
30
+ '-c': '--config',
31
+ }, { argv: cliArgs })
32
+
33
+
34
+ const appSourcePath = path.resolve(options['--source'] || 'src/App.jsx');
35
+ let apiSourcePath = path.resolve(options['--api-source'] || 'src/Api.js');
36
+ let middlewareSourcePath = path.resolve(options['--middleware-source'] || 'src/Middleware.js');
37
+ const configPath = path.resolve(options['--config'] || 'src/config.js');
38
+ const buildPath = path.resolve(options['--destination'] || 'build');
39
+ const publicDir = path.resolve('public')
40
+
41
+ const scriptDir = path.dirname(url.fileURLToPath(import.meta.url))
42
+ const inputClient = path.resolve(scriptDir, 'client.js')
43
+ const inputServer = path.resolve(scriptDir, 'server.js')
44
+
45
+ const inputFiles = [inputClient, inputServer]
46
+
47
+ if (!fs.existsSync(appSourcePath)) {
48
+ throw new Error(`[@ossy/cli][app][build] Source path does not exist: ${appSourcePath}`);
49
+ }
50
+
51
+ if (!fs.existsSync(apiSourcePath)) {
52
+ apiSourcePath = path.resolve(scriptDir, 'Api.js')
53
+ }
54
+
55
+ if (!fs.existsSync(middlewareSourcePath)) {
56
+ apiSourcePath = path.resolve(scriptDir, 'Middleware.js')
57
+ }
58
+
59
+ if (fs.existsSync(configPath)) {
60
+ inputFiles.push(configPath)
61
+ }
62
+
63
+ const inputOptions = {
64
+ input: inputFiles,
65
+ plugins: [
66
+ remove({ targets: buildPath }),
67
+ // inject({ 'React': 'react' }),
68
+ replace({
69
+ preventAssignment: true,
70
+ delimiters: ['%%', '%%'],
71
+ '@ossy/app/source-file': appSourcePath,
72
+ }),
73
+ replace({
74
+ preventAssignment: true,
75
+ delimiters: ['%%', '%%'],
76
+ '@ossy/api/source-file': apiSourcePath,
77
+ }),
78
+ replace({
79
+ preventAssignment: true,
80
+ delimiters: ['%%', '%%'],
81
+ '@ossy/middleware/source-file': apiSourcePath,
82
+ }),
83
+ replace({
84
+ preventAssignment: true,
85
+ 'process.env.NODE_ENV': JSON.stringify('production')
86
+ }),
87
+ json(),
88
+ // removeOwnPeerDependencies(),
89
+ resolveCommonJsDependencies(),
90
+ resolveDependencies({ preferBuiltins: true }),
91
+ babel({
92
+ babelHelpers: 'bundled',
93
+ // exclude: ['**/node_modules/**/*'],
94
+ presets: ['@babel/preset-env', '@babel/preset-react']
95
+ }),
96
+ // preserveDirectives(),
97
+ // minifyJS(),
98
+ copy({
99
+ targets: [
100
+ fs.existsSync(publicDir)
101
+ ? { src: `${publicDir}/**/*`, dest: 'build/public' }
102
+ : undefined,
103
+ ].filter(x => !!x)
104
+ })
105
+ ],
106
+ };
107
+
108
+ const outputOptions = [
109
+ {
110
+ dir: 'build',
111
+ // preserveModules: true,
112
+ entryFileNames: ({ name }) => {
113
+ if (name === 'server') {
114
+ return '[name].js'
115
+ } else if (name === 'Api') {
116
+ return '[name].js'
117
+ } else if (name === 'client') {
118
+ return 'public/static/main.js'
119
+ } else if (name === 'config') {
120
+ return 'public/static/[name].js'
121
+ } else {
122
+ return 'public/static/[name].js'
123
+ }
124
+ },
125
+ chunkFileNames: 'public/static/[name]-[hash].js',
126
+ format: 'esm',
127
+ }
128
+ ];
129
+
130
+ const bundle = await rollup.watch(inputOptions);
131
+
132
+ for (const options of outputOptions) {
133
+ await bundle.write(options);
134
+ }
135
+
136
+ console.log('[@ossy/cli][app][build] Finished');
137
+ };
package/cli/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  /* eslint-disable global-require, no-unused-vars */
3
3
  import { build } from './build.js'
4
+ import { dev } from './dev.js'
4
5
 
5
6
  const [_, __, command, ...restArgs] = process.argv
6
7
 
@@ -10,6 +11,7 @@ if (!command) {
10
11
 
11
12
  const commandHandler = {
12
13
  'build': build,
14
+ 'dev': dev,
13
15
  }[command]
14
16
 
15
17
  if (!commandHandler) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ossy/app",
3
- "version": "0.3.1",
3
+ "version": "0.4.1",
4
4
  "description": "",
5
5
  "source": "./src/index.js",
6
6
  "main": "./src/index.js",
@@ -50,5 +50,5 @@
50
50
  "/cli",
51
51
  "README.md"
52
52
  ],
53
- "gitHead": "b97ec6944720f804a43ae63bde88c3e14b0521cf"
53
+ "gitHead": "c6833acf8cb55ac9d601f3a4a66809a93973caea"
54
54
  }