Skip to content

Commit 9a6fb16

Browse files
authored
fix(service): fix models for create command (#33)
1 parent ffd46a1 commit 9a6fb16

File tree

8 files changed

+1162
-933
lines changed

8 files changed

+1162
-933
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ or a link to a ticket system...
2424

2525
### New Feature / Bug Fix
2626

27-
- [ ] Run unit tests to ensure all existing tests are still passing
28-
- [ ] Add new passing unit tests to cover the code introduced by your PR
27+
- [ ] Run unit tests **AND E2E TESTS** to ensure all existing tests are still passing
28+
- [ ] Add new passing unit **AND E2E TESTS** tests to cover the code introduced by your PR
2929

3030
<!--
3131
Thanks for contributing!

package-lock.json

Lines changed: 1115 additions & 903 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"scripts": {
55
"postinstall": "lerna bootstrap",
66
"build": "lerna run build",
7+
"clean": "lerna run clean",
78
"test": "jest --coverage",
89
"e2e": "lerna run e2e",
910
"lint": "tslint -c tslint.json './packages/**/src/**/*.ts'",

packages/addon-contentful/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/addon-theme-switcher/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/addon-vuex-persist/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/service/src/models/JSONModel.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,21 @@ import { format } from 'prettier';
33
import { runtimeRoot } from '../utils/path';
44
import { logError, logInfo } from '../utils/ui';
55

6-
const prettierConfig = JSON.parse(fs.readFileSync(runtimeRoot('.prettierrc')).toString());
6+
let prettierConfig;
7+
8+
try {
9+
prettierConfig = JSON.parse(fs.readFileSync(runtimeRoot('.prettierrc')).toString());
10+
} catch (e) {
11+
prettierConfig = {
12+
singleQuote: true,
13+
bracketSpacing: true,
14+
arrowParens: 'always',
15+
trailingComma: 'all',
16+
tabWidth: 2,
17+
printWidth: 120,
18+
endOfLine: 'lf',
19+
};
20+
}
721

822
export class JSONModel<T> {
923
protected path: string = null;
@@ -15,30 +29,30 @@ export class JSONModel<T> {
1529
}
1630

1731
public load() {
18-
try {
19-
this.model = JSON.parse(fs.readFileSync(this.path).toString());
20-
} catch (e) {
21-
logError(e);
22-
logInfo(fs.readFileSync(this.path).toString());
32+
if (fs.existsSync(this.path)) {
33+
try {
34+
this.model = JSON.parse(fs.readFileSync(this.path).toString());
35+
} catch (e) {
36+
logError(e);
37+
}
2338
}
2439
}
2540

2641
public save(prettier: boolean = true) {
2742
let jsonString = '';
2843
try {
29-
jsonString = JSON.stringify(this.model, null, (prettierConfig && prettierConfig.tabWidth) || 2) + '\n';
44+
jsonString = JSON.stringify(this.model, null, prettierConfig.tabWidth) + '\n';
45+
46+
const data = prettier
47+
? format(jsonString, {
48+
...prettierConfig,
49+
parser: 'json',
50+
})
51+
: jsonString;
52+
53+
fs.writeFileSync(this.path, data);
3054
} catch (e) {
3155
logError(e);
32-
logInfo(this.model);
3356
}
34-
35-
const data = prettier
36-
? format(jsonString, {
37-
...prettierConfig,
38-
parser: 'json',
39-
})
40-
: jsonString;
41-
42-
fs.writeFileSync(this.path, data);
4357
}
4458
}

packages/service/src/models/VuesionConfig.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ class Model extends JSONModel<IVuesionConfig> implements IVuesionConfig {
4343
constructor() {
4444
super(runtimeRoot('.vuesion/config.json'));
4545

46-
this.clean = this.model.clean;
47-
this.currentVersion = this.model.currentVersion;
48-
this.devServer = this.model.devServer;
49-
this.generators = this.model.generators;
50-
this.i18n = this.model.i18n;
51-
this.prettier = this.model.prettier;
52-
this.spa = this.model.spa;
53-
this.webpack = this.model.webpack;
46+
if (this.model !== null) {
47+
this.clean = this.model.clean;
48+
this.currentVersion = this.model.currentVersion;
49+
this.devServer = this.model.devServer;
50+
this.generators = this.model.generators;
51+
this.i18n = this.model.i18n;
52+
this.prettier = this.model.prettier;
53+
this.spa = this.model.spa;
54+
this.webpack = this.model.webpack;
55+
}
5456
}
5557

5658
public getWebpackAliases() {

0 commit comments

Comments
 (0)