I want to get the list of contents of a Folder ( located in SD-Card ) and put it in an array, and separate Folders from Files.
right now I am using this:
const fs = require("tns-core-modules/file-system");
const root = android.os.Environment.getExternalStorageDirectory().getAbsolutePath().toString();
dir = fs.path.join( root , '/Parole' );
let documents = fs.Folder.fromPath( dir );
documents.getEntities()
.then((entities) => {
entities.forEach((entity) => {
console.log(entity);
});
}).catch((err) => {
console.log(err.stack);
});
but entity contanis no info but name & path for Folders ( and for Files which has no EXT ) , How can I recognize if it refers to a folder or not?
(p.s. I am Not using any Framework in my project)
(p.s. I have some Files with-out Any EXT in my project!!!!)
Use the Folder apis to distinguish between folder and file.
entities.forEach((entity) => {
if (fs.Folder.exists(entity.path)) {
// Folder
} else {
// File
}
});
Related
I am using the StoryShots addon for Storybook to test snapshots from my React project. I would like to save all snapshot files in one directory in relation to the project directory. The default is that the snapshots are saved in relation to the story's location. I tried various configurations (like working with __dirname) but couldn't come up with a solution yet. Maybe someone has an idea?
Here is my storyshots test file used by Jest (storyshots.test.ts):
import initStoryshots, { multiSnapshotWithOptions, Stories2SnapsConverter } from '#storybook/addon-storyshots'
initStoryshots({
test: multiSnapshotWithOptions(),
stories2snapsConverter: new Stories2SnapsConverter({
snapshotsDirName: './__snapshots__/',
storiesExtensions: ['.js', '.jsx', '.ts', '.tsx'],
})
})
You can do something like this:
const IMAGE_SNAPSHOT_DIR = path.resolve(path.join(__dirname, 'component-image-snapshots'));
initStoryshots({
test: imageSnapshot({
getMatchOptions: (option) => {
const filename = option.context.kind.replace(' ', '');
return {
customSnapshotsDir: path.join(IMAGE_SNAPSHOT_DIR, filename),
};
},
}),
});
I'm using the Nativescript tutorial for creating a carousel here.
The problem I'm running into is that I get the following error (minus my obfuscation)
Error: Failed to load component from module: undefined.xml or file: /data/data/{Obfuscated}/files/app/pages/welcome/slides/slide1.xml
when it tries to load xml files on this line (full snippet below):
slides.push(builder.load(slidePath))
Upon some inspection I found that it's the file system that doesn't see the files I'm loading. My code is the same as the tutorials code. I've gone through it line by line (even doing a diff) and the code is in fact the same.
Here's a better look at the file path it's choking on, you can compare that to the image I provided below:
/data/data/{Obfuscated}/files/app/pages/welcome/slides/slide1.xml
I can verify that the folder structure is the same as in the tutorial app/pages/welcome/slides.slide1.xml but when the page loads, I get that error and it never loads the xml.
Here's the full snippet:
private loadSlides(slideFiles, slidesPath) {
return new Promise(function (resolve, reject) {
const slides = []
const currentAppFolder = fs.knownFolders.currentApp();
const path = fs.path.normalize(currentAppFolder.path + "/" + slidesPath);
slideFiles.forEach((dataFile, i) => {
const slidePath = path + "/" + dataFile;
console.log(slidePath);
// Here's where it crashes
slides.push(builder.load(slidePath))
});
resolve(slides);
});
}
When I test it out by debugging and using the file-system module to test whether the path exists... it always comes back false, even though the folder structure definitely exists the way it does in the tutorial.
The console.log line displays this:
/data/data/{myobfuscation}/files/app/pages/welcome/slides
As you can see it matches my folder path below.
How do I get the file-system to see that folder structure? It works just fine when I use it for verifying the existence image files.
Here's an image of the folder structure:
Webpack will never know you would require those XML files at runtime, you will have to adjust webpack.config.js to include those files in the bundle.
Update the CopyWebpackPlugin configuration as follows,
// Copy assets to out dir. Add your own globs as needed.
new CopyWebpackPlugin(
[
{ from: { glob: "assets/**" } },
{ from: { glob: "fonts/**" } },
{ from: { glob: "**/*.jpg" } },
{ from: { glob: "**/*.png" } },
{ from: { glob: "**/*.xml" } },
],
{ ignore: [`${relative(appPath, appResourcesFullPath)}/**`] },
),
Adding { from: { glob: "**/*.xml" } }, copies all XML files along with folder structure into the bundle.
I am trying to make "main.css" file to be directly in css folder.
However, I get this path "/css/Content/scss/main.css" and I want
"/css/main.css"
gulp.task('sass', () => {
const sourceFolder = path.join('.', 'Content', 'scss', 'main.scss');
const distFolder = path.join('.', 'wwwroot', 'css');
return gulp.src(sourceFolder)
.pipe(sass({
sourceMap: true,
style: 'compressed'
}))
.pipe(cleanCSS({
compatibility: 'ie8'
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(distFolder))
.on('end', () => console.log(`[${new Date().toLocaleTimeString()}] -> sass compilation complete...`));
});
Assuming you want main.css to end up in wwwroot/css try changing to this line:
return gulp.src(sourceFolder, { base: path.join('Content', 'scss') })
Sorry but I cannot explain why your original code works on Linux.
From glob base in gulpjs.docs:
Vinyl instances generated by src() are constructed with the glob base
set as their base property. When written to the file system with
dest(), the base will be removed from the output path to preserve
directory structures.
So with the base set as path.join('Content', 'scss') that portion of the filepath will be removed, thus main.css will go directly into your distFolder with the parent folders removed.
I'm following this tutorial. http://www.c-sharpcorner.com/article/using-mvc-6-and-angularjs-2-with-net-core/
I have gotten to the point of using gulp to copy files to the lib-npm folder. All the expected files copy except angular. I receive no error message, the files just are there.
here is my gulp file
/// <binding />
/*
This file in the main entry point for defining Gulp tasks and using Gulp plugins.
Click here to learn more. http://go.microsoft.com/fwlink/?LinkId=518007
*/
"use strict";
var gulp = require("gulp");
var root_path = {
webroot: "./wwwroot/"
};
//library source
root_path.nmSrc = "./node_modules/";
//library destination
root_path.package_lib = root_path.webroot + "lib-npm/";
gulp.task("copy-systemjs", function () {
return gulp.src(root_path.nmSrc + '/systemjs/dist/**/*.*', {
base: root_path.nmSrc + '/systemjs/dist/'
}).pipe(gulp.dest(root_path.package_lib + '/systemjs/'));
});
gulp.task("copy-angular2", function () {
return gulp.src(root_path.nmSrc + '/angular2/bundles/**/*.js', {
base: root_path.nmSrc + '/angular2/bundles/'
}).pipe(gulp.dest(root_path.package_lib + '/angular2/'));
});
gulp.task("copy-es6-shim", function () {
return gulp.src(root_path.nmSrc + '/es6-shim/es6-sh*', {
base: root_path.nmSrc + '/es6-shim/'
}).pipe(gulp.dest(root_path.package_lib + '/es6-shim/'));
});
gulp.task("copy-rxjs", function () {
return gulp.src(root_path.nmSrc + '/rxjs/bundles/*.*', {
base: root_path.nmSrc + '/rxjs/bundles/'
}).pipe(gulp.dest(root_path.package_lib + '/rxjs/'));
});
gulp.task("copy-all", ["copy-rxjs", 'copy-angular2', 'copy-systemjs', 'copy-es6-shim']);
I have also noticed that my .\node_modules\Angular2 folder in my project doesn't have an .js files in it. Is this normal?
Angular2 version is 1.0.2
I receive the following errors on build because the files are missing
Cannot find name 'Component'.
Build:Cannot find module 'angular2/core'.
Build:Cannot find module 'angular2/platform/browser'.
Build:Cannot find name 'Component'.
Cannot find module 'angular2/core'.
Cannot find module 'angular2/platform/browser'
I would suggest you not to copy node_modules every time you build an app. You can easily amend the UseStaticFiles middleware inside the Startup.cs class as described here. By doing this your node_modules stay where they are and you don't need to repeatedly copy them.
Btw. Recently (before switching to UseStatisFiles modification) I have done the same in the Gulp and the following has worked well:
gulp.task('build-angular-js', function () {
return gulp.src(paths.angularJs)
.pipe(cache('linting'))
.pipe(gulp.dest(paths.jsNgDest));
});
..where paths equals to:
var paths = {
webroot: "./wwwroot/",
angularJs: [
"./node_modules/core-js/client/shim.min.js",
"./node_modules/zone.js/dist/zone.js",
"./node_modules/reflect-metadata/Reflect.js",
"./node_modules/systemjs/dist/system.src.js",
"./App/External/systemjs.config.js",
"./node_modules/#angular/**/*.js",
"./node_modules/rxjs/**/*.js"
],
appJs: [
"./App/App/**/*.js"
]
};
paths.jsDest = paths.webroot + "app";
paths.jsNgDest = paths.webroot + "app";
The complete template and all sources including gulpfile.js can be found here on GitHub. Note that cache is a gulp plugin to avoid copying not modified files. As said above though - better to avoid copying node_modules.
I have two variables.
var files = 'dist/**';
var destination = '/public_html/projects/test';
Using Gulp, my tasks add files to the dist folder when they are production ready.
Then using vinyl-ftp, an npm package, I upload the files variable to destination on the server.
My problem is that when the files are uploaded, my dist folder is uploaded as well. The path then looks like this to my index: public_html/projects/test/dist/index.html.
My question then is how do I only grab the conents of dist and then upload those to the server?
You need to set your gulp.src base path to your local 'dist' subfolder. e.g.
gulp
.src('dist/**', {base: 'dist/'})
.pipe(...)
In my Case the solution given by user15895 works fine, Thank you!!! But I need do a simple ajdust.
var ftp = require('vinyl-ftp'),
gutil = require('gulp-util');
//Here in my gulp deploy task ..
var ftpConnection = ftp.create({
host : "ftp.xxx.com",
user : "xxx",
password : "xxx",
parallel : 10,
log : gutil.log
});
var globs = [ './build/**'];
return gulp.src( globs, {base : './build' , buffer : false })
.pipe( ftpConnection.newer('/public_html'))
.pipe( ftpConnection.dest('/public_html'))