Skip to content

Commit 4ff640e

Browse files
Merge pull request #30 from jawa-the-hutt/dev
Dev to Master
2 parents 750115b + 84ba0bf commit 4ff640e

23 files changed

+219
-139
lines changed

Diff for: README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@ An example of this would be the following Vue component:
5353
```
5454

5555
### Optional Separation of concerns for Web and Native SFC's
56-
If you want complete seperation of concerns between Web and Native for components, core logic and styling, you can also provide an alternate file naming scheme in your project. The name will dictate which mode (Web or Native) and platform (Android or IOS) the file will be used with. The same overall schema will work for `.vue`, `.js`, `.ts`, `.scss` and `.css` files.
56+
If you want complete seperation of concerns between Web and Native for components, core logic and styling, you can also provide an alternate file naming scheme in your project. The name will dictate which mode (Web or Native) and platform (Android or IOS) the file will be used with. The same overall schema will work for `.vue`, `.js`, `.ts`, `.scss` and `.css` files.
5757

5858
| File Type | Android __and__ IOS | Android only | IOS only | Web only |
5959
| ---------- | ------------------- | --------------- | --------------- | --------------- |
60-
| vue | *.native.vue | *.android.vue | *.ios.vue | *.vue |
60+
| vue | *.native.vue | *.android.vue | *.ios.vue | *.vue |
6161
| js | *.native.js | *.android.js | *.ios.js | *.js |
6262
| ts | *.native.ts | *.android.ts | *.ios.ts | *.ts |
6363
| scss | *.native.scss | *.android.scss | *.ios.scss | *.scss |
6464
| css | *.native.css | *.android.css | *.ios.css | *.css |
6565

6666
Webpack will handle figuring out which files to include based on the `npm run` command syntax you pass in. You can also mix and match this file naming schema with the `web` or `native` tag options mentioned above.
6767

68-
At `serve` or `build` in conjunction with the mode such as `android` or `ios`, Webpack will filter which files are looked at. For instance, if you do `npm run serve:android`, then it will look for `*.native.vue` and `*.android.vue` files and ignore `*.ios.vue` files entirely. Conversely, it will do the same when you are working with `ios` and will ignore `*.android.vue` files.
68+
At `serve` or `build` in conjunction with the mode such as `android` or `ios`, Webpack will filter which files are looked at. For instance, if you do `npm run serve:android`, then it will look for `*.native.vue` and `*.android.vue` files and ignore `*.ios.vue` files entirely. Conversely, it will do the same when you are working with `ios` and will ignore `*.android.vue` files.
6969

7070
This will allow you to develop generic native components under the `*.native.vue` file extension, but in special cases, it may require you to do platform specific components, core logic and styling. Use the corrosponding file extension to allow this to happen.
7171

@@ -218,7 +218,7 @@ Each time the project is built or served, the plugin will copy the latest webpac
218218
If you'd like to see what the webpack config is doing then you can run one of the following:
219219

220220
1. `vue inspect -- --env.android > out-android.js`
221-
2. `vue inspect -- --env.ios > out-android.js`
221+
2. `vue inspect -- --env.ios > out-ios.js`
222222
3. `vue inspect -- --env.web > out-web.js`
223223

224224
These will default to showing you the Development version of the webpack config. You can pass in the `-- --env.production` option to see the Production version of the config. Subtitute `development.android` or `production.ios`, etc to see the different configs based on the environmental variables.

Diff for: generator/index.js

+47-33
Original file line numberDiff line numberDiff line change
@@ -56,47 +56,48 @@ module.exports = async (api, options, rootOptions) => {
5656
version: '5.2.0'
5757
},
5858
'tns-android': {
59-
version: '5.2.0'
59+
version: '5.2.1'
6060
}
6161
},
6262
scripts: {
63-
'build:android':
64-
// eslint-disable-next-line max-len
65-
'npm run setup-webpack-config && cross-env-shell VUE_CLI_MODE=production.android tns build android --bundle --env.production && npm run remove-webpack-config',
66-
'build:ios':
67-
'npm run setup-webpack-config && cross-env-shell VUE_CLI_MODE=production.ios tns build ios --bundle --env.production && npm run remove-webpack-config',
63+
'build:android': 'npm run setup-webpack-config && tns build android --bundle --env.production && npm run remove-webpack-config',
64+
'build:ios': 'npm run setup-webpack-config && tns build ios --bundle --env.production && npm run remove-webpack-config',
6865
'remove-webpack-config': 'node ./node_modules/vue-cli-plugin-nativescript-vue/lib/scripts/webpack-maintenance post',
69-
'serve:android': 'npm run setup-webpack-config && cross-env-shell VUE_CLI_MODE=development.android tns run android --bundle --env.development',
70-
'serve:ios': 'npm run setup-webpack-config && cross-env-shell VUE_CLI_MODE=development.ios tns run ios --bundle --env.development',
66+
'serve:android': 'npm run setup-webpack-config && tns run android --bundle --env.development',
67+
'serve:ios': 'npm run setup-webpack-config && tns run ios --bundle --env.development',
7168
// 'inspect:android': 'npm run setup-webpack-config && vue inspect -- --env.android > out-android.js',
7269
// 'inspect:ios': 'npm run setup-webpack-config && vue inspect -- --env.ios > out-ios.js',
73-
'debug:android': 'npm run setup-webpack-config && cross-env-shell VUE_CLI_MODE=development.android tns debug android --bundle --env.development',
74-
'debug:ios': 'npm run setup-webpack-config && cross-env-shell VUE_CLI_MODE=development.ios tns debug ios --bundle --env.development',
75-
'preview:android':
76-
'npm run setup-webpack-config && cross-env-shell VUE_CLI_MODE=development.android tns preview --bundle --env.development --env.android',
77-
'preview:ios': 'npm run setup-webpack-config && cross-env-shell VUE_CLI_MODE=development.android tns preview --bundle --env.development --env.ios',
78-
'setup-webpack-config': 'node ./node_modules/vue-cli-plugin-nativescript-vue/lib/scripts/webpack-maintenance pre'
70+
'debug:android': 'npm run setup-webpack-config && tns debug android --bundle --env.development',
71+
'debug:ios': 'npm run setup-webpack-config && tns debug ios --bundle --env.development',
72+
'preview:android': 'npm run setup-webpack-config && tns preview --bundle --env.development --env.android',
73+
'preview:ios': 'npm run setup-webpack-config && tns preview --bundle --env.development --env.ios',
74+
'setup-webpack-config': 'node ./node_modules/vue-cli-plugin-nativescript-vue/lib/scripts/webpack-maintenance pre',
75+
'clean:platforms': 'rimraf platforms',
76+
'clean:android': 'rimraf platforms/android',
77+
'clean:ios': 'rimraf platforms/ios'
7978
},
8079
dependencies: {
8180
'nativescript-vue': '^2.0.2',
8281
'tns-core-modules': '^5.2.1'
8382
},
8483
devDependencies: {
85-
'cross-env': '^5.2.0',
8684
'nativescript-dev-webpack': '^0.17.0',
8785
'nativescript-vue-template-compiler': '^2.0.2',
8886
'nativescript-worker-loader': '~0.9.1',
8987
'node-sass': '^4.11.0',
90-
'string-replace-loader': '^2.1.1'
88+
'string-replace-loader': '^2.1.1',
89+
rimraf: '^2.6.3',
90+
webpack: '^4.29.6',
91+
'webpack-cli': '^3.2.3'
9192
}
9293
});
9394

9495
// add scripts when we are also developing for the web
9596
if (!options.isNativeOnly) {
9697
api.extendPackage({
9798
scripts: {
98-
'serve:web': 'vue-cli-service serve --mode development.web --env.development --env.web',
99-
'build:web': 'vue-cli-service build --mode production.web --env.production --env.web'
99+
'serve:web': 'vue-cli-service serve --mode development.web',
100+
'build:web': 'vue-cli-service build --mode production.web'
100101
//'inspect:web': 'npm run setup-webpack-config && vue inspect -- --env.web > out-web.js'
101102
}
102103
});
@@ -118,7 +119,7 @@ module.exports = async (api, options, rootOptions) => {
118119
dependencies: {},
119120
devDependencies: {
120121
'fork-ts-checker-webpack-plugin': '^0.4.15',
121-
'uglifyjs-webpack-plugin': '^2.0.1'
122+
'terser-webpack-plugin': '^1.2.3'
122123
//'tns-platform-declarations': '^4.2.1'
123124
}
124125
});
@@ -138,10 +139,10 @@ module.exports = async (api, options, rootOptions) => {
138139
if (api.hasPlugin('babel')) {
139140
api.extendPackage({
140141
devDependencies: {
141-
'@babel/core': '^7.1.2',
142-
'@babel/preset-env': '^7.1.0',
143-
'babel-loader': '^8.0.4',
144-
'babel-traverse': '^6.26.0'
142+
'@babel/core': '^7.3.4',
143+
'@babel/preset-env': '^7.3.4',
144+
'babel-loader': '^8.0.5',
145+
'@babel/traverse': '^7.3.4'
145146
}
146147
});
147148

@@ -237,7 +238,7 @@ module.exports = async (api, options, rootOptions) => {
237238
});
238239
}
239240

240-
api.onCreateComplete(() => {
241+
api.onCreateComplete(async () => {
241242
// make changes to .gitignore
242243
gitignoreAdditions(api);
243244

@@ -252,15 +253,26 @@ module.exports = async (api, options, rootOptions) => {
252253
nativeOnlyRenameFiles(genConfig.dirPathPrefix + genConfig.nativeAppPathModifier.slice(0, -1));
253254
}
254255

255-
if (api.hasPlugin('typescript')) {
256-
if (fs.existsSync(api.resolve('tslint.json'))) {
257-
require('../lib/tslint')({}, api, true);
258-
tslintSetup(genConfig.dirPathPrefix, api.resolve('tslint.json'), genConfig.tsExclusionArray);
259-
}
256+
// remove router config for projects that don't use vue-router
257+
if (!rootOptions.router) {
258+
fs.remove(genConfig.dirPathPrefix + genConfig.nativeAppPathModifier + 'router' + genConfig.jsOrTs, (err) => {
259+
if (err) throw err;
260+
});
261+
}
260262

263+
if (api.hasPlugin('typescript')) {
261264
// we need to edit the tsconfig.json file in /app
262265
// for a Native only project to remove references to /src
263-
tsconfigSetup(options, genConfig.dirPathPrefix, genConfig.nativeAppPathModifier);
266+
await tsconfigSetup(options, genConfig.dirPathPrefix, genConfig.nativeAppPathModifier);
267+
268+
if (fs.existsSync(api.resolve('tslint.json'))) {
269+
await tslintSetup(genConfig.dirPathPrefix, api.resolve('tslint.json'), genConfig.tsExclusionArray);
270+
271+
const baseDir = genConfig.nativeAppPathModifier;
272+
require('../lib/tslint')({
273+
'_': [`${baseDir}**/*.ts`, `${baseDir}**/*.vue`, `${baseDir}**/*.tsx`, 'tests/**/*.ts', 'tests/**/*.tsx']
274+
}, api, false);
275+
}
264276
}
265277

266278
// the main difference between New and Existing for this section is
@@ -709,7 +721,7 @@ const tslintSetup = (module.exports.tslintSetup = async (dirPathPrefix, tslintPa
709721
// setup tsconfig for native only projects
710722
const tsconfigSetup = (module.exports.tsconfigSetup = async (options, dirPathPrefix, nativeAppPathModifier) => {
711723
try {
712-
// setup the abilty to edit the tsconfig.json file in the root of the project
724+
// setup the ability to edit the tsconfig.json file in the root of the project
713725
let tsConfigContent = '';
714726
let tsConfigPath = path.join(dirPathPrefix, 'tsconfig.json');
715727

@@ -724,6 +736,9 @@ const tsconfigSetup = (module.exports.tsconfigSetup = async (options, dirPathPre
724736
tsConfigContent.compilerOptions.noImplicitAny = false;
725737
// // // tsConfigContent.compilerOptions.types = [];
726738

739+
// edit types attribute to fix build
740+
tsConfigContent.compilerOptions.types = ['node'];
741+
727742
// edit some of the options in compilerOptions.paths object array
728743
tsConfigContent.compilerOptions.paths['@/*'] = [nativeAppPathModifier + '*'];
729744
tsConfigContent.compilerOptions.paths['assets/*'] = [nativeAppPathModifier + 'assets/*'];
@@ -821,7 +836,7 @@ const renderDirectoryStructure = (module.exports.renderDirectoryStructure = asyn
821836
) => {
822837
try {
823838
const files = new Array();
824-
const baseDir = await extractCallDir()
839+
const baseDir = await extractCallDir();
825840
const _files = await getAllFilesInDirStructure(srcPathPrefix, baseDir);
826841

827842
for (const rawPath of _files) {
@@ -902,7 +917,6 @@ const getAllFilesInDirStructure = (module.exports.replaceInFile = async (srcPath
902917
// utility function used to remove sections of strings from files
903918
const replaceInFile = (module.exports.replaceInFile = async (options) => {
904919
try {
905-
//const changes =
906920
await replace(options);
907921
} catch (error) {
908922
console.error('Error occurred:', error);

Diff for: generator/templates/nvw/src/App.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
<%_ } _%>
198198
<%_ } else { _%>
199199
<%# -------------------- IS Using standard CSS -------------------- -%>
200-
<style web lang="scss">
200+
<style web>
201201
@import '~styles/style-one';
202202

203203
.w-page {
@@ -209,7 +209,7 @@
209209
color: #42b983;
210210
}
211211
</style>
212-
<style native lang="scss">
212+
<style native>
213213
@import '~styles/style-one';
214214
</style>
215215
<%_ } _%>

Diff for: generator/templates/nvw/src/components/HelloWorld.android.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<%_ } _%>
7979
<%_ } else { _%>
8080
<%# -------------------- IS Using standard CSS -------------------- -%>
81-
<style scoped lang="scss">
81+
<style scoped>
8282
.message {
8383
color: #42b983;
8484
}

Diff for: generator/templates/nvw/src/components/HelloWorld.ios.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<%_ } _%>
7979
<%_ } else { _%>
8080
<%# -------------------- IS Using standard CSS -------------------- -%>
81-
<style scoped lang="scss">
81+
<style scoped>
8282
.message {
8383
color: #42b983;
8484
}

Diff for: generator/templates/nvw/src/components/HelloWorld.native.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<%_ } _%>
7979
<%_ } else { _%>
8080
<%# -------------------- IS Using standard CSS -------------------- -%>
81-
<style scoped lang="scss">
81+
<style scoped>
8282
.message {
8383
color: #42b983;
8484
}

Diff for: generator/templates/nvw/src/components/HelloWorld.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
<%_ } _%>
9393
<%_ } else { _%>
9494
<%# -------------------- IS Using standard CSS -------------------- -%>
95-
<style scoped lang="scss">
95+
<style scoped>
9696
.message {
9797
color: #42b983;
9898
display: block;

Diff for: generator/templates/nvw/src/views/About.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
<%_ } _%>
106106
<%_ } else { _%>
107107
<%# -------------------- IS Using standard CSS -------------------- -%>
108-
<style scoped lang="scss">
108+
<style scoped>
109109
@import '~styles/style-two';
110110
@import '~styles/style-one';
111111

Diff for: generator/templates/nvw/src/views/Home.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
<%_ } _%>
123123
<%_ } else { _%>
124124
<%# -------------------- IS Using standard CSS -------------------- -%>
125-
<style scoped lang="scss">
125+
<style scoped>
126126
@import '~styles/style-one';
127127
@import '~styles/style-two';
128128

Diff for: generator/templates/simple/src/App.vue

+12-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
</nav>
1111
<div class="w-container">
1212
<router-link tag="button" class="w-button" id="homeButton" to="/">Home</router-link>
13-
<router-link tag="button" class="w-button" id="aboutButton" to="/about">About</router-link>
13+
<!-- alternate way to route manually and use the same method as native -->
14+
<button class="w-button" id="aboutButton" v-on:click="goToAboutPage">About</button>
1415
<router-view/>
1516
</div>
1617
</div>
@@ -62,6 +63,8 @@
6263

6364
<%_ if (!rootOptions.router) { _%>
6465
const { VUE_APP_MODE, VUE_APP_PLATFORM } = process.env;
66+
<%_ } else { _%>
67+
const { VUE_APP_MODE } = process.env;
6568
<%_ } _%>
6669

6770
export default {
@@ -84,7 +87,7 @@
8487
this.$navigateTo(Home);
8588
},
8689
goToAboutPage() {
87-
this.$navigateTo(About);
90+
VUE_APP_MODE == 'web' ? this.$router.push('about') : this.$navigateTo(About);
8891
}
8992
<%_ } _%>
9093
}
@@ -101,9 +104,11 @@
101104
import About from '~/views/About.vue';
102105
<%_ } _%>
103106

104-
<%_ if (!rootOptions.router) { _%>
107+
<%_ if (!rootOptions.router) { _%>
105108
const { VUE_APP_MODE, VUE_APP_PLATFORM } = process.env;
106-
<%_ } _%>
109+
<%_ } else { _%>
110+
const { VUE_APP_MODE } = process.env;
111+
<%_ } _%>
107112

108113
@Component({
109114
name: 'home',
@@ -125,7 +130,7 @@
125130
}
126131

127132
public goToAboutPage() {
128-
Vue.prototype.$navigateTo(About);
133+
VUE_APP_MODE == 'web' ? this.$router.push('about') : Vue.prototype.$navigateTo(About);
129134
}
130135
<%_ } _%>
131136
}
@@ -193,15 +198,15 @@
193198
<%_ } _%>
194199
<%_ } else { _%>
195200
<%# -------------------- IS Using standard CSS -------------------- -%>
196-
<style web lang="scss">
201+
<style web>
197202
@import '~styles/style-one';
198203

199204
.w-page {
200205
height: 100%;
201206
width: 100%;
202207
}
203208
</style>
204-
<style native lang="scss">
209+
<style native>
205210
@import '~styles/style-one';
206211
</style>
207212
<%_ } _%>

Diff for: generator/templates/simple/src/components/HelloWorld.android.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<%_ } _%>
7979
<%_ } else { _%>
8080
<%# -------------------- IS Using standard CSS -------------------- -%>
81-
<style scoped lang="scss">
81+
<style scoped>
8282
.message {
8383
color: #42b983;
8484
}

Diff for: generator/templates/simple/src/components/HelloWorld.ios.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<%_ } _%>
7979
<%_ } else { _%>
8080
<%# -------------------- IS Using standard CSS -------------------- -%>
81-
<style scoped lang="scss">
81+
<style scoped>
8282
.message {
8383
color: #42b983;
8484
}

Diff for: generator/templates/simple/src/components/HelloWorld.native.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<%_ } _%>
7979
<%_ } else { _%>
8080
<%# -------------------- IS Using standard CSS -------------------- -%>
81-
<style scoped lang="scss">
81+
<style scoped>
8282
.message {
8383
color: #42b983;
8484
}

Diff for: generator/templates/simple/src/components/HelloWorld.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<%_ } _%>
9090
<%_ } else { _%>
9191
<%# -------------------- IS Using standard CSS -------------------- -%>
92-
<style scoped lang="scss">
92+
<style scoped>
9393
.message {
9494
color: #42b983;
9595
display: block;

Diff for: generator/templates/simple/src/main.native.js

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
extend: '@vue/cli-service/generator/template/src/main.js'
33
replace:
44
- !!js/regexp /import Vue from 'vue'/
5+
- !!js/regexp /import App from './App.vue'/
56
- !!js/regexp /Vue.config.productionTip = false/
67
- !!js/regexp /h => h\(App\),/
78
- !!js/regexp /}\)\.\$mount\('#app'\)/
@@ -11,6 +12,10 @@ replace:
1112
import Vue from 'nativescript-vue';
1213
<%# END_REPLACE %>
1314

15+
<%# REPLACE %>
16+
import App from './App.vue';
17+
<%# END_REPLACE %>
18+
1419
<%# REPLACE %>
1520
// Set the following to `true` to hide the logs created by nativescript-vue
1621
Vue.config.silent = false;

0 commit comments

Comments
 (0)