Add File System Example
This commit is contained in:
		
							parent
							
								
									eb31b843e2
								
							
						
					
					
						commit
						3955b2e342
					
				
							
								
								
									
										85
									
								
								src/components/FsExample.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								src/components/FsExample.vue
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,85 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <div>
 | 
				
			||||||
 | 
					    <div v-if="error">
 | 
				
			||||||
 | 
					      There was an error attempting to read from the file system.
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <button
 | 
				
			||||||
 | 
					      data-test="fs-example-button"
 | 
				
			||||||
 | 
					      @click="getCurrentDirectory"
 | 
				
			||||||
 | 
					    >
 | 
				
			||||||
 | 
					      <template v-if="!error">
 | 
				
			||||||
 | 
					        Click for File System example
 | 
				
			||||||
 | 
					      </template>
 | 
				
			||||||
 | 
					      <template v-else>
 | 
				
			||||||
 | 
					        Try again for File System example
 | 
				
			||||||
 | 
					      </template>
 | 
				
			||||||
 | 
					    </button>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <template v-if="contents">
 | 
				
			||||||
 | 
					      <p>
 | 
				
			||||||
 | 
					        The contents of the current working directory:
 | 
				
			||||||
 | 
					      </p>
 | 
				
			||||||
 | 
					      <div class="contents">
 | 
				
			||||||
 | 
					        <div
 | 
				
			||||||
 | 
					          v-for="(file, fileIndex) in contents"
 | 
				
			||||||
 | 
					          class="file"
 | 
				
			||||||
 | 
					          :key="'file' + fileIndex"
 | 
				
			||||||
 | 
					        >
 | 
				
			||||||
 | 
					          {{ file }}
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    </template>
 | 
				
			||||||
 | 
					  </div>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script>
 | 
				
			||||||
 | 
					export default {
 | 
				
			||||||
 | 
					  name: 'FsExample',
 | 
				
			||||||
 | 
					  data: function () {
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					      contents: null,
 | 
				
			||||||
 | 
					      error: false
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  methods: {
 | 
				
			||||||
 | 
					    getCurrentDirectory: function () {
 | 
				
			||||||
 | 
					      const fs = window.nw.require('fs');
 | 
				
			||||||
 | 
					      try {
 | 
				
			||||||
 | 
					        this.contents = fs.readdirSync('.');
 | 
				
			||||||
 | 
					        this.error = false;
 | 
				
			||||||
 | 
					      } catch (err) {
 | 
				
			||||||
 | 
					        this.error = true;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  computed: {}
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<style scoped>
 | 
				
			||||||
 | 
					button {
 | 
				
			||||||
 | 
					  background: linear-gradient(0deg, #2EB277, #65E6AC);
 | 
				
			||||||
 | 
					  border-width: 3.4px;
 | 
				
			||||||
 | 
					  border-color: #35495E;
 | 
				
			||||||
 | 
					  border-radius: 8px;
 | 
				
			||||||
 | 
					  margin: 22px 0px 6px 0px;
 | 
				
			||||||
 | 
					  padding: 11px 17px;
 | 
				
			||||||
 | 
					  color: #050709;
 | 
				
			||||||
 | 
					  font-family: 'Trebuchet MS', Verdana, sans-serif;
 | 
				
			||||||
 | 
					  font-size: 16px;
 | 
				
			||||||
 | 
					  font-weight: bold;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.contents {
 | 
				
			||||||
 | 
					  display: flex;
 | 
				
			||||||
 | 
					  flex-flow: wrap;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					.file {
 | 
				
			||||||
 | 
					  flex-grow: 1;
 | 
				
			||||||
 | 
					  min-width: 200px;
 | 
				
			||||||
 | 
					  background: #DDD;
 | 
				
			||||||
 | 
					  margin: 5px;
 | 
				
			||||||
 | 
					  padding: 11px;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					</style>
 | 
				
			||||||
@ -37,17 +37,23 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    <h3>Ecosystem</h3>
 | 
					    <h3>Ecosystem</h3>
 | 
				
			||||||
    <LinkList :links="ecosystemLinks" />
 | 
					    <LinkList :links="ecosystemLinks" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <hr />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <FsExample />
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script>
 | 
					<script>
 | 
				
			||||||
import Vue from 'vue';
 | 
					import Vue from 'vue';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import FsExample from '@/components/FsExample.vue';
 | 
				
			||||||
import LinkList from '@/components/LinkList.vue';
 | 
					import LinkList from '@/components/LinkList.vue';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
  name: 'HelloWorld',
 | 
					  name: 'HelloWorld',
 | 
				
			||||||
  components: {
 | 
					  components: {
 | 
				
			||||||
 | 
					    FsExample,
 | 
				
			||||||
    LinkList
 | 
					    LinkList
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  props: {
 | 
					  props: {
 | 
				
			||||||
@ -157,7 +163,7 @@ export default {
 | 
				
			|||||||
  },
 | 
					  },
 | 
				
			||||||
  computed: {
 | 
					  computed: {
 | 
				
			||||||
    devMode: function () {
 | 
					    devMode: function () {
 | 
				
			||||||
      return window.process.env.NODE_ENV === 'development';
 | 
					      return window.process.versions['nw-flavor'] === 'sdk';
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    versions: function () {
 | 
					    versions: function () {
 | 
				
			||||||
      return window.process.versions;
 | 
					      return window.process.versions;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user