Skip to content

Commit 8b70a99

Browse files
committed
Merge branch 'develop'
2 parents d7f235a + 21f6e1c commit 8b70a99

2 files changed

Lines changed: 153 additions & 88 deletions

File tree

src/apps/catalog/index.ts

Lines changed: 120 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import * as _ from 'lodash';
22

33
import { App, Archivable, BuildOpts, Buildable } from '../types';
4-
import Install, { Pkg, configureDeclarations, pieToConfigureMap, toDeclarations } from '../../install';
4+
import Install, {
5+
Pkg,
6+
configureDeclarations,
7+
pieToConfigureMap,
8+
toDeclarations
9+
} from '../../install';
510
import { Names, getNames, webpackConfig } from '../common';
611
import { archiveIgnores, createArchive } from '../create-archive';
7-
import { existsSync, writeFileSync, readFileSync, readJsonSync } from 'fs-extra';
12+
import {
13+
existsSync,
14+
writeFileSync,
15+
readFileSync,
16+
readJsonSync
17+
} from 'fs-extra';
818
import { join, resolve } from 'path';
919
import { JsonConfig } from '../../question/config';
1020
import { SupportConfig } from '../../framework-support';
@@ -23,29 +33,36 @@ const logger = buildLogger();
2333
*/
2434
export default class CatalogApp
2535
implements App, Archivable<Pkg[]>, Buildable<Pkg[], BuildOpts> {
26-
27-
public static generatedFiles: string[] = ['pie-item.tar.gz', 'pie-catalog.bundle.js'];
28-
29-
public static build(args: any, loadSupport: (JsonConfig) => Promise<SupportConfig>): Promise<App> {
36+
public static generatedFiles: string[] = [
37+
'pie-item.tar.gz',
38+
'pie-catalog.bundle.js'
39+
];
40+
41+
public static build(
42+
args: any,
43+
loadSupport: (JsonConfig) => Promise<SupportConfig>
44+
): Promise<App> {
3045
const dir = resolve(args.dir || process.cwd());
3146
if (!existsSync(join(dir, 'docs/demo'))) {
32-
throw new Error(`Can't find a 'docs/demo' directory in path: ${dir}. Is this a pie directory?`);
47+
throw new Error(
48+
`Can't find a 'docs/demo' directory in path: ${dir}. Is this a pie directory?`
49+
);
3350
}
3451

3552
const config = JsonConfig.build(join(dir, 'docs/demo'), args);
3653

37-
return loadSupport(config)
38-
.then((s) => {
39-
return new CatalogApp(args, dir, config, s, getNames(args));
40-
});
54+
return loadSupport(config).then(s => {
55+
return new CatalogApp(args, dir, config, s, getNames(args));
56+
});
4157
}
4258

4359
private static ENTRY = 'catalog.entry.js';
4460
private static BUNDLE = 'pie-catalog.bundle.js';
4561
private static WEBPACK_CONFIG = 'catalog.webpack.config.js';
4662

4763
private static EXTERNALS = {
48-
'lodash': '_',
64+
// tslint:disable-next-line:object-literal-key-quotes
65+
lodash: '_',
4966
'lodash.merge': '_.merge',
5067
'lodash/assign': '_.assign',
5168
'lodash/cloneDeep': '_.cloneDeep',
@@ -55,20 +72,24 @@ export default class CatalogApp
5572
'lodash/isEqual': '_.isEqual',
5673
'lodash/map': '_.map',
5774
'lodash/merge': '_.merge',
58-
'react': 'React',
75+
// tslint:disable-next-line:object-literal-key-quotes
76+
react: 'React',
5977
'react-addons-transition-group': 'React.addons.TransitionGroup',
6078
'react-dom': 'ReactDOM',
79+
'react-dom/server': 'ReactDOMServer',
6180
'react/lib/ReactCSSTransitionGroup': 'React.addons.CSSTransitionGroup',
6281
'react/lib/ReactTransitionGroup': 'React.addons.TransitionGroup'
6382
};
6483

6584
private installer: Install;
6685

67-
constructor(readonly args: any,
86+
constructor(
87+
readonly args: any,
6888
private pieRoot: string,
6989
readonly config: JsonConfig,
7090
readonly support: SupportConfig,
71-
readonly names: Names) {
91+
readonly names: Names
92+
) {
7293
this.installer = new Install(config.dir, config.raw);
7394
}
7495

@@ -77,30 +98,39 @@ export default class CatalogApp
7798
}
7899

79100
public async build(opts: BuildOpts): Promise<Pkg[]> {
80-
81101
const { dirs, pkgs } = await this.installer.install(opts.forceInstall);
82102

83103
const js = `
84104
//controllers
85105
let controllers = window.controllers = {};
86-
${ pkgs.map(bi => controllerDependency(bi.element.tag, bi.controller.moduleId)).join('\n')}
106+
${pkgs
107+
.map(bi => controllerDependency(bi.element.tag, bi.controller.moduleId))
108+
.join('\n')}
87109
//custom elements
88-
${toDeclarations(pkgs).map((d) => d.js).join('\n')}
110+
${toDeclarations(pkgs)
111+
.map(d => d.js)
112+
.join('\n')}
89113
90114
//configure elements
91-
${configureDeclarations(pkgs).map(e => e.js).join('\n')}
115+
${configureDeclarations(pkgs)
116+
.map(e => e.js)
117+
.join('\n')}
92118
`;
93119

94120
writeFileSync(join(dirs.root, CatalogApp.ENTRY), js, 'utf8');
95121

96-
const config = _.merge(webpackConfig(
97-
dirs,
98-
this.support,
99-
CatalogApp.ENTRY,
100-
CatalogApp.BUNDLE,
101-
this.config.dir), {
122+
const config = _.merge(
123+
webpackConfig(
124+
dirs,
125+
this.support,
126+
CatalogApp.ENTRY,
127+
CatalogApp.BUNDLE,
128+
this.config.dir
129+
),
130+
{
102131
externals: CatalogApp.EXTERNALS
103-
});
132+
}
133+
);
104134

105135
logger.silly('config: ', config);
106136

@@ -118,13 +148,16 @@ export default class CatalogApp
118148
}
119149
].concat(config.module.rules);
120150

121-
await report.promise('building webpack', buildWebpack(config, CatalogApp.WEBPACK_CONFIG));
151+
await report.promise(
152+
'building webpack',
153+
buildWebpack(config, CatalogApp.WEBPACK_CONFIG)
154+
);
122155

123156
return pkgs;
124157
}
125158

126159
public async createArchive(buildInfo: Pkg[]): Promise<string> {
127-
const root = (name) => resolve(join(this.pieRoot, name));
160+
const root = name => resolve(join(this.pieRoot, name));
128161
const archivePath = resolve(join(this.config.dir, this.names.out.archive));
129162
const pkg = readJsonSync(root('package.json'));
130163

@@ -138,14 +171,24 @@ export default class CatalogApp
138171
logger.silly('tag', tag, 'hash', hash, 'shorthash', shortHash);
139172

140173
if (!repository || !npm) {
141-
return Promise.reject(new Error('The package.json is missing `repository` and `name` fields'));
174+
return Promise.reject(
175+
new Error('The package.json is missing `repository` and `name` fields')
176+
);
142177
}
143178

144179
/* TODO: ignore config/markup? */
145180
const ignores = archiveIgnores(this.config.dir);
146181

147-
logger.silly('call createArchive', archivePath, this.config.dir, ignores, addExtras);
148-
const readme = existsSync(root('README.md')) ? readFileSync(root('README.md'), 'utf8') : '';
182+
logger.silly(
183+
'call createArchive',
184+
archivePath,
185+
this.config.dir,
186+
ignores,
187+
addExtras
188+
);
189+
const readme = existsSync(root('README.md'))
190+
? readFileSync(root('README.md'), 'utf8')
191+
: '';
149192

150193
const git = {
151194
hash,
@@ -154,15 +197,24 @@ export default class CatalogApp
154197
};
155198
const schemas = buildSchemas(root('docs/schemas'));
156199
logger.silly('callAddExtras...');
157-
const ae = addExtras(this.config.raw, this.config.markup, this.support,
158-
buildInfo, pkg, npm, readme, repository, git, schemas);
159-
return createArchive(archivePath, this.config.dir, ignores, ae)
160-
.catch((e) => {
161-
const msg = `Error creating the archive: ${e.message}`;
162-
logger.error(msg);
163-
logger.info(e.stack);
164-
throw new Error(msg);
165-
});
200+
const ae = addExtras(
201+
this.config.raw,
202+
this.config.markup,
203+
this.support,
204+
buildInfo,
205+
pkg,
206+
npm,
207+
readme,
208+
repository,
209+
git,
210+
schemas
211+
);
212+
return createArchive(archivePath, this.config.dir, ignores, ae).catch(e => {
213+
const msg = `Error creating the archive: ${e.message}`;
214+
logger.error(msg);
215+
logger.info(e.stack);
216+
throw new Error(msg);
217+
});
166218
}
167219
}
168220

@@ -176,32 +228,32 @@ export const addExtras = (
176228
readme: string,
177229
repository: any,
178230
git: any,
179-
schemas: any[]) => (archive: any): void => {
180-
181-
const catalog = {
182-
demo: {
183-
config,
184-
configureMap: pieToConfigureMap(pkgs),
185-
externals: support.externals,
186-
markup,
187-
},
188-
npm,
189-
package: pkg,
190-
readme,
191-
repository,
192-
schemas,
193-
version: {
194-
git,
195-
pkg: pkg.version,
196-
}
197-
};
198-
199-
const catalogString = JSON.stringify(catalog, null, ' ');
200-
logger.silly('catalog json: ', catalogString);
201-
logger.silly('archive: ', archive);
202-
/**
203-
* It is important that the catalog json is the first entry in the tar,
204-
* so that the upload stream will consume this entry first.
205-
*/
206-
archive.append(catalogString, { name: 'pie-catalog-data.json' });
231+
schemas: any[]
232+
) => (archive: any): void => {
233+
const catalog = {
234+
demo: {
235+
config,
236+
configureMap: pieToConfigureMap(pkgs),
237+
externals: support.externals,
238+
markup
239+
},
240+
npm,
241+
package: pkg,
242+
readme,
243+
repository,
244+
schemas,
245+
version: {
246+
git,
247+
pkg: pkg.version
248+
}
207249
};
250+
251+
const catalogString = JSON.stringify(catalog, null, ' ');
252+
logger.silly('catalog json: ', catalogString);
253+
logger.silly('archive: ', archive);
254+
/**
255+
* It is important that the catalog json is the first entry in the tar,
256+
* so that the upload stream will consume this entry first.
257+
*/
258+
archive.append(catalogString, { name: 'pie-catalog-data.json' });
259+
};

src/install/index.ts

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
11
import * as _ from 'lodash';
22

3-
import { install, Dirs, Pkg, PieConfigure, PieController, PackageType, Element } from '@pie-cli-libs/installer';
4-
import { ElementDeclaration } from '../code-gen';
5-
import { PieTarget } from './common';
6-
import { RawConfig } from '../question/config';
7-
import report from '../cli/report';
8-
9-
export {
3+
import {
4+
install,
105
Dirs,
11-
PackageType,
126
Pkg,
137
PieConfigure,
148
PieController,
9+
PackageType,
1510
Element
16-
};
11+
} from '@pie-cli-libs/installer';
12+
import { ElementDeclaration } from '../code-gen';
13+
import { PieTarget } from './common';
14+
import { RawConfig } from '../question/config';
15+
import report from '../cli/report';
16+
17+
export { Dirs, PackageType, Pkg, PieConfigure, PieController, Element };
1718

1819
export { PieTarget };
1920

2021
export type Mappings = {
21-
controllers: PieTarget[],
22-
configure: PieTarget[]
22+
controllers: PieTarget[];
23+
configure: PieTarget[];
2324
};
2425

25-
export const controllerTargets = (pkgs: Pkg[]): PieTarget[] => toTargets('controller', pkgs);
26+
export const controllerTargets = (pkgs: Pkg[]): PieTarget[] =>
27+
toTargets('controller', pkgs);
2628

2729
export const configureDeclarations = (pkgs: Pkg[]): ElementDeclaration[] => {
2830
return pkgs.filter(bi => bi.configure).map(bi => {
2931
return new ElementDeclaration(`${bi.configure.tag}`, bi.configure.moduleId);
3032
});
3133
};
3234

33-
export const pieToConfigureMap = (pkgs: Pkg[] = []): { [key: string]: string } => {
35+
export const pieToConfigureMap = (
36+
pkgs: Pkg[] = []
37+
): { [key: string]: string } => {
3438
return pkgs.reduce((acc, p) => {
3539
if (p.configure) {
3640
return { ...acc, [p.element.tag]: p.configure.tag };
@@ -41,26 +45,35 @@ export const pieToConfigureMap = (pkgs: Pkg[] = []): { [key: string]: string } =
4145
};
4246

4347
export const toDeclarations = (pkgs: Pkg[]): ElementDeclaration[] => {
44-
return pkgs.map(bi => new ElementDeclaration(bi.element.tag, bi.element.moduleId));
48+
return pkgs.map(
49+
bi => new ElementDeclaration(bi.element.tag, bi.element.moduleId)
50+
);
4551
};
4652

47-
const toTargets = (key: 'controller' | 'configure', pkgs: Pkg[]): PieTarget[] => {
53+
const toTargets = (
54+
key: 'controller' | 'configure',
55+
pkgs: Pkg[]
56+
): PieTarget[] => {
4857
return _(pkgs)
4958
.filter(bi => bi[key])
5059
.map(bi => ({ pie: (bi as any).element.tag, target: bi[key].moduleId }))
5160
.value();
5261
};
5362

5463
export type InstallResult = {
55-
dirs: Dirs,
56-
pkgs: Pkg[]
64+
dirs: Dirs;
65+
pkgs: Pkg[];
5766
};
5867

5968
export default class Install {
60-
61-
constructor(private rootDir: string, private config: RawConfig) { }
69+
constructor(private rootDir: string, private config: RawConfig) {}
6270

6371
public install(force: boolean = false): Promise<InstallResult> {
64-
return install(this.rootDir, this.config.elements, this.config.models, report);
72+
return install(
73+
this.rootDir,
74+
this.config.elements,
75+
this.config.models,
76+
report
77+
);
6578
}
6679
}

0 commit comments

Comments
 (0)