1 |
|
2 |
|
3 |
|
4 | import { IConfigParseResult } from '../libs/config-parse-result';
|
5 | import {IPlugin, forwardChildIamRoleStatements} from '../libs/plugin';
|
6 | import { isStorage } from './storage-component'
|
7 | import { PARSER_MODES } from '../libs/parser';
|
8 | import * as deepmerge from 'deepmerge';
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export interface IStoragePlugin {
|
15 | |
16 |
|
17 |
|
18 | parserMode: string,
|
19 |
|
20 | |
21 |
|
22 |
|
23 | buildPath: string,
|
24 | }
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | export const StoragePlugin = (props: IStoragePlugin): IPlugin => {
|
30 | const path = require('path');
|
31 |
|
32 | const result: IPlugin = {
|
33 |
|
34 | applies: (component): boolean => {
|
35 |
|
36 | return isStorage(component);
|
37 | },
|
38 |
|
39 |
|
40 |
|
41 | process: (
|
42 | component: any,
|
43 | childConfigs: Array<IConfigParseResult>,
|
44 | infrastructureMode: string | undefined
|
45 | ): IConfigParseResult => {
|
46 |
|
47 | const fs = require("fs");
|
48 | const path = require ("path");
|
49 |
|
50 | function createFolder() {
|
51 |
|
52 | if (props.parserMode === PARSER_MODES.MODE_START) {
|
53 |
|
54 | const targetFolder = ".s3";
|
55 |
|
56 | if ( !fs.existsSync( targetFolder) ) {
|
57 | fs.mkdirSync( targetFolder, {recursive: true} );
|
58 |
|
59 | }
|
60 | fs.chmodSync( targetFolder, 0o777);
|
61 | }
|
62 | }
|
63 |
|
64 |
|
65 |
|
66 | |
67 |
|
68 |
|
69 | const localS3Config = props.parserMode !== PARSER_MODES.MODE_START ? {} : {
|
70 |
|
71 | plugins: ["serverless-s3-local"],
|
72 |
|
73 |
|
74 | custom: {
|
75 | "s3": {
|
76 | port: 3002,
|
77 | directory: path.join(
|
78 | require("../../../infrastructure-scripts/dist/infra-comp-utils/system-libs").currentAbsolutePath(),".s3"
|
79 | )
|
80 | }
|
81 | },
|
82 |
|
83 | provider: {
|
84 | staticBucket: "${self:provider.stackName}",
|
85 |
|
86 | }
|
87 | };
|
88 |
|
89 | return {
|
90 | slsConfigs: deepmerge.all([
|
91 | localS3Config
|
92 | ].concat(childConfigs.map(config => config.slsConfigs))),
|
93 |
|
94 |
|
95 | webpackConfigs: childConfigs.reduce((result, config) => result.concat(config.webpackConfigs), []),
|
96 |
|
97 | postBuilds: childConfigs.reduce((result, config) => result.concat(config.postBuilds), [createFolder]),
|
98 |
|
99 | iamRoleStatements: forwardChildIamRoleStatements(childConfigs)
|
100 | }
|
101 | }
|
102 | }
|
103 |
|
104 | return result;
|
105 |
|
106 | }; |
\ | No newline at end of file |