@bigcommerce/stencil-cli 8.2.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 +5 -11
- 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 +19 -78
- 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 +12 -9
- 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/css-assembler.js +0 -99
package/lib/release/questions.js
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import semver from 'semver';
|
|
3
3
|
|
|
4
4
|
const dateFormatOptions = {
|
|
5
5
|
year: 'numeric',
|
|
6
6
|
month: '2-digit',
|
|
7
7
|
day: '2-digit',
|
|
8
8
|
};
|
|
9
|
-
|
|
10
9
|
async function askQuestions(currentVersion, githubToken, remotes) {
|
|
11
10
|
const remoteChoices = remotes.map((remote) => {
|
|
12
11
|
return { value: remote, name: `${remote.name}: ${remote.url}` };
|
|
13
12
|
});
|
|
14
|
-
|
|
15
13
|
const nextPatchVersion = semver.inc(currentVersion, 'patch');
|
|
16
14
|
const nextMinorVersion = semver.inc(currentVersion, 'minor');
|
|
17
15
|
const nextMajorVersion = semver.inc(currentVersion, 'major');
|
|
18
16
|
const nextReleaseCandidate = currentVersion.includes('-rc.')
|
|
19
17
|
? semver.inc(currentVersion, 'prerelease', 'rc')
|
|
20
18
|
: `${nextMinorVersion}-rc.1`;
|
|
21
|
-
|
|
22
19
|
const questions = [
|
|
23
20
|
{
|
|
24
21
|
name: 'version',
|
|
@@ -67,7 +64,6 @@ async function askQuestions(currentVersion, githubToken, remotes) {
|
|
|
67
64
|
when: (answers) => answers.version === 'custom',
|
|
68
65
|
validate: (value) => {
|
|
69
66
|
const valid = semver.valid(value) && true;
|
|
70
|
-
|
|
71
67
|
return valid || 'Must be a valid semver, such as 1.2.3';
|
|
72
68
|
},
|
|
73
69
|
},
|
|
@@ -97,18 +93,12 @@ async function askQuestions(currentVersion, githubToken, remotes) {
|
|
|
97
93
|
message: 'Proceed?',
|
|
98
94
|
},
|
|
99
95
|
];
|
|
100
|
-
|
|
101
96
|
const answers = await inquirer.prompt(questions);
|
|
102
|
-
|
|
103
97
|
if (!answers.proceed) {
|
|
104
98
|
throw new Error('Operation cancelled');
|
|
105
99
|
}
|
|
106
|
-
|
|
107
100
|
answers.githubToken = answers.githubToken || githubToken;
|
|
108
|
-
|
|
109
101
|
answers.date = new Date().toLocaleString('en-US', dateFormatOptions).split('/').join('-');
|
|
110
|
-
|
|
111
102
|
return answers;
|
|
112
103
|
}
|
|
113
|
-
|
|
114
|
-
module.exports = askQuestions;
|
|
104
|
+
export default askQuestions;
|
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;
|
|
@@ -37,6 +36,8 @@ const PATHS_TO_ZIP = [
|
|
|
37
36
|
{ pattern: 'webpack.*.js' },
|
|
38
37
|
];
|
|
39
38
|
|
|
39
|
+
const stencilStyles = new StencilStyles();
|
|
40
|
+
|
|
40
41
|
class Bundle {
|
|
41
42
|
constructor(
|
|
42
43
|
themePath,
|
|
@@ -47,27 +48,22 @@ class Bundle {
|
|
|
47
48
|
) {
|
|
48
49
|
const tasks = {};
|
|
49
50
|
this.options = options;
|
|
50
|
-
|
|
51
51
|
this.templatesPath = path.join(themePath, 'templates');
|
|
52
52
|
this.themePath = themePath;
|
|
53
53
|
this.themeConfig = themeConfig;
|
|
54
54
|
this.configuration = rawConfig;
|
|
55
|
-
|
|
56
55
|
this.validator = new BundleValidator(
|
|
57
56
|
this.themePath,
|
|
58
57
|
this.themeConfig,
|
|
59
58
|
this.options.marketplace !== true,
|
|
60
59
|
);
|
|
61
|
-
|
|
62
60
|
if (this.configuration.css_compiler) {
|
|
63
61
|
tasks.css = this.getCssAssembleTask(this.configuration.css_compiler);
|
|
64
62
|
}
|
|
65
|
-
|
|
66
63
|
tasks.templates = this.assembleTemplatesTask.bind(this);
|
|
67
64
|
tasks.lang = this.assembleLangTask.bind(this);
|
|
68
65
|
tasks.schema = this.assembleSchema.bind(this);
|
|
69
66
|
tasks.schemaTranslations = this.assembleSchemaTranslations.bind(this);
|
|
70
|
-
|
|
71
67
|
if (typeof buildConfigManager.production === 'function') {
|
|
72
68
|
tasks.theme = (callback) => {
|
|
73
69
|
console.log('Theme task Started...');
|
|
@@ -75,16 +71,12 @@ class Bundle {
|
|
|
75
71
|
if (err) {
|
|
76
72
|
return callback(err);
|
|
77
73
|
}
|
|
78
|
-
|
|
79
74
|
console.log(`${'ok'.green} -- Theme task Finished`);
|
|
80
|
-
|
|
81
75
|
return callback();
|
|
82
76
|
});
|
|
83
77
|
};
|
|
84
78
|
}
|
|
85
|
-
|
|
86
79
|
this.tasks = tasks;
|
|
87
|
-
|
|
88
80
|
this._getExternalLibs = this._getExternalLibs.bind(this);
|
|
89
81
|
}
|
|
90
82
|
|
|
@@ -118,7 +110,6 @@ class Bundle {
|
|
|
118
110
|
} else {
|
|
119
111
|
basePath = path.join(this.themePath, 'assets', compiler);
|
|
120
112
|
}
|
|
121
|
-
|
|
122
113
|
console.log('%s Parsing Started...', compiler.toUpperCase());
|
|
123
114
|
fs.readdir(basePath, (err, files) => {
|
|
124
115
|
const filterFiles = files.filter((file) => {
|
|
@@ -126,13 +117,12 @@ class Bundle {
|
|
|
126
117
|
});
|
|
127
118
|
async.map(
|
|
128
119
|
filterFiles,
|
|
129
|
-
(file
|
|
130
|
-
|
|
120
|
+
async (file) => {
|
|
121
|
+
return stencilStyles.assembleCssFiles(
|
|
131
122
|
file,
|
|
132
123
|
basePath,
|
|
133
124
|
compiler,
|
|
134
125
|
assembleOptions,
|
|
135
|
-
mapCallback,
|
|
136
126
|
);
|
|
137
127
|
},
|
|
138
128
|
(assemblingError, results) => {
|
|
@@ -140,11 +130,9 @@ class Bundle {
|
|
|
140
130
|
if (assemblingError) {
|
|
141
131
|
return callback(assemblingError);
|
|
142
132
|
}
|
|
143
|
-
|
|
144
133
|
filterFiles.forEach((file, index) => {
|
|
145
134
|
ret[file] = results[index];
|
|
146
135
|
});
|
|
147
|
-
|
|
148
136
|
console.log(`${'ok'.green} -- %s Parsing Finished`, compiler.toUpperCase());
|
|
149
137
|
return callback(null, ret);
|
|
150
138
|
},
|
|
@@ -165,14 +153,10 @@ class Bundle {
|
|
|
165
153
|
const content = await fs.promises.readFile(templatePath, { encoding: 'utf-8' });
|
|
166
154
|
const externalPathRegex = /{{2}>\s*(['"]external)[^{]*?}{2}/g;
|
|
167
155
|
const externalTemplatesImports = content.match(externalPathRegex);
|
|
168
|
-
|
|
169
156
|
if (!externalTemplatesImports) return [];
|
|
170
|
-
|
|
171
157
|
return externalTemplatesImports.map((templateImport) => {
|
|
172
158
|
const [, importPath] = templateAssembler.partialRegex.exec(templateImport);
|
|
173
|
-
|
|
174
159
|
templateAssembler.partialRegex.lastIndex = 0;
|
|
175
|
-
|
|
176
160
|
return importPath
|
|
177
161
|
.split('/templates/')[0]
|
|
178
162
|
.slice(templateAssembler.packageMarker.length + 1);
|
|
@@ -183,17 +167,14 @@ class Bundle {
|
|
|
183
167
|
console.log('Template Parsing Started...');
|
|
184
168
|
const internalTemplatesList = await recursiveReadDir(this.templatesPath, ['!*.html']);
|
|
185
169
|
let externalLibs;
|
|
186
|
-
|
|
187
170
|
try {
|
|
188
171
|
const removeDuplicates = (arr) => Array.from(new Set(arr.flat()));
|
|
189
172
|
const temp = internalTemplatesList.map(this._getExternalLibs);
|
|
190
173
|
const result = await Promise.all(temp);
|
|
191
|
-
|
|
192
174
|
externalLibs = removeDuplicates(result);
|
|
193
175
|
} catch (error) {
|
|
194
176
|
callback(error);
|
|
195
177
|
}
|
|
196
|
-
|
|
197
178
|
let externalLibPaths = [];
|
|
198
179
|
if (externalLibs.length) {
|
|
199
180
|
externalLibPaths = externalLibs.map((lib) =>
|
|
@@ -221,33 +202,26 @@ class Bundle {
|
|
|
221
202
|
);
|
|
222
203
|
});
|
|
223
204
|
partials.push(...extractedPartials);
|
|
224
|
-
|
|
225
205
|
return partials;
|
|
226
206
|
},
|
|
227
207
|
[],
|
|
228
208
|
);
|
|
229
209
|
const allPartials = [...externalPartials, ...internalPartials];
|
|
230
|
-
|
|
231
210
|
let results;
|
|
232
211
|
try {
|
|
233
212
|
results = await async.map(
|
|
234
213
|
allPartials,
|
|
235
214
|
templateAssembler.assembleAndBundle.bind(null, this.templatesPath),
|
|
236
215
|
);
|
|
237
|
-
|
|
238
216
|
const ret = {};
|
|
239
|
-
|
|
240
217
|
allPartials.forEach((file, index) => {
|
|
241
218
|
ret[file] = results[index];
|
|
242
219
|
});
|
|
243
|
-
|
|
244
220
|
await Promise.all([
|
|
245
221
|
this._checkObjects.bind(this, results),
|
|
246
222
|
this._detectCycles.bind(this, results),
|
|
247
223
|
]);
|
|
248
|
-
|
|
249
224
|
console.log(`${'ok'.green} -- Template Parsing Finished`);
|
|
250
|
-
|
|
251
225
|
return ret;
|
|
252
226
|
} catch (err) {
|
|
253
227
|
return callback(err);
|
|
@@ -256,21 +230,15 @@ class Bundle {
|
|
|
256
230
|
|
|
257
231
|
async assembleSchema() {
|
|
258
232
|
console.log('Building Theme Schema File...');
|
|
259
|
-
|
|
260
233
|
const schema = await this.themeConfig.getSchema();
|
|
261
|
-
|
|
262
234
|
console.log(`${'ok'.green} -- Theme Schema Building Finished`);
|
|
263
|
-
|
|
264
235
|
return schema;
|
|
265
236
|
}
|
|
266
237
|
|
|
267
238
|
async assembleSchemaTranslations() {
|
|
268
239
|
console.log('Schema Translations Parsing Started...');
|
|
269
|
-
|
|
270
240
|
const schema = await this.themeConfig.getSchemaTranslations();
|
|
271
|
-
|
|
272
241
|
console.log(`${'ok'.green} -- Schema Translations Parsing Finished`);
|
|
273
|
-
|
|
274
242
|
return schema;
|
|
275
243
|
}
|
|
276
244
|
|
|
@@ -280,7 +248,6 @@ class Bundle {
|
|
|
280
248
|
if (err) {
|
|
281
249
|
return callback(err);
|
|
282
250
|
}
|
|
283
|
-
|
|
284
251
|
console.log(`${'ok'.green} -- Language Files Parsing Finished`);
|
|
285
252
|
return callback(null, results);
|
|
286
253
|
});
|
|
@@ -288,20 +255,16 @@ class Bundle {
|
|
|
288
255
|
|
|
289
256
|
generateManifest(taskResults, callback) {
|
|
290
257
|
console.log('Generating Manifest Started...');
|
|
291
|
-
|
|
292
258
|
recursiveReadDir(this.templatesPath, ['!*.html'], (err, filePaths) => {
|
|
293
259
|
if (err) {
|
|
294
260
|
return callback(err);
|
|
295
261
|
}
|
|
296
|
-
|
|
297
262
|
const templates = filePaths.map((file) => {
|
|
298
263
|
return upath.toUnix(
|
|
299
264
|
file.replace(this.templatesPath + path.sep, '').replace('.html', ''),
|
|
300
265
|
);
|
|
301
266
|
});
|
|
302
|
-
|
|
303
267
|
const regions = fetchRegions(taskResults.templates, templates);
|
|
304
|
-
|
|
305
268
|
console.log(`${'ok'.green} -- Manifest Generation Finished`);
|
|
306
269
|
return callback(null, {
|
|
307
270
|
regions,
|
|
@@ -322,7 +285,6 @@ class Bundle {
|
|
|
322
285
|
console.error('error '.red + err.message);
|
|
323
286
|
return callback(err);
|
|
324
287
|
}
|
|
325
|
-
|
|
326
288
|
return callback();
|
|
327
289
|
});
|
|
328
290
|
}
|
|
@@ -349,7 +311,6 @@ class Bundle {
|
|
|
349
311
|
*/
|
|
350
312
|
_validateTheme(callback) {
|
|
351
313
|
console.log('Validating theme...');
|
|
352
|
-
|
|
353
314
|
this.validator.validateTheme((err) => {
|
|
354
315
|
if (err) {
|
|
355
316
|
throw err;
|
|
@@ -372,34 +333,27 @@ class Bundle {
|
|
|
372
333
|
const outputFolder =
|
|
373
334
|
typeof this.options.dest === 'string' ? this.options.dest : this.themePath;
|
|
374
335
|
const bundleZipPath = path.join(outputFolder, outputName);
|
|
375
|
-
|
|
376
336
|
this.tasks.templates = this.assembleTemplatesTask.bind(this, callback);
|
|
377
|
-
|
|
378
337
|
async
|
|
379
338
|
.parallel(this.tasks)
|
|
380
339
|
.then((taskResults) => {
|
|
381
340
|
const archive = Archiver('zip');
|
|
382
341
|
const fileStream = fs.createWriteStream(bundleZipPath);
|
|
383
342
|
archive.pipe(fileStream);
|
|
384
|
-
|
|
385
343
|
// Create manifest will use taskResults to generate a manifest file
|
|
386
344
|
return this.generateManifest(taskResults, (manifestGenerationError, manifest) => {
|
|
387
345
|
if (manifestGenerationError) {
|
|
388
346
|
return callback(manifestGenerationError);
|
|
389
347
|
}
|
|
390
|
-
|
|
391
348
|
// eslint-disable-next-line no-param-reassign
|
|
392
349
|
taskResults.manifest = manifest;
|
|
393
350
|
// zip theme files
|
|
394
351
|
this._bundleThemeFiles(archive, this.themePath);
|
|
395
|
-
|
|
396
352
|
// zip all generated files
|
|
397
353
|
const failedTemplates = this._bundleParsedFiles(archive, taskResults);
|
|
398
|
-
|
|
399
354
|
fileStream.on('close', () => {
|
|
400
355
|
const stats = fs.statSync(bundleZipPath);
|
|
401
356
|
const { size } = stats;
|
|
402
|
-
|
|
403
357
|
if (failedTemplates.length) {
|
|
404
358
|
return console.error(
|
|
405
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(
|
|
@@ -407,18 +361,14 @@ class Bundle {
|
|
|
407
361
|
)}`,
|
|
408
362
|
);
|
|
409
363
|
}
|
|
410
|
-
|
|
411
364
|
if (size > MAX_SIZE_BUNDLE) {
|
|
412
365
|
return console.error(
|
|
413
366
|
`Error: Your bundle of size ${size} bytes is above the max size of ${MAX_SIZE_BUNDLE} bytes`,
|
|
414
367
|
);
|
|
415
368
|
}
|
|
416
|
-
|
|
417
369
|
console.log(`${'ok'.green} -- Zipping Files Finished`);
|
|
418
|
-
|
|
419
370
|
return callback(null, bundleZipPath);
|
|
420
371
|
});
|
|
421
|
-
|
|
422
372
|
// This triggers 'close' event in the file stream. No need to callback()
|
|
423
373
|
return archive.finalize();
|
|
424
374
|
});
|
|
@@ -453,7 +403,6 @@ class Bundle {
|
|
|
453
403
|
archive.append(JSON.stringify(data, null, 2), { name });
|
|
454
404
|
};
|
|
455
405
|
const failedTemplates = [];
|
|
456
|
-
|
|
457
406
|
for (const [task, result] of Object.entries(taskResults)) {
|
|
458
407
|
switch (task) {
|
|
459
408
|
case 'css':
|
|
@@ -463,11 +412,9 @@ class Bundle {
|
|
|
463
412
|
this.configuration.css_compiler === 'css'
|
|
464
413
|
? this.configuration.css_compiler
|
|
465
414
|
: 'scss';
|
|
466
|
-
|
|
467
415
|
archiveJsonFile(data, `parsed/${ext}/${filename}.json`);
|
|
468
416
|
}
|
|
469
417
|
break;
|
|
470
|
-
|
|
471
418
|
case 'templates':
|
|
472
419
|
// Create the parsed tree files
|
|
473
420
|
for (const [filename, data] of Object.entries(result)) {
|
|
@@ -480,27 +427,22 @@ class Bundle {
|
|
|
480
427
|
}
|
|
481
428
|
}
|
|
482
429
|
break;
|
|
483
|
-
|
|
484
430
|
case 'lang':
|
|
485
431
|
// append the parsed translation file with all translations
|
|
486
432
|
archiveJsonFile(result, 'parsed/lang.json');
|
|
487
433
|
break;
|
|
488
|
-
|
|
489
434
|
case 'schema':
|
|
490
435
|
// append the generated schema.json file
|
|
491
436
|
archiveJsonFile(result, 'schema.json');
|
|
492
437
|
break;
|
|
493
|
-
|
|
494
438
|
case 'schemaTranslations':
|
|
495
439
|
// append the parsed schemaTranslations.json file
|
|
496
440
|
archiveJsonFile(result, 'schemaTranslations.json');
|
|
497
441
|
break;
|
|
498
|
-
|
|
499
442
|
case 'manifest':
|
|
500
443
|
// append the generated manifest.json file
|
|
501
444
|
archiveJsonFile(result, 'manifest.json');
|
|
502
445
|
break;
|
|
503
|
-
|
|
504
446
|
default:
|
|
505
447
|
break;
|
|
506
448
|
}
|
|
@@ -508,5 +450,4 @@ class Bundle {
|
|
|
508
450
|
return failedTemplates;
|
|
509
451
|
}
|
|
510
452
|
}
|
|
511
|
-
|
|
512
|
-
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;
|