@bigcommerce/stencil-cli 8.3.0 → 8.4.0
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/bin/stencil-bundle.js +7 -18
- package/bin/stencil-debug.js +5 -9
- package/bin/stencil-download.js +7 -19
- package/bin/stencil-init.js +4 -8
- package/bin/stencil-pull.js +5 -11
- package/bin/stencil-push.js +5 -8
- package/bin/stencil-release.js +5 -10
- package/bin/stencil-scss-autofix.js +6 -11
- package/bin/stencil-start.js +6 -9
- package/bin/stencil.js +2 -3
- package/constants.js +9 -9
- package/lib/BuildConfigManager.js +25 -23
- package/lib/Cycles.js +3 -12
- package/lib/ScssValidator.js +5 -9
- package/lib/StencilCLISettings.js +1 -3
- package/lib/StencilConfigManager.js +6 -22
- package/lib/StencilDebug.js +7 -10
- package/lib/archiveManager.js +7 -23
- package/lib/bundle-validator.js +28 -64
- package/lib/cliCommon.js +11 -21
- package/lib/commander.js +2 -3
- package/lib/content-api-client.js +5 -13
- package/lib/css/compile.js +3 -6
- package/lib/graphql/query.js +5 -8
- package/lib/lang/validator.js +5 -11
- package/lib/lang-assembler.js +4 -10
- package/lib/lang-helper.js +3 -6
- package/lib/nodeSass/AutoFixer.js +10 -19
- package/lib/nodeSass/BaseFixer.js +5 -7
- package/lib/nodeSass/BaseRulesFixer.js +3 -8
- package/lib/nodeSass/CommaRemovalFixer.js +3 -8
- package/lib/nodeSass/ConditionalImportFixer.js +3 -9
- package/lib/nodeSass/UndefinedVariableFixer.js +3 -6
- package/lib/parse-json.js +10 -9
- package/lib/regions.js +3 -23
- package/lib/release/questions.js +3 -13
- package/lib/release/release.js +16 -55
- package/lib/spinner.js +1 -2
- package/lib/stencil-bundle.js +15 -75
- package/lib/stencil-download.js +5 -6
- package/lib/stencil-download.utils.js +5 -18
- package/lib/stencil-init.js +8 -24
- package/lib/stencil-pull.js +4 -5
- package/lib/stencil-pull.utils.js +5 -28
- package/lib/stencil-push.js +3 -4
- package/lib/stencil-push.utils.js +12 -102
- package/lib/stencil-start.js +19 -48
- package/lib/store-settings-api-client.js +4 -7
- package/lib/template-assembler.js +6 -45
- package/lib/theme-api-client.js +7 -30
- package/lib/theme-config.js +16 -59
- package/lib/utils/NetworkUtils.js +6 -16
- package/lib/utils/asyncUtils.js +2 -3
- package/lib/utils/frontmatter.js +4 -5
- package/lib/utils/fsUtils.js +6 -10
- package/lib/validator/schema-translations.js +5 -7
- package/package.json +11 -8
- package/server/config.js +3 -7
- package/server/index.js +29 -29
- package/server/lib/page-type-util.js +2 -5
- package/server/lib/show-logo.js +3 -3
- package/server/lib/utils.js +6 -11
- package/server/manifest.js +7 -11
- package/server/plugins/renderer/renderer.module.js +38 -100
- package/server/plugins/renderer/responses/index.js +7 -4
- package/server/plugins/renderer/responses/pencil-response.js +4 -32
- package/server/plugins/renderer/responses/raw-response.js +6 -14
- package/server/plugins/renderer/responses/redirect-response.js +1 -4
- package/server/plugins/router/router.module.js +9 -14
- package/server/plugins/theme-assets/theme-assets.module.js +15 -27
package/lib/release/release.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import os from 'os';
|
|
2
|
+
import uuid from 'uuid4';
|
|
3
|
+
import fsModule from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
// eslint-disable-next-line import/no-unresolved, node/no-missing-import
|
|
6
|
+
import { Octokit as octokitModule } from '@octokit/rest';
|
|
7
|
+
import simpleGit from 'simple-git';
|
|
8
|
+
import ThemeConfig from '../theme-config.js';
|
|
9
|
+
import askQuestions from './questions.js';
|
|
10
|
+
import Bundle from '../stencil-bundle.js';
|
|
11
|
+
import StencilConfigManager from '../StencilConfigManager.js';
|
|
12
|
+
import fsUtilsModule from '../utils/fsUtils.js';
|
|
13
|
+
import { THEME_PATH } from '../../constants.js';
|
|
14
14
|
|
|
15
15
|
class StencilRelease {
|
|
16
16
|
constructor({
|
|
@@ -34,34 +34,25 @@ class StencilRelease {
|
|
|
34
34
|
async run(cliOptions) {
|
|
35
35
|
const gitData = await this.getGitData();
|
|
36
36
|
this.checkGitData(gitData, cliOptions);
|
|
37
|
-
|
|
38
37
|
const version = await this._themeConfigManager.getVersion();
|
|
39
38
|
this.checkCurrentVersion(version);
|
|
40
|
-
|
|
41
39
|
const answers = await askQuestions(version, await this.getGithubToken(), gitData.remotes);
|
|
42
|
-
|
|
43
40
|
await this.saveGithubToken(answers.githubToken);
|
|
44
|
-
|
|
45
41
|
const options = {
|
|
46
42
|
...answers,
|
|
47
43
|
...cliOptions,
|
|
48
44
|
};
|
|
49
45
|
await this.doRelease(options);
|
|
50
|
-
|
|
51
46
|
this._logger.log('done'.green);
|
|
52
|
-
|
|
53
47
|
return true;
|
|
54
48
|
}
|
|
55
49
|
|
|
56
50
|
async getGitData() {
|
|
57
51
|
const status = await this._git.status();
|
|
58
|
-
|
|
59
52
|
const response = await this._git.getRemotes(true);
|
|
60
|
-
|
|
61
53
|
const remotes = response.map((remote) => {
|
|
62
54
|
const url = remote.refs.push || '';
|
|
63
|
-
const match = url.match(/github\.com[/|:](
|
|
64
|
-
|
|
55
|
+
const match = url.match(/github\.com[/|:](.+)\/(.+)/);
|
|
65
56
|
return {
|
|
66
57
|
name: remote.name,
|
|
67
58
|
url,
|
|
@@ -69,7 +60,6 @@ class StencilRelease {
|
|
|
69
60
|
repo: match ? match[2] : null,
|
|
70
61
|
};
|
|
71
62
|
});
|
|
72
|
-
|
|
73
63
|
const dirty =
|
|
74
64
|
status.not_added.length > 0 ||
|
|
75
65
|
status.conflicted.length > 0 ||
|
|
@@ -77,7 +67,6 @@ class StencilRelease {
|
|
|
77
67
|
status.deleted.length > 0 ||
|
|
78
68
|
status.modified.length > 0 ||
|
|
79
69
|
status.renamed.length > 0;
|
|
80
|
-
|
|
81
70
|
return { dirty, ...status, remotes };
|
|
82
71
|
}
|
|
83
72
|
|
|
@@ -94,21 +83,17 @@ class StencilRelease {
|
|
|
94
83
|
if (gitData.remotes.length === 0) {
|
|
95
84
|
throw new Error('No git remote repository found');
|
|
96
85
|
}
|
|
97
|
-
|
|
98
86
|
if (gitData.current !== options.branch) {
|
|
99
87
|
throw new Error(
|
|
100
88
|
`Not on ${options.branch} branch, please checkout ${options.branch} branch to proceed`,
|
|
101
89
|
);
|
|
102
90
|
}
|
|
103
|
-
|
|
104
91
|
if (gitData.dirty) {
|
|
105
92
|
throw new Error('git tree is dirty, please commit changes to proceed');
|
|
106
93
|
}
|
|
107
|
-
|
|
108
94
|
if (gitData.behind !== 0) {
|
|
109
95
|
throw new Error(`Your branch is behind by ${gitData.behind} commits`);
|
|
110
96
|
}
|
|
111
|
-
|
|
112
97
|
if (gitData.ahead !== 0) {
|
|
113
98
|
this.printWarning(`your branch is ahead by ${gitData.ahead} commits`);
|
|
114
99
|
}
|
|
@@ -126,31 +111,24 @@ class StencilRelease {
|
|
|
126
111
|
|
|
127
112
|
async getGithubToken() {
|
|
128
113
|
const data = (await this._stencilConfigManager.read(true)) || {};
|
|
129
|
-
|
|
130
114
|
return data.githubToken;
|
|
131
115
|
}
|
|
132
116
|
|
|
133
117
|
async saveGithubToken(githubToken) {
|
|
134
118
|
const data = (await this._stencilConfigManager.read(true)) || {};
|
|
135
|
-
|
|
136
119
|
data.githubToken = githubToken;
|
|
137
|
-
|
|
138
120
|
await this._stencilConfigManager.save(data);
|
|
139
121
|
}
|
|
140
122
|
|
|
141
123
|
async doRelease(options) {
|
|
142
124
|
// Update changelog and get text for release notes
|
|
143
125
|
const changelog = await this.parseChangelog(options.version, options.date);
|
|
144
|
-
|
|
145
126
|
await this.bumpJsonFileVersion(this._themeConfigManager.configPath, options.version);
|
|
146
127
|
await this.bumpJsonFileVersion(path.join(THEME_PATH, 'package.json'), options.version);
|
|
147
128
|
await this.bumpJsonFileVersion(path.join(THEME_PATH, 'package-lock.json'), options.version);
|
|
148
|
-
|
|
149
129
|
const bundlePath = await this.bundleTheme();
|
|
150
|
-
|
|
151
130
|
try {
|
|
152
131
|
await this.commitAndPush(options.version, options.remote, options.branch);
|
|
153
|
-
|
|
154
132
|
if (options.createGithubRelease) {
|
|
155
133
|
await this.createGithubRelease(
|
|
156
134
|
options.version,
|
|
@@ -167,27 +145,22 @@ class StencilRelease {
|
|
|
167
145
|
async parseChangelog(version, date) {
|
|
168
146
|
const filePath = path.join(THEME_PATH, 'CHANGELOG.md');
|
|
169
147
|
let changelog = '';
|
|
170
|
-
|
|
171
148
|
try {
|
|
172
149
|
changelog = await this._fs.promises.readFile(filePath, 'utf8');
|
|
173
150
|
} catch (e) {
|
|
174
151
|
// no CHANGELOG file
|
|
175
152
|
return null;
|
|
176
153
|
}
|
|
177
|
-
|
|
178
154
|
const match = changelog.match(/##\s*?draft\s*?\n([\s\S]*?)(##|$)/i);
|
|
179
|
-
|
|
180
155
|
// bump the version and date
|
|
181
156
|
changelog = changelog.replace(
|
|
182
157
|
/##\s*?draft\s*?\n/i,
|
|
183
158
|
`## Draft\n\n## ${version} (${date})\n`,
|
|
184
159
|
);
|
|
185
|
-
|
|
186
160
|
// Update the changelog file if this is a full release
|
|
187
161
|
if (!this.isReleaseCandidate(version)) {
|
|
188
162
|
await this._fs.promises.writeFile(filePath, changelog);
|
|
189
163
|
}
|
|
190
|
-
|
|
191
164
|
return match ? match[1].trim() : null;
|
|
192
165
|
}
|
|
193
166
|
|
|
@@ -197,7 +170,6 @@ class StencilRelease {
|
|
|
197
170
|
|
|
198
171
|
async bumpJsonFileVersion(filePath, version) {
|
|
199
172
|
const data = await this._fsUtils.parseJsonFile(filePath);
|
|
200
|
-
|
|
201
173
|
data.version = version;
|
|
202
174
|
await this._fs.promises.writeFile(filePath, `${JSON.stringify(data, null, 2)}\n`);
|
|
203
175
|
}
|
|
@@ -209,24 +181,19 @@ class StencilRelease {
|
|
|
209
181
|
name: uuid(),
|
|
210
182
|
};
|
|
211
183
|
const bundle = new Bundle(THEME_PATH, this._themeConfigManager, rawConfig, bundleOptions);
|
|
212
|
-
|
|
213
184
|
return bundle.initBundle();
|
|
214
185
|
}
|
|
215
186
|
|
|
216
187
|
async commitAndPush(version, remote, branch) {
|
|
217
188
|
await this._git.add(['config.json', 'package.json', 'package-lock.json', 'CHANGELOG.md']);
|
|
218
189
|
const summary = await this._git.commit(`Releasing ${version}`);
|
|
219
|
-
|
|
220
190
|
this._logger.log(`Pushing Changes to ${remote.name}...`);
|
|
221
|
-
|
|
222
191
|
await this._git.push(remote.name, branch);
|
|
223
|
-
|
|
224
192
|
return summary.commit;
|
|
225
193
|
}
|
|
226
194
|
|
|
227
195
|
async createGithubRelease(version, changelog, remote, bundlePath) {
|
|
228
196
|
const github = await this.getGithubClient();
|
|
229
|
-
|
|
230
197
|
const releaseParams = {
|
|
231
198
|
owner: remote.owner,
|
|
232
199
|
repo: remote.repo,
|
|
@@ -234,14 +201,10 @@ class StencilRelease {
|
|
|
234
201
|
body: changelog || '',
|
|
235
202
|
prerelease: this.isReleaseCandidate(version),
|
|
236
203
|
};
|
|
237
|
-
|
|
238
204
|
this._logger.log('Creating Github Release...');
|
|
239
|
-
|
|
240
205
|
const release = await github.repos.createRelease(releaseParams);
|
|
241
206
|
const themeName = await this._themeConfigManager.getName();
|
|
242
|
-
|
|
243
207
|
this._logger.log('Uploading Bundle File...');
|
|
244
|
-
|
|
245
208
|
const zipFile = await this._fs.promises.readFile(bundlePath);
|
|
246
209
|
const uploadParams = {
|
|
247
210
|
release_id: release.data.id,
|
|
@@ -251,16 +214,14 @@ class StencilRelease {
|
|
|
251
214
|
name: `${themeName}-${version}.zip`,
|
|
252
215
|
};
|
|
253
216
|
const asset = await github.repos.uploadReleaseAsset(uploadParams);
|
|
254
|
-
|
|
255
217
|
this._logger.log(`Release url: ${release.data.html_url.green}`);
|
|
256
218
|
this._logger.log(`Bundle download url: ${asset.data.browser_download_url.green}`);
|
|
257
219
|
}
|
|
258
220
|
|
|
259
221
|
async getGithubClient() {
|
|
260
|
-
return new this._octokit
|
|
222
|
+
return new this._octokit({
|
|
261
223
|
auth: await this.getGithubToken(),
|
|
262
224
|
});
|
|
263
225
|
}
|
|
264
226
|
}
|
|
265
|
-
|
|
266
|
-
module.exports = StencilRelease;
|
|
227
|
+
export default StencilRelease;
|
package/lib/spinner.js
CHANGED
package/lib/stencil-bundle.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const { fetchRegions } = require('./regions');
|
|
1
|
+
import upath from 'upath';
|
|
2
|
+
import Archiver from 'archiver';
|
|
3
|
+
import async from 'async';
|
|
4
|
+
import crypto from 'crypto';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import StencilStyles from '@bigcommerce/stencil-styles';
|
|
8
|
+
import BuildConfigManager from './BuildConfigManager.js';
|
|
9
|
+
import BundleValidator from './bundle-validator.js';
|
|
10
|
+
import Cycles from './Cycles.js';
|
|
11
|
+
import langAssembler from './lang-assembler.js';
|
|
12
|
+
import templateAssembler from './template-assembler.js';
|
|
13
|
+
import { recursiveReadDir } from './utils/fsUtils.js';
|
|
14
|
+
import { fetchRegions } from './regions.js';
|
|
16
15
|
|
|
17
16
|
const MEGABYTE = 1024 * 1024;
|
|
18
17
|
const MAX_SIZE_BUNDLE = MEGABYTE * 50;
|
|
@@ -49,27 +48,22 @@ class Bundle {
|
|
|
49
48
|
) {
|
|
50
49
|
const tasks = {};
|
|
51
50
|
this.options = options;
|
|
52
|
-
|
|
53
51
|
this.templatesPath = path.join(themePath, 'templates');
|
|
54
52
|
this.themePath = themePath;
|
|
55
53
|
this.themeConfig = themeConfig;
|
|
56
54
|
this.configuration = rawConfig;
|
|
57
|
-
|
|
58
55
|
this.validator = new BundleValidator(
|
|
59
56
|
this.themePath,
|
|
60
57
|
this.themeConfig,
|
|
61
58
|
this.options.marketplace !== true,
|
|
62
59
|
);
|
|
63
|
-
|
|
64
60
|
if (this.configuration.css_compiler) {
|
|
65
61
|
tasks.css = this.getCssAssembleTask(this.configuration.css_compiler);
|
|
66
62
|
}
|
|
67
|
-
|
|
68
63
|
tasks.templates = this.assembleTemplatesTask.bind(this);
|
|
69
64
|
tasks.lang = this.assembleLangTask.bind(this);
|
|
70
65
|
tasks.schema = this.assembleSchema.bind(this);
|
|
71
66
|
tasks.schemaTranslations = this.assembleSchemaTranslations.bind(this);
|
|
72
|
-
|
|
73
67
|
if (typeof buildConfigManager.production === 'function') {
|
|
74
68
|
tasks.theme = (callback) => {
|
|
75
69
|
console.log('Theme task Started...');
|
|
@@ -77,16 +71,12 @@ class Bundle {
|
|
|
77
71
|
if (err) {
|
|
78
72
|
return callback(err);
|
|
79
73
|
}
|
|
80
|
-
|
|
81
74
|
console.log(`${'ok'.green} -- Theme task Finished`);
|
|
82
|
-
|
|
83
75
|
return callback();
|
|
84
76
|
});
|
|
85
77
|
};
|
|
86
78
|
}
|
|
87
|
-
|
|
88
79
|
this.tasks = tasks;
|
|
89
|
-
|
|
90
80
|
this._getExternalLibs = this._getExternalLibs.bind(this);
|
|
91
81
|
}
|
|
92
82
|
|
|
@@ -120,7 +110,6 @@ class Bundle {
|
|
|
120
110
|
} else {
|
|
121
111
|
basePath = path.join(this.themePath, 'assets', compiler);
|
|
122
112
|
}
|
|
123
|
-
|
|
124
113
|
console.log('%s Parsing Started...', compiler.toUpperCase());
|
|
125
114
|
fs.readdir(basePath, (err, files) => {
|
|
126
115
|
const filterFiles = files.filter((file) => {
|
|
@@ -141,11 +130,9 @@ class Bundle {
|
|
|
141
130
|
if (assemblingError) {
|
|
142
131
|
return callback(assemblingError);
|
|
143
132
|
}
|
|
144
|
-
|
|
145
133
|
filterFiles.forEach((file, index) => {
|
|
146
134
|
ret[file] = results[index];
|
|
147
135
|
});
|
|
148
|
-
|
|
149
136
|
console.log(`${'ok'.green} -- %s Parsing Finished`, compiler.toUpperCase());
|
|
150
137
|
return callback(null, ret);
|
|
151
138
|
},
|
|
@@ -166,14 +153,10 @@ class Bundle {
|
|
|
166
153
|
const content = await fs.promises.readFile(templatePath, { encoding: 'utf-8' });
|
|
167
154
|
const externalPathRegex = /{{2}>\s*(['"]external)[^{]*?}{2}/g;
|
|
168
155
|
const externalTemplatesImports = content.match(externalPathRegex);
|
|
169
|
-
|
|
170
156
|
if (!externalTemplatesImports) return [];
|
|
171
|
-
|
|
172
157
|
return externalTemplatesImports.map((templateImport) => {
|
|
173
158
|
const [, importPath] = templateAssembler.partialRegex.exec(templateImport);
|
|
174
|
-
|
|
175
159
|
templateAssembler.partialRegex.lastIndex = 0;
|
|
176
|
-
|
|
177
160
|
return importPath
|
|
178
161
|
.split('/templates/')[0]
|
|
179
162
|
.slice(templateAssembler.packageMarker.length + 1);
|
|
@@ -184,17 +167,14 @@ class Bundle {
|
|
|
184
167
|
console.log('Template Parsing Started...');
|
|
185
168
|
const internalTemplatesList = await recursiveReadDir(this.templatesPath, ['!*.html']);
|
|
186
169
|
let externalLibs;
|
|
187
|
-
|
|
188
170
|
try {
|
|
189
171
|
const removeDuplicates = (arr) => Array.from(new Set(arr.flat()));
|
|
190
172
|
const temp = internalTemplatesList.map(this._getExternalLibs);
|
|
191
173
|
const result = await Promise.all(temp);
|
|
192
|
-
|
|
193
174
|
externalLibs = removeDuplicates(result);
|
|
194
175
|
} catch (error) {
|
|
195
176
|
callback(error);
|
|
196
177
|
}
|
|
197
|
-
|
|
198
178
|
let externalLibPaths = [];
|
|
199
179
|
if (externalLibs.length) {
|
|
200
180
|
externalLibPaths = externalLibs.map((lib) =>
|
|
@@ -222,33 +202,26 @@ class Bundle {
|
|
|
222
202
|
);
|
|
223
203
|
});
|
|
224
204
|
partials.push(...extractedPartials);
|
|
225
|
-
|
|
226
205
|
return partials;
|
|
227
206
|
},
|
|
228
207
|
[],
|
|
229
208
|
);
|
|
230
209
|
const allPartials = [...externalPartials, ...internalPartials];
|
|
231
|
-
|
|
232
210
|
let results;
|
|
233
211
|
try {
|
|
234
212
|
results = await async.map(
|
|
235
213
|
allPartials,
|
|
236
214
|
templateAssembler.assembleAndBundle.bind(null, this.templatesPath),
|
|
237
215
|
);
|
|
238
|
-
|
|
239
216
|
const ret = {};
|
|
240
|
-
|
|
241
217
|
allPartials.forEach((file, index) => {
|
|
242
218
|
ret[file] = results[index];
|
|
243
219
|
});
|
|
244
|
-
|
|
245
220
|
await Promise.all([
|
|
246
221
|
this._checkObjects.bind(this, results),
|
|
247
222
|
this._detectCycles.bind(this, results),
|
|
248
223
|
]);
|
|
249
|
-
|
|
250
224
|
console.log(`${'ok'.green} -- Template Parsing Finished`);
|
|
251
|
-
|
|
252
225
|
return ret;
|
|
253
226
|
} catch (err) {
|
|
254
227
|
return callback(err);
|
|
@@ -257,21 +230,15 @@ class Bundle {
|
|
|
257
230
|
|
|
258
231
|
async assembleSchema() {
|
|
259
232
|
console.log('Building Theme Schema File...');
|
|
260
|
-
|
|
261
233
|
const schema = await this.themeConfig.getSchema();
|
|
262
|
-
|
|
263
234
|
console.log(`${'ok'.green} -- Theme Schema Building Finished`);
|
|
264
|
-
|
|
265
235
|
return schema;
|
|
266
236
|
}
|
|
267
237
|
|
|
268
238
|
async assembleSchemaTranslations() {
|
|
269
239
|
console.log('Schema Translations Parsing Started...');
|
|
270
|
-
|
|
271
240
|
const schema = await this.themeConfig.getSchemaTranslations();
|
|
272
|
-
|
|
273
241
|
console.log(`${'ok'.green} -- Schema Translations Parsing Finished`);
|
|
274
|
-
|
|
275
242
|
return schema;
|
|
276
243
|
}
|
|
277
244
|
|
|
@@ -281,7 +248,6 @@ class Bundle {
|
|
|
281
248
|
if (err) {
|
|
282
249
|
return callback(err);
|
|
283
250
|
}
|
|
284
|
-
|
|
285
251
|
console.log(`${'ok'.green} -- Language Files Parsing Finished`);
|
|
286
252
|
return callback(null, results);
|
|
287
253
|
});
|
|
@@ -289,20 +255,16 @@ class Bundle {
|
|
|
289
255
|
|
|
290
256
|
generateManifest(taskResults, callback) {
|
|
291
257
|
console.log('Generating Manifest Started...');
|
|
292
|
-
|
|
293
258
|
recursiveReadDir(this.templatesPath, ['!*.html'], (err, filePaths) => {
|
|
294
259
|
if (err) {
|
|
295
260
|
return callback(err);
|
|
296
261
|
}
|
|
297
|
-
|
|
298
262
|
const templates = filePaths.map((file) => {
|
|
299
263
|
return upath.toUnix(
|
|
300
264
|
file.replace(this.templatesPath + path.sep, '').replace('.html', ''),
|
|
301
265
|
);
|
|
302
266
|
});
|
|
303
|
-
|
|
304
267
|
const regions = fetchRegions(taskResults.templates, templates);
|
|
305
|
-
|
|
306
268
|
console.log(`${'ok'.green} -- Manifest Generation Finished`);
|
|
307
269
|
return callback(null, {
|
|
308
270
|
regions,
|
|
@@ -323,7 +285,6 @@ class Bundle {
|
|
|
323
285
|
console.error('error '.red + err.message);
|
|
324
286
|
return callback(err);
|
|
325
287
|
}
|
|
326
|
-
|
|
327
288
|
return callback();
|
|
328
289
|
});
|
|
329
290
|
}
|
|
@@ -350,7 +311,6 @@ class Bundle {
|
|
|
350
311
|
*/
|
|
351
312
|
_validateTheme(callback) {
|
|
352
313
|
console.log('Validating theme...');
|
|
353
|
-
|
|
354
314
|
this.validator.validateTheme((err) => {
|
|
355
315
|
if (err) {
|
|
356
316
|
throw err;
|
|
@@ -373,34 +333,27 @@ class Bundle {
|
|
|
373
333
|
const outputFolder =
|
|
374
334
|
typeof this.options.dest === 'string' ? this.options.dest : this.themePath;
|
|
375
335
|
const bundleZipPath = path.join(outputFolder, outputName);
|
|
376
|
-
|
|
377
336
|
this.tasks.templates = this.assembleTemplatesTask.bind(this, callback);
|
|
378
|
-
|
|
379
337
|
async
|
|
380
338
|
.parallel(this.tasks)
|
|
381
339
|
.then((taskResults) => {
|
|
382
340
|
const archive = Archiver('zip');
|
|
383
341
|
const fileStream = fs.createWriteStream(bundleZipPath);
|
|
384
342
|
archive.pipe(fileStream);
|
|
385
|
-
|
|
386
343
|
// Create manifest will use taskResults to generate a manifest file
|
|
387
344
|
return this.generateManifest(taskResults, (manifestGenerationError, manifest) => {
|
|
388
345
|
if (manifestGenerationError) {
|
|
389
346
|
return callback(manifestGenerationError);
|
|
390
347
|
}
|
|
391
|
-
|
|
392
348
|
// eslint-disable-next-line no-param-reassign
|
|
393
349
|
taskResults.manifest = manifest;
|
|
394
350
|
// zip theme files
|
|
395
351
|
this._bundleThemeFiles(archive, this.themePath);
|
|
396
|
-
|
|
397
352
|
// zip all generated files
|
|
398
353
|
const failedTemplates = this._bundleParsedFiles(archive, taskResults);
|
|
399
|
-
|
|
400
354
|
fileStream.on('close', () => {
|
|
401
355
|
const stats = fs.statSync(bundleZipPath);
|
|
402
356
|
const { size } = stats;
|
|
403
|
-
|
|
404
357
|
if (failedTemplates.length) {
|
|
405
358
|
return console.error(
|
|
406
359
|
`Error: Your bundle failed as templates generated from the files below are greater than or equal to 1 megabyte in size:\n${failedTemplates.join(
|
|
@@ -408,18 +361,14 @@ class Bundle {
|
|
|
408
361
|
)}`,
|
|
409
362
|
);
|
|
410
363
|
}
|
|
411
|
-
|
|
412
364
|
if (size > MAX_SIZE_BUNDLE) {
|
|
413
365
|
return console.error(
|
|
414
366
|
`Error: Your bundle of size ${size} bytes is above the max size of ${MAX_SIZE_BUNDLE} bytes`,
|
|
415
367
|
);
|
|
416
368
|
}
|
|
417
|
-
|
|
418
369
|
console.log(`${'ok'.green} -- Zipping Files Finished`);
|
|
419
|
-
|
|
420
370
|
return callback(null, bundleZipPath);
|
|
421
371
|
});
|
|
422
|
-
|
|
423
372
|
// This triggers 'close' event in the file stream. No need to callback()
|
|
424
373
|
return archive.finalize();
|
|
425
374
|
});
|
|
@@ -454,7 +403,6 @@ class Bundle {
|
|
|
454
403
|
archive.append(JSON.stringify(data, null, 2), { name });
|
|
455
404
|
};
|
|
456
405
|
const failedTemplates = [];
|
|
457
|
-
|
|
458
406
|
for (const [task, result] of Object.entries(taskResults)) {
|
|
459
407
|
switch (task) {
|
|
460
408
|
case 'css':
|
|
@@ -464,11 +412,9 @@ class Bundle {
|
|
|
464
412
|
this.configuration.css_compiler === 'css'
|
|
465
413
|
? this.configuration.css_compiler
|
|
466
414
|
: 'scss';
|
|
467
|
-
|
|
468
415
|
archiveJsonFile(data, `parsed/${ext}/${filename}.json`);
|
|
469
416
|
}
|
|
470
417
|
break;
|
|
471
|
-
|
|
472
418
|
case 'templates':
|
|
473
419
|
// Create the parsed tree files
|
|
474
420
|
for (const [filename, data] of Object.entries(result)) {
|
|
@@ -481,27 +427,22 @@ class Bundle {
|
|
|
481
427
|
}
|
|
482
428
|
}
|
|
483
429
|
break;
|
|
484
|
-
|
|
485
430
|
case 'lang':
|
|
486
431
|
// append the parsed translation file with all translations
|
|
487
432
|
archiveJsonFile(result, 'parsed/lang.json');
|
|
488
433
|
break;
|
|
489
|
-
|
|
490
434
|
case 'schema':
|
|
491
435
|
// append the generated schema.json file
|
|
492
436
|
archiveJsonFile(result, 'schema.json');
|
|
493
437
|
break;
|
|
494
|
-
|
|
495
438
|
case 'schemaTranslations':
|
|
496
439
|
// append the parsed schemaTranslations.json file
|
|
497
440
|
archiveJsonFile(result, 'schemaTranslations.json');
|
|
498
441
|
break;
|
|
499
|
-
|
|
500
442
|
case 'manifest':
|
|
501
443
|
// append the generated manifest.json file
|
|
502
444
|
archiveJsonFile(result, 'manifest.json');
|
|
503
445
|
break;
|
|
504
|
-
|
|
505
446
|
default:
|
|
506
447
|
break;
|
|
507
448
|
}
|
|
@@ -509,5 +450,4 @@ class Bundle {
|
|
|
509
450
|
return failedTemplates;
|
|
510
451
|
}
|
|
511
452
|
}
|
|
512
|
-
|
|
513
|
-
module.exports = Bundle;
|
|
453
|
+
export default Bundle;
|
package/lib/stencil-download.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import async from 'async';
|
|
2
|
+
import stencilPushUtils from './stencil-push.utils.js';
|
|
3
|
+
import stencilPullUtils from './stencil-pull.utils.js';
|
|
4
|
+
import stencilDownloadUtil from './stencil-download.utils.js';
|
|
5
5
|
|
|
6
6
|
function stencilDownload(options) {
|
|
7
7
|
return async.waterfall([
|
|
@@ -16,5 +16,4 @@ function stencilDownload(options) {
|
|
|
16
16
|
stencilDownloadUtil.downloadThemeFiles,
|
|
17
17
|
]);
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
module.exports = stencilDownload;
|
|
19
|
+
export default stencilDownload;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import * as tmp from 'tmp-promise';
|
|
2
|
+
import { extractZipFiles } from './archiveManager.js';
|
|
3
|
+
import NetworkUtils from './utils/NetworkUtils.js';
|
|
4
|
+
import themeApiClient from './theme-api-client.js';
|
|
5
5
|
|
|
6
6
|
const networkUtils = new NetworkUtils();
|
|
7
|
-
|
|
8
7
|
const utils = {};
|
|
9
|
-
|
|
10
8
|
utils.downloadThemeFiles = async (options) => {
|
|
11
9
|
const { path: tempThemePath, cleanup } = await tmp.file();
|
|
12
|
-
|
|
13
10
|
try {
|
|
14
11
|
await networkUtils.fetchFile(options.downloadUrl, tempThemePath);
|
|
15
12
|
} catch (err) {
|
|
@@ -17,43 +14,33 @@ utils.downloadThemeFiles = async (options) => {
|
|
|
17
14
|
`Unable to download theme files from ${options.downloadUrl}: ${err.message}`,
|
|
18
15
|
);
|
|
19
16
|
}
|
|
20
|
-
|
|
21
17
|
console.log(`${'ok'.green} -- Theme files downloaded`);
|
|
22
18
|
console.log(`${'ok'.green} -- Extracting theme files`);
|
|
23
|
-
|
|
24
19
|
await extractZipFiles({
|
|
25
20
|
zipPath: tempThemePath,
|
|
26
21
|
fileToExtract: options.file,
|
|
27
22
|
exclude: options.exclude,
|
|
28
23
|
});
|
|
29
|
-
|
|
30
24
|
console.log(`${'ok'.green} -- Theme files extracted`);
|
|
31
|
-
|
|
32
25
|
await cleanup();
|
|
33
|
-
|
|
34
26
|
return options;
|
|
35
27
|
};
|
|
36
|
-
|
|
37
28
|
utils.startThemeDownloadJob = async (options) => {
|
|
38
29
|
const {
|
|
39
30
|
config: { accessToken },
|
|
40
31
|
activeTheme,
|
|
41
32
|
storeHash,
|
|
42
33
|
} = options;
|
|
43
|
-
|
|
44
34
|
const apiHost = options.apiHost || options.config.apiHost;
|
|
45
|
-
|
|
46
35
|
const { jobId } = await themeApiClient.downloadTheme({
|
|
47
36
|
accessToken,
|
|
48
37
|
themeId: activeTheme.active_theme_uuid,
|
|
49
38
|
apiHost,
|
|
50
39
|
storeHash,
|
|
51
40
|
});
|
|
52
|
-
|
|
53
41
|
return {
|
|
54
42
|
...options,
|
|
55
43
|
jobId,
|
|
56
44
|
};
|
|
57
45
|
};
|
|
58
|
-
|
|
59
|
-
module.exports = utils;
|
|
46
|
+
export default utils;
|