oc 0.49.7 → 0.49.8
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/CHANGELOG.md +22 -0
- package/README.md +2 -15
- package/dist/cli/domain/clean.d.ts +2 -2
- package/dist/cli/domain/clean.js +10 -13
- package/dist/cli/domain/get-components-by-dir.d.ts +1 -1
- package/dist/cli/domain/get-components-by-dir.js +8 -15
- package/dist/cli/domain/get-mocked-plugins.js +8 -6
- package/dist/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.js +4 -5
- package/dist/cli/domain/handle-dependencies/get-compiler.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/get-compiler.js +3 -3
- package/dist/cli/domain/handle-dependencies/index.d.ts +4 -3
- package/dist/cli/domain/handle-dependencies/index.js +40 -34
- package/dist/cli/domain/handle-dependencies/install-compiler.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/install-compiler.js +14 -7
- package/dist/cli/domain/handle-dependencies/install-missing-dependencies.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/install-missing-dependencies.js +13 -9
- package/dist/cli/domain/handle-dependencies/link-missing-dependencies.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/link-missing-dependencies.js +4 -8
- package/dist/cli/domain/init-template/index.d.ts +2 -2
- package/dist/cli/domain/init-template/index.js +6 -8
- package/dist/cli/domain/init-template/install-template.d.ts +2 -2
- package/dist/cli/domain/init-template/install-template.js +10 -9
- package/dist/cli/domain/init-template/scaffold.d.ts +2 -2
- package/dist/cli/domain/init-template/scaffold.js +7 -7
- package/dist/cli/domain/local.js +11 -10
- package/dist/cli/domain/mock.d.ts +1 -1
- package/dist/cli/domain/mock.js +21 -21
- package/dist/cli/domain/package-components.d.ts +1 -1
- package/dist/cli/domain/package-components.js +14 -17
- package/dist/cli/domain/registry.js +68 -81
- package/dist/cli/domain/watch.js +1 -1
- package/dist/cli/facade/clean.d.ts +10 -4
- package/dist/cli/facade/clean.js +38 -28
- package/dist/cli/facade/dev.d.ts +108 -15
- package/dist/cli/facade/dev.js +85 -99
- package/dist/cli/facade/init.d.ts +12 -5
- package/dist/cli/facade/init.js +22 -20
- package/dist/cli/facade/mock.d.ts +12 -5
- package/dist/cli/facade/mock.js +5 -6
- package/dist/cli/facade/package.d.ts +12 -5
- package/dist/cli/facade/package.js +30 -32
- package/dist/cli/facade/preview.d.ts +8 -3
- package/dist/cli/facade/preview.js +12 -10
- package/dist/cli/facade/publish.d.ts +16 -7
- package/dist/cli/facade/publish.js +94 -114
- package/dist/cli/facade/registry-add.d.ts +8 -3
- package/dist/cli/facade/registry-add.js +10 -9
- package/dist/cli/facade/registry-ls.d.ts +4 -1
- package/dist/cli/facade/registry-ls.js +19 -17
- package/dist/cli/facade/registry-remove.d.ts +8 -3
- package/dist/cli/facade/registry-remove.js +10 -9
- package/dist/cli/facade/registry.d.ts +4 -1
- package/dist/cli/facade/registry.js +6 -3
- package/dist/cli/index.js +3 -5
- package/dist/cli/programmatic-api.d.ts +1 -1
- package/dist/components/oc-client/_package/package.json +1 -1
- package/dist/components/oc-client/package.json +1 -1
- package/dist/registry/app-start.d.ts +2 -2
- package/dist/registry/app-start.js +20 -20
- package/dist/registry/domain/components-cache/components-list.d.ts +7 -6
- package/dist/registry/domain/components-cache/components-list.js +31 -45
- package/dist/registry/domain/components-cache/index.d.ts +6 -5
- package/dist/registry/domain/components-cache/index.js +47 -50
- package/dist/registry/domain/components-details.d.ts +5 -4
- package/dist/registry/domain/components-details.js +27 -38
- package/dist/registry/domain/extract-package.d.ts +2 -2
- package/dist/registry/domain/extract-package.js +9 -12
- package/dist/registry/domain/get-package-json-from-temp-dir.d.ts +1 -1
- package/dist/registry/domain/get-package-json-from-temp-dir.js +2 -2
- package/dist/registry/domain/nested-renderer.d.ts +7 -6
- package/dist/registry/domain/nested-renderer.js +36 -72
- package/dist/registry/domain/options-sanitiser.js +5 -3
- package/dist/registry/domain/plugins-initialiser.d.ts +3 -1
- package/dist/registry/domain/plugins-initialiser.js +29 -33
- package/dist/registry/domain/repository.js +78 -100
- package/dist/registry/domain/require-wrapper.js +1 -2
- package/dist/registry/domain/storage-adapter.d.ts +10 -0
- package/dist/registry/domain/storage-adapter.js +55 -0
- package/dist/registry/index.d.ts +2 -2
- package/dist/registry/index.js +15 -28
- package/dist/registry/middleware/index.d.ts +6 -2
- package/dist/registry/middleware/index.js +5 -1
- package/dist/registry/router.d.ts +2 -2
- package/dist/registry/router.js +0 -2
- package/dist/registry/routes/component-info.js +3 -2
- package/dist/registry/routes/component-preview.js +2 -1
- package/dist/registry/routes/components.js +1 -1
- package/dist/registry/routes/helpers/get-component-fallback.d.ts +2 -7
- package/dist/registry/routes/helpers/get-component.d.ts +5 -5
- package/dist/registry/routes/helpers/get-component.js +6 -5
- package/dist/registry/routes/helpers/is-url-discoverable.d.ts +2 -2
- package/dist/registry/routes/helpers/is-url-discoverable.js +15 -9
- package/dist/registry/routes/index.js +4 -3
- package/dist/registry/routes/publish.d.ts +1 -1
- package/dist/registry/routes/publish.js +32 -31
- package/dist/resources/settings.js +1 -1
- package/dist/types.d.ts +35 -43
- package/dist/utils/npm-utils.d.ts +6 -8
- package/dist/utils/npm-utils.js +20 -9
- package/dist/utils/put.d.ts +2 -1
- package/dist/utils/put.js +10 -29
- package/logintervals.md +1 -1
- package/package.json +6 -1
- package/src/cli/domain/clean.ts +10 -20
- package/src/cli/domain/get-components-by-dir.ts +12 -26
- package/src/cli/domain/get-mocked-plugins.ts +32 -26
- package/src/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.ts +8 -12
- package/src/cli/domain/handle-dependencies/get-compiler.ts +8 -11
- package/src/cli/domain/handle-dependencies/index.ts +55 -109
- package/src/cli/domain/handle-dependencies/install-compiler.ts +22 -15
- package/src/cli/domain/handle-dependencies/install-missing-dependencies.ts +19 -13
- package/src/cli/domain/handle-dependencies/link-missing-dependencies.ts +8 -16
- package/src/cli/domain/init-template/index.ts +13 -20
- package/src/cli/domain/init-template/install-template.ts +11 -12
- package/src/cli/domain/init-template/scaffold.ts +9 -12
- package/src/cli/domain/local.ts +19 -22
- package/src/cli/domain/mock.ts +32 -36
- package/src/cli/domain/package-components.ts +14 -25
- package/src/cli/domain/registry.ts +80 -116
- package/src/cli/domain/watch.ts +1 -1
- package/src/cli/facade/clean.ts +37 -37
- package/src/cli/facade/dev.ts +159 -182
- package/src/cli/facade/init.ts +36 -38
- package/src/cli/facade/mock.ts +11 -10
- package/src/cli/facade/package.ts +44 -49
- package/src/cli/facade/preview.ts +20 -18
- package/src/cli/facade/publish.ts +134 -172
- package/src/cli/facade/registry-add.ts +16 -15
- package/src/cli/facade/registry-ls.ts +27 -22
- package/src/cli/facade/registry-remove.ts +16 -15
- package/src/cli/facade/registry.ts +7 -5
- package/src/cli/index.ts +3 -5
- package/src/components/oc-client/_package/package.json +1 -1
- package/src/components/oc-client/package.json +1 -1
- package/src/globals.d.ts +38 -0
- package/src/registry/app-start.ts +27 -31
- package/src/registry/domain/components-cache/components-list.ts +45 -67
- package/src/registry/domain/components-cache/index.ts +55 -60
- package/src/registry/domain/components-details.ts +49 -75
- package/src/registry/domain/extract-package.ts +19 -27
- package/src/registry/domain/get-package-json-from-temp-dir.ts +3 -4
- package/src/registry/domain/nested-renderer.ts +64 -122
- package/src/registry/domain/options-sanitiser.ts +6 -3
- package/src/registry/domain/plugins-initialiser.ts +45 -49
- package/src/registry/domain/repository.ts +129 -235
- package/src/registry/domain/require-wrapper.ts +1 -2
- package/src/registry/domain/storage-adapter.ts +85 -0
- package/src/registry/index.ts +48 -79
- package/src/registry/middleware/index.ts +10 -2
- package/src/registry/router.ts +2 -10
- package/src/registry/routes/component-info.ts +4 -3
- package/src/registry/routes/component-preview.ts +3 -2
- package/src/registry/routes/components.ts +1 -1
- package/src/registry/routes/helpers/get-component-fallback.ts +3 -9
- package/src/registry/routes/helpers/get-component.ts +11 -9
- package/src/registry/routes/helpers/is-url-discoverable.ts +14 -15
- package/src/registry/routes/index.ts +18 -13
- package/src/registry/routes/publish.ts +31 -34
- package/src/resources/settings.ts +1 -1
- package/src/types.ts +63 -136
- package/src/utils/npm-utils.ts +38 -37
- package/src/utils/put.ts +15 -37
package/src/cli/facade/dev.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import async from 'async';
|
|
2
1
|
import colors from 'colors/safe';
|
|
3
|
-
import
|
|
2
|
+
import getPortCb from 'getport';
|
|
4
3
|
import livereload from 'livereload';
|
|
5
4
|
import path from 'path';
|
|
6
|
-
import
|
|
5
|
+
import { promisify } from 'util';
|
|
6
|
+
import { fromPromise } from 'universalify';
|
|
7
7
|
|
|
8
8
|
import getMockedPlugins from '../domain/get-mocked-plugins';
|
|
9
9
|
import handleDependencies from '../domain/handle-dependencies';
|
|
@@ -18,70 +18,63 @@ type Registry = ReturnType<typeof oc.Registry>;
|
|
|
18
18
|
const cliMessages = strings.messages.cli;
|
|
19
19
|
const cliErrors = strings.errors.cli;
|
|
20
20
|
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const delay = (time = 0) => new Promise(res => setTimeout(res, time));
|
|
22
|
+
const getPort = promisify(getPortCb);
|
|
23
|
+
|
|
24
|
+
const dev = ({ local, logger }: { logger: Logger; local: Local }) =>
|
|
25
|
+
fromPromise(
|
|
26
|
+
async (opts: {
|
|
25
27
|
prefix: string;
|
|
26
28
|
dirPath: string;
|
|
27
29
|
port?: number;
|
|
28
30
|
baseUrl: string;
|
|
29
31
|
fallbackRegistryUrl: string;
|
|
30
32
|
hotReloading?: boolean;
|
|
31
|
-
components
|
|
33
|
+
components?: string[];
|
|
32
34
|
watch?: boolean;
|
|
33
35
|
verbose?: boolean;
|
|
34
36
|
production?: boolean;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
components,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (err) {
|
|
56
|
-
logger.err(strings.errors.generic(String(err)));
|
|
57
|
-
} else {
|
|
58
|
-
logger.warn(cliMessages.CHANGES_DETECTED(changedFile));
|
|
59
|
-
if (!hotReloading) {
|
|
60
|
-
logger.warn(cliMessages.HOT_RELOADING_DISABLED);
|
|
61
|
-
} else if (!componentDir) {
|
|
62
|
-
cb(components, refreshLiveReload);
|
|
37
|
+
}): Promise<Registry> => {
|
|
38
|
+
const componentsDir = opts.dirPath;
|
|
39
|
+
const port = opts.port || 3000;
|
|
40
|
+
const baseUrl = opts.baseUrl || `http://localhost:${port}/`;
|
|
41
|
+
const fallbackRegistryUrl = opts.fallbackRegistryUrl;
|
|
42
|
+
const hotReloading =
|
|
43
|
+
typeof opts.hotReloading === 'undefined' ? true : opts.hotReloading;
|
|
44
|
+
const optWatch = typeof opts.watch === 'undefined' ? true : opts.watch;
|
|
45
|
+
let packaging = false;
|
|
46
|
+
|
|
47
|
+
const watchForChanges = function (
|
|
48
|
+
{
|
|
49
|
+
components,
|
|
50
|
+
refreshLiveReload
|
|
51
|
+
}: { components: string[]; refreshLiveReload: () => void },
|
|
52
|
+
cb: any
|
|
53
|
+
) {
|
|
54
|
+
watch(components, componentsDir, (err, changedFile, componentDir) => {
|
|
55
|
+
if (err) {
|
|
56
|
+
logger.err(strings.errors.generic(String(err)));
|
|
63
57
|
} else {
|
|
64
|
-
|
|
58
|
+
logger.warn(cliMessages.CHANGES_DETECTED(changedFile));
|
|
59
|
+
if (!hotReloading) {
|
|
60
|
+
logger.warn(cliMessages.HOT_RELOADING_DISABLED);
|
|
61
|
+
} else if (!componentDir) {
|
|
62
|
+
cb(components, refreshLiveReload);
|
|
63
|
+
} else {
|
|
64
|
+
cb([componentDir], refreshLiveReload);
|
|
65
|
+
}
|
|
65
66
|
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const packageComponents = (
|
|
71
|
-
componentsDirs: string[],
|
|
72
|
-
optCb?: () => void
|
|
73
|
-
) => {
|
|
74
|
-
const cb = typeof optCb === 'function' ? optCb : _.noop;
|
|
75
|
-
|
|
76
|
-
let i = 0;
|
|
67
|
+
});
|
|
68
|
+
};
|
|
77
69
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
const packageComponents = async (
|
|
71
|
+
componentsDirs: string[]
|
|
72
|
+
): Promise<void> => {
|
|
73
|
+
if (!packaging) {
|
|
74
|
+
packaging = true;
|
|
75
|
+
logger.warn(cliMessages.PACKAGING_COMPONENTS, false);
|
|
81
76
|
|
|
82
|
-
|
|
83
|
-
componentsDirs,
|
|
84
|
-
(dir, cb) => {
|
|
77
|
+
for (const dir of componentsDirs) {
|
|
85
78
|
logger.warn(cliMessages.PACKAGING(dir), false);
|
|
86
79
|
const packageOptions = {
|
|
87
80
|
componentPath: dir,
|
|
@@ -90,150 +83,134 @@ const dev =
|
|
|
90
83
|
production: opts.production
|
|
91
84
|
};
|
|
92
85
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
error => {
|
|
99
|
-
if (error) {
|
|
86
|
+
try {
|
|
87
|
+
await local.package(packageOptions);
|
|
88
|
+
packaging = false;
|
|
89
|
+
logger.ok('OK');
|
|
90
|
+
} catch (error: any) {
|
|
100
91
|
const errorDescription =
|
|
101
92
|
error instanceof SyntaxError || !!error.message
|
|
102
93
|
? error.message
|
|
103
94
|
: error;
|
|
104
95
|
logger.err(
|
|
105
|
-
cliErrors.PACKAGING_FAIL(
|
|
106
|
-
componentsDirs[i],
|
|
107
|
-
String(errorDescription)
|
|
108
|
-
)
|
|
96
|
+
cliErrors.PACKAGING_FAIL(dir, String(errorDescription))
|
|
109
97
|
);
|
|
110
98
|
logger.warn(cliMessages.RETRYING_10_SECONDS);
|
|
111
|
-
|
|
112
|
-
packaging = false;
|
|
113
|
-
packageComponents(componentsDirs);
|
|
114
|
-
}, 10000);
|
|
115
|
-
} else {
|
|
99
|
+
await delay(10000);
|
|
116
100
|
packaging = false;
|
|
117
|
-
|
|
118
|
-
cb();
|
|
101
|
+
packageComponents(componentsDirs);
|
|
119
102
|
}
|
|
120
103
|
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const registerPlugins = (registry: Registry) => {
|
|
108
|
+
const mockedPlugins = getMockedPlugins(logger, componentsDir);
|
|
109
|
+
mockedPlugins.forEach(p => registry.register(p));
|
|
110
|
+
|
|
111
|
+
registry.on('request', data => {
|
|
112
|
+
if (data.errorCode === 'PLUGIN_MISSING_FROM_REGISTRY') {
|
|
113
|
+
logger.err(
|
|
114
|
+
cliErrors.PLUGIN_MISSING_FROM_REGISTRY(
|
|
115
|
+
String(data.errorDetails),
|
|
116
|
+
colors.blue(strings.commands.cli.MOCK_PLUGIN)
|
|
117
|
+
)
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
logger.warn(cliMessages.SCANNING_COMPONENTS, true);
|
|
124
|
+
const components = await local.getComponentsByDir(
|
|
125
|
+
componentsDir,
|
|
126
|
+
opts.components
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
if (!components.length) {
|
|
130
|
+
const err = cliErrors.DEV_FAIL(cliErrors.COMPONENTS_NOT_FOUND);
|
|
131
|
+
logger.err(err);
|
|
132
|
+
throw err;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
logger.ok('OK');
|
|
136
|
+
components.forEach(component =>
|
|
137
|
+
logger.log(colors.green('├── ') + component)
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
const dependencies = await handleDependencies({
|
|
141
|
+
components,
|
|
142
|
+
logger
|
|
143
|
+
}).catch(err => {
|
|
144
|
+
logger.err(err);
|
|
145
|
+
return Promise.reject(err);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
await packageComponents(components);
|
|
149
|
+
|
|
150
|
+
let liveReload: { refresher: () => void; port: number | undefined } = {
|
|
151
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
152
|
+
refresher: () => {},
|
|
153
|
+
port: undefined
|
|
154
|
+
};
|
|
155
|
+
if (hotReloading) {
|
|
156
|
+
const otherPort = await getPort(port + 1).catch(err => {
|
|
157
|
+
logger.err(String(err));
|
|
158
|
+
return Promise.reject(err);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const liveReloadServer = livereload.createServer({
|
|
162
|
+
port: otherPort
|
|
163
|
+
});
|
|
164
|
+
const refresher = () => liveReloadServer.refresh('/');
|
|
165
|
+
liveReload = { refresher, port: otherPort };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const registry = oc.Registry({
|
|
169
|
+
baseUrl,
|
|
170
|
+
prefix: opts.prefix || '',
|
|
171
|
+
dependencies: dependencies.modules,
|
|
172
|
+
discovery: true,
|
|
173
|
+
env: { name: 'local' },
|
|
174
|
+
fallbackRegistryUrl,
|
|
175
|
+
hotReloading,
|
|
176
|
+
liveReloadPort: liveReload.port,
|
|
177
|
+
local: true,
|
|
178
|
+
components: opts.components,
|
|
179
|
+
path: path.resolve(componentsDir),
|
|
180
|
+
port,
|
|
181
|
+
templates: dependencies.templates,
|
|
182
|
+
verbosity: 1
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
registerPlugins(registry);
|
|
186
|
+
|
|
187
|
+
logger.warn(cliMessages.REGISTRY_STARTING(baseUrl));
|
|
188
|
+
if (liveReload.port) {
|
|
189
|
+
logger.warn(
|
|
190
|
+
cliMessages.REGISTRY_LIVERELOAD_STARTING(String(liveReload.port))
|
|
121
191
|
);
|
|
122
192
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (data.errorCode === 'PLUGIN_MISSING_FROM_REGISTRY') {
|
|
131
|
-
logger.err(
|
|
132
|
-
cliErrors.PLUGIN_MISSING_FROM_REGISTRY(
|
|
133
|
-
data.errorDetails!,
|
|
134
|
-
colors.blue(strings.commands.cli.MOCK_PLUGIN)
|
|
135
|
-
)
|
|
193
|
+
try {
|
|
194
|
+
await promisify(registry.start);
|
|
195
|
+
|
|
196
|
+
if (optWatch) {
|
|
197
|
+
watchForChanges(
|
|
198
|
+
{ components, refreshLiveReload: liveReload.refresher },
|
|
199
|
+
packageComponents
|
|
136
200
|
);
|
|
137
201
|
}
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
logger.warn(cliMessages.SCANNING_COMPONENTS, true);
|
|
142
|
-
local.getComponentsByDir(
|
|
143
|
-
componentsDir,
|
|
144
|
-
opts.components as any,
|
|
145
|
-
(err, components) => {
|
|
146
|
-
if (_.isEmpty(components)) {
|
|
147
|
-
err = cliErrors.DEV_FAIL(cliErrors.COMPONENTS_NOT_FOUND) as any;
|
|
148
|
-
callback(err, undefined as any);
|
|
149
|
-
return logger.err(String(err));
|
|
150
|
-
}
|
|
151
202
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
203
|
+
return registry;
|
|
204
|
+
} catch (err: any) {
|
|
205
|
+
if (err.code === 'EADDRINUSE') {
|
|
206
|
+
// eslint-disable-next-line no-ex-assign
|
|
207
|
+
err = cliErrors.PORT_IS_BUSY(port) as any;
|
|
208
|
+
}
|
|
156
209
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
logger.err(err);
|
|
160
|
-
return callback(err, undefined as any);
|
|
161
|
-
}
|
|
162
|
-
packageComponents(components, () => {
|
|
163
|
-
async.waterfall(
|
|
164
|
-
[
|
|
165
|
-
(next: any) => {
|
|
166
|
-
if (hotReloading) {
|
|
167
|
-
getPort(port + 1, (error, otherPort) => {
|
|
168
|
-
if (error) {
|
|
169
|
-
return next(error);
|
|
170
|
-
}
|
|
171
|
-
const liveReloadServer = livereload.createServer({
|
|
172
|
-
port: otherPort
|
|
173
|
-
});
|
|
174
|
-
const refresher = () => liveReloadServer.refresh('/');
|
|
175
|
-
next(null, { refresher, port: otherPort });
|
|
176
|
-
});
|
|
177
|
-
} else {
|
|
178
|
-
next(null, { refresher: _.noop, port: null });
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
],
|
|
182
|
-
(err, liveReload: any) => {
|
|
183
|
-
if (err) {
|
|
184
|
-
logger.err(String(err));
|
|
185
|
-
return callback(err, undefined as any);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const registry = oc.Registry({
|
|
189
|
-
baseUrl,
|
|
190
|
-
prefix: opts.prefix || '',
|
|
191
|
-
dependencies: dependencies.modules,
|
|
192
|
-
discovery: true,
|
|
193
|
-
env: { name: 'local' },
|
|
194
|
-
fallbackRegistryUrl,
|
|
195
|
-
hotReloading,
|
|
196
|
-
liveReloadPort: liveReload.port,
|
|
197
|
-
local: true,
|
|
198
|
-
components: opts.components,
|
|
199
|
-
path: path.resolve(componentsDir),
|
|
200
|
-
port,
|
|
201
|
-
templates: dependencies.templates,
|
|
202
|
-
verbosity: 1
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
registerPlugins(registry);
|
|
206
|
-
|
|
207
|
-
logger.warn(cliMessages.REGISTRY_STARTING(baseUrl));
|
|
208
|
-
if (liveReload.port) {
|
|
209
|
-
logger.warn(
|
|
210
|
-
cliMessages.REGISTRY_LIVERELOAD_STARTING(liveReload.port)
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
registry.start(err => {
|
|
214
|
-
if (err) {
|
|
215
|
-
if ((err as any).code === 'EADDRINUSE') {
|
|
216
|
-
err = cliErrors.PORT_IS_BUSY(port) as any;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
logger.err(String(err));
|
|
220
|
-
return callback(err, undefined as any);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (optWatch) {
|
|
224
|
-
watchForChanges(
|
|
225
|
-
{ components, refreshLiveReload: liveReload.refresher },
|
|
226
|
-
packageComponents
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
callback(null, registry);
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
);
|
|
233
|
-
});
|
|
234
|
-
});
|
|
210
|
+
logger.err(String(err));
|
|
211
|
+
throw err;
|
|
235
212
|
}
|
|
236
|
-
|
|
237
|
-
|
|
213
|
+
}
|
|
214
|
+
);
|
|
238
215
|
|
|
239
216
|
export default dev;
|
package/src/cli/facade/init.ts
CHANGED
|
@@ -1,52 +1,50 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
import { fromPromise } from 'universalify';
|
|
2
3
|
|
|
3
4
|
import strings from '../../resources/index';
|
|
4
5
|
import { Local } from '../../types';
|
|
5
6
|
import { Logger } from '../logger';
|
|
6
7
|
|
|
7
|
-
const init =
|
|
8
|
-
(
|
|
9
|
-
|
|
10
|
-
opts: {
|
|
8
|
+
const init = ({ local, logger }: { local: Local; logger: Logger }) =>
|
|
9
|
+
fromPromise(
|
|
10
|
+
async (opts: {
|
|
11
11
|
componentName: string;
|
|
12
12
|
componentPath: string;
|
|
13
13
|
templateType: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
logger.err(errors.INIT_FAIL(err));
|
|
43
|
-
} else {
|
|
44
|
-
logger.log(messages.initSuccess(componentName, componentPath));
|
|
14
|
+
}): Promise<string> => {
|
|
15
|
+
const templateType =
|
|
16
|
+
typeof opts.templateType === 'undefined'
|
|
17
|
+
? 'oc-template-es6'
|
|
18
|
+
: opts.templateType;
|
|
19
|
+
const errors = strings.errors.cli;
|
|
20
|
+
const messages = strings.messages.cli;
|
|
21
|
+
const componentPath = path.join(process.cwd(), opts.componentPath);
|
|
22
|
+
const componentName = path.basename(componentPath);
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
await local.init({
|
|
26
|
+
componentName,
|
|
27
|
+
componentPath,
|
|
28
|
+
templateType,
|
|
29
|
+
logger
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
logger.log(messages.initSuccess(componentName, componentPath));
|
|
33
|
+
|
|
34
|
+
return componentName;
|
|
35
|
+
} catch (err) {
|
|
36
|
+
let errMsg = String(err);
|
|
37
|
+
|
|
38
|
+
if (err === 'name not valid') {
|
|
39
|
+
errMsg = errors.NAME_NOT_VALID;
|
|
40
|
+
} else if (err === 'template type not valid') {
|
|
41
|
+
errMsg = errors.TEMPLATE_TYPE_NOT_VALID(templateType);
|
|
45
42
|
}
|
|
46
43
|
|
|
47
|
-
|
|
44
|
+
logger.err(errors.INIT_FAIL(errMsg));
|
|
45
|
+
throw err;
|
|
48
46
|
}
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
}
|
|
48
|
+
);
|
|
51
49
|
|
|
52
50
|
export default init;
|
package/src/cli/facade/mock.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import { fromPromise } from 'universalify';
|
|
1
2
|
import strings from '../../resources/index';
|
|
2
3
|
import { Local } from '../../types';
|
|
3
4
|
import { Logger } from '../logger';
|
|
4
5
|
|
|
5
|
-
const mock =
|
|
6
|
-
(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
const mock = ({ local, logger }: { local: Local; logger: Logger }) =>
|
|
7
|
+
fromPromise(
|
|
8
|
+
async (opts: {
|
|
9
|
+
targetType: string;
|
|
10
|
+
targetValue: string;
|
|
11
|
+
targetName: string;
|
|
12
|
+
}): Promise<void> => {
|
|
13
|
+
await local.mock(opts);
|
|
12
14
|
logger.ok(
|
|
13
15
|
strings.messages.cli.MOCKED_PLUGIN(opts.targetName, opts.targetValue)
|
|
14
16
|
);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
17
|
+
}
|
|
18
|
+
);
|
|
18
19
|
|
|
19
20
|
export default mock;
|
|
@@ -1,69 +1,64 @@
|
|
|
1
1
|
import strings from '../../resources/index';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import { fromPromise } from 'universalify';
|
|
3
4
|
import handleDependencies from '../domain/handle-dependencies';
|
|
4
5
|
import { Logger } from '../logger';
|
|
5
6
|
import { Component, Local } from '../../types';
|
|
6
7
|
|
|
7
|
-
const cliPackage =
|
|
8
|
-
(
|
|
9
|
-
|
|
10
|
-
opts: {
|
|
8
|
+
const cliPackage = ({ local, logger }: { local: Local; logger: Logger }) =>
|
|
9
|
+
fromPromise(
|
|
10
|
+
async (opts: {
|
|
11
11
|
componentPath: string;
|
|
12
12
|
useComponentDependencies?: boolean;
|
|
13
13
|
compress?: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
}): Promise<Component> => {
|
|
15
|
+
const componentPath = opts.componentPath;
|
|
16
|
+
const useComponentDependencies = opts.useComponentDependencies;
|
|
17
|
+
const packageDir = path.resolve(componentPath, '_package');
|
|
18
|
+
const compressedPackagePath = path.resolve(
|
|
19
|
+
componentPath,
|
|
20
|
+
'package.tar.gz'
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
logger.warn(strings.messages.cli.PACKAGING(packageDir));
|
|
24
|
+
try {
|
|
25
|
+
await handleDependencies({
|
|
26
|
+
components: [path.resolve(componentPath)],
|
|
27
|
+
logger,
|
|
28
|
+
useComponentDependencies
|
|
29
|
+
});
|
|
21
30
|
|
|
22
|
-
logger.warn(strings.messages.cli.PACKAGING(packageDir));
|
|
23
|
-
handleDependencies(
|
|
24
|
-
{
|
|
25
|
-
components: [path.resolve(componentPath)],
|
|
26
|
-
logger,
|
|
27
|
-
useComponentDependencies
|
|
28
|
-
},
|
|
29
|
-
err => {
|
|
30
|
-
if (err) {
|
|
31
|
-
logger.err(err);
|
|
32
|
-
return callback(err, undefined as any);
|
|
33
|
-
}
|
|
34
31
|
const packageOptions = {
|
|
35
32
|
production: true,
|
|
36
33
|
componentPath: path.resolve(componentPath)
|
|
37
34
|
};
|
|
38
|
-
local.package(packageOptions, (err, component) => {
|
|
39
|
-
if (err) {
|
|
40
|
-
logger.err(strings.errors.cli.PACKAGE_CREATION_FAIL(String(err)));
|
|
41
|
-
return callback(err as any, undefined as any);
|
|
42
|
-
}
|
|
43
35
|
|
|
44
|
-
|
|
36
|
+
const component = await local.package(packageOptions).catch(err => {
|
|
37
|
+
logger.err(strings.errors.cli.PACKAGE_CREATION_FAIL(String(err)));
|
|
38
|
+
return Promise.reject(err);
|
|
39
|
+
});
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
logger.warn(
|
|
48
|
-
strings.messages.cli.COMPRESSING(compressedPackagePath)
|
|
49
|
-
);
|
|
41
|
+
logger.ok(strings.messages.cli.PACKAGED(packageDir));
|
|
50
42
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
43
|
+
if (opts.compress) {
|
|
44
|
+
logger.warn(strings.messages.cli.COMPRESSING(compressedPackagePath));
|
|
45
|
+
|
|
46
|
+
await local.compress(packageDir, compressedPackagePath).catch(err => {
|
|
47
|
+
logger.err(strings.errors.cli.PACKAGE_CREATION_FAIL(String(err)));
|
|
48
|
+
return Promise.reject(err);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
logger.ok(strings.messages.cli.COMPRESSED(compressedPackagePath));
|
|
52
|
+
|
|
53
|
+
return component;
|
|
54
|
+
} else {
|
|
55
|
+
return component;
|
|
56
|
+
}
|
|
57
|
+
} catch (err) {
|
|
58
|
+
logger.err(String(err));
|
|
59
|
+
throw err;
|
|
65
60
|
}
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
}
|
|
62
|
+
);
|
|
68
63
|
|
|
69
64
|
export default cliPackage;
|
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import open from 'open';
|
|
2
|
+
import { fromPromise } from 'universalify';
|
|
2
3
|
|
|
3
4
|
import strings from '../../resources/index';
|
|
4
5
|
import { RegistryCli } from '../../types';
|
|
5
6
|
import { Logger } from '../logger';
|
|
6
7
|
|
|
7
|
-
const preview =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
8
|
+
const preview = ({
|
|
9
|
+
logger,
|
|
10
|
+
registry
|
|
11
|
+
}: {
|
|
12
|
+
logger: Logger;
|
|
13
|
+
registry: RegistryCli;
|
|
14
|
+
}) =>
|
|
15
|
+
fromPromise(async (opts: { componentHref: string }): Promise<string> => {
|
|
16
|
+
try {
|
|
17
|
+
const href = await registry.getComponentPreviewUrlByUrl(
|
|
18
|
+
opts.componentHref
|
|
19
|
+
);
|
|
20
|
+
await open(href);
|
|
21
|
+
return href;
|
|
22
|
+
} catch (err) {
|
|
23
|
+
logger.err(strings.errors.cli.COMPONENT_HREF_NOT_FOUND);
|
|
24
|
+
throw strings.errors.cli.COMPONENT_HREF_NOT_FOUND;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
25
27
|
|
|
26
28
|
export default preview;
|