Yeoman generator - deep copy empty folder structure - copy

Given the following generator folder structure; I'm attempting to deep copy all folders under the 'for_copy' folder.
generator root
app
templates
for_copy
data
external
media
All the folders are empty. I would like to have this structure created for me when I invoke the generator.
I have tried using fs.copy, bulkCopy, and bulkDirectory. None of them are doing the job.
Any clues as to how I might achieve this would be greatly appreciated.
See below code snippet:
writing: function() {
this.log('Writing templates...');
//doesn't work
this.fs.copy(
this.templatePath('for_copy'),
this.destinationRoot()
);
//doesn't work
this.bulkCopy(
this.templatePath('for_copy'),
this.destinationRoot()
);
//doesn't work
this.bulkDirectory(
this.templatePath('for_copy'),
this.destinationRoot()
);
//doesn't work
this.bulkDirectory(
this.templatePath('for_copy') +'**/*',
this.destinationRoot()
);
}

Yeoman only cares about files. When you use bulkDirectory, you actually copy files over, not directories.
You can use mkdirp module to create directories.
mkdirp.sync(path.join(this.destinationPath(), 'data'));
mkdirp.sync(path.join(this.destinationPath(), 'external'));
// etc ...

Related

Specifying window (global) variable type hinting in VSCode from external JS file without typescript

This may be a silly question but I really don't know where to look.
I'm creating a browser testing environment for a pretty large-scale API written in typescript. This API uses esbuild to build the typescript files into a /dist/ folder with a single index.js entry-point and its appropriate d.ts file.
I've created a /tests/ folder to hold some browser files that includes an index.html file with Mocha and Chai imported. It also imports /dist/index.js which is set globally to a window.myAPI variable.
In /tests/index.html:
import * as myAPI from "./dist/index.js"
Alongside index.html in the tests folder, there are separate JS files included for different tests that run things on window.myAPI... to do assertion tests.
search.test.js
book.test.js
navigate.test.js
I then run a server to host at the root. These separate tests are then imported from /tests/index.html. The separate tests look like this inside:
const { chai, mocha } = window;
const { assert } = chai;
describe("Search", function() {
describe("Setup", function() {
it("Setting URL should work", function() {
const call = myAPI.someCall()
assert.ok(call);
});
});
});
mocha.run();
Everything works, but I have no code hinting for myAPI. I'd like to be able to see what functions are available when I type myAPI, and what parameters they take, and what they should return - along with all my comments on each function.
In typescript you can do things like ambient declarations, but I don't want to make my tests typescript because then I add an unnecessary build step to the tests. But it would be as easy as:
/// <reference path = "/dist/index.d.ts" />
How can I tell VSCode that window.myAPI is an import of /dist/index.js and should import the types as well so I can see them ?
I'm open to different solutions to this, but I feel like this should be pretty simple. I don't know if ESLint is capable of doing something like this, but I tagged it because I feel it's relevant.
Thanks!

Webpack - Add asset to stats

I'm still kinda new to building Webpack plugins, so I have a question on regarding how to proper add assets to the compilation.
I am building this plugin: rebabel-webpack-plugin
That in all its simplicity takes the compiled files and recompiles them again with babel to transpile them in to fx ES 5 compatable files (I know... it seems weird... The why is in the projects readme).
This actually works pretty well, but my assets are not showing up in the Stats part of webpack (eg. compiler.getStats())
I am adding my recompiled assets to the compilation.assets list, but only my initial entry files and a dynamic named chunk shows up in the stats object.
So how do I make my recompiled assests show up in webpacks stats section?
So after some digging around I think I found a solution to my problem.
It seems that I needed to add my newly created assets as chunks as well and change the names of the file references in there.
So the following code seems to solve the problem:
function addPrefixToFile(prefix, file) {
return file.replace(/(^|[/\\])([^/\\]+)$/, `$1${prefix}$2`);
}
const files = chunks.reduce((arr, chunk) => {
if(!chunk.rendered) { return arr; }
// Create chunk copy
const copy = Object.assign(Object.create(chunk), {
name: chunk.name ? `${prefix}${chunk.name}` : chunk.name,
files: (chunk.files || []).map((file) => addPrefixToFile(file)),
parents: chunk.parents.map(
(parent) => Object.assign({}, parent, {
files: (parent.files || []).map((file) => addPrefixToFile(file))
})
)
});
chunkCopies.push(copy);
}, []);
// ... further down the line ...
chunks.push(...chunkCopies);
To me it seems a bit hacky so I was wondering if there is a better way of doing this. But well... it works.

ngCordova - How to remove all files from local dir

I'm developing an app in Ionic Framework and I use ngCordova's file plugin to get access to the device’s files and directories.
I need to clean all files from a directory but I don't know how. In the official docs (http://ngcordova.com/docs/plugins/file/) tells how to remove a single file (removeFile)or how to remove all files and also the directory (removeRecursively) but I just need to only remove all the files from a dir.
I've tried to do this but it does not remove any file:
$scope.cleanFiles = function cleanFiles() {
$cordovaFile.removeFile(cordova.file.dataDirectory, "*")
.then(function (success) {
console.log('removed all files');
}, function (error) {
console.log('error removing files');
});
}
Any help? Thanks!
I am using the same plugin for files. it's working properly for me. please try to see logs when removing file. and other thing i noticed, you need not to write function like this.
$scope.cleanFiles = function cleanFiles()
rather
$scope.cleanFiles = function()
is enough for declaring it as a function.

How do I write a Webpack plugin to generate index.js files on demand?

In general, I want to know how to do code-generation/fabrication in a Webpack plugin on demand. I want to generate contents for files that do not exist when they are "required."
Specifically, I want a plugin that, when I require a directory, automatically requires all files in that directory (recursively).
For example, suppose we have the directory structure:
foo
bar.js
baz.js
main.js
And main.js has:
var foo = require("./foo");
// ...
I want webpack to automatically generate foo/index.js:
module.exports = {
bar: require("./bar"),
baz: require("./baz")
};
I've read most of the webpack docs. github.com/webpack/docs/wiki/How-to-write-a-plugin has an example of generating assets. However, I can't find an example of how to generate an asset on demand. It seems this should be a Resolver, but resolvers seem to only output file paths, not file contents.
Actually for your use case:
Specifically, I want a plugin that, when I require a directory, automatically requires all files in that directory (recursively).
you don't need a plugin. See How to load all files in a subdirectories using webpack without require statements
Doing code-generation/fabrication on demand can be done in JavaScript quite easily, why would you restrict your code generation specifically to only applied, when "required" by WebPack?
As NodeJS itself will look for an index.js, if you require a directory, you can quite easily generate arbitrary exports:
//index.js generating dynamic exports
var time = new Date();
var dynamicExport = {
staticFn : function() {
console.log('Time is:', time);
}
}
//dynamically create a function as a property in dynamicExport
//here you could add some file processing logic that is requiring stuff on demand and export it accordingly
dynamicExport['dyn' + time.getDay()] = function() {
console.log('Take this Java!');
}
module.exports = dynamicExport;

Configuring ScalaDoc task in Gradle to generate aggregated documentation

I have a multi module scala project in Gradle. Everything works great with it, except the ScalaDoc. I would like to generate a single 'uber-scaladoc' with all of the libraries cross-linked. I'm still very new to groovy/gradle, so this is probably a 'me' problem. Any assistance getting this setup would be greatly appreciated.
build.gradle (in the root directory)
// ...
task doScaladoc(type: ScalaDoc) {
subprojects.each { p ->
// do something here? include the project's src/main/scala/*?
// it looks like I would want to call 'include' in here to include each project's
// source directory, but I'm not familiar enough with the Project type to get at
// that info.
//
// http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.scala.ScalaDoc.html
}
}
The goal here would be able to just run 'gradle doScalaDoc' at the command line and have the aggregate documentation show up.
Thanks in advance.