Distribution file source is different to development path source - html

I've started using a task runner to export all of my folders into a distribution folder using Gulp. The problem arises when I export images into the distribution folder, the path name is different from the one I'm using in my src file. So, as an example, when I target an image in HTML I type:
/assets/images/example.jpg
However, when the HTML file is distributed, it is supposed to target:
/images/example.jpg
It's still pointing to the assets folder, and creates a dead link. Should I be using a module like gulp-replace to automatically change these path names? Or should I just type in the assumed path name? Or, is there another method that I'm missing?
Sorry if I've phrased this badly, I'm working towards a new developer environment - let me know if I can provide you with any other details.

Should I be using a module like gulp-replace to automatically change
these path names?
Yes, gulp-replace will do the trick.
As an alternative you can place your index.html file into assets folder, so you don't need to change any paths when distributing the project.

Related

ReactJS link to local HTML file from different folder/project

I'm using ReactJS to build a site, and I want to create a link (a href="relativepath") to a local HTML file so that when the user clicks on the link, it'll open up the html page. The local file is in a different folder X outside of the project, and I don't want to upload it into my src folder because the html file depends on a lot of other files in X. Is there a good way to do so?
I also want to upload a different local HTML file that is already within the src folder of my React App. I currently have something like this:
import htmlFile from "../links/htmlFile.html"; export default function Something(props) { return (<a href={htmlFile}></a>)}
and it says in my terminal that
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <html>| | <head> >
I already tried adding in webpack + an htmlLoader, but I think I followed the steps incorrectly as I wasn't able to get it to work. I uninstalled those packages, so I'm now back to square one.
Thank you so much!
Just linking to or importing from a local file in some other location won't work unless those local files are also deployed to the server in the same location relative to the app (and the web server has access to that location).
So you'll need to copy the file and its linked dependencies in a folder that will be deployed along with your react build, but not where it'll get treated as part of the react codebase so webpack will try to compile it (so not in src either).
If you used create-react-app to set up your application, for example, this would be the public folder; other webpack setups may use different names but the general concept is the same.

Invoking Oracle Fmx file

I have an Oracle Forms application. In the menu options I need to provide an option to open another application. I am using Replace_menu (File_Name) option to change the menu options of the new application.
The fmx file which I need to invoke is in a different folder but in the same parent directory.
If I pass the whole path including the file name this options works fine, however if I try to use the relative path it fails.
Consider I have the following folder structure:
C:\Sample\Sup
Forms1 and Forms2 are 2 folders.
The first application is in Forms1. I need to invoke form_menu.mmx inside Forms2 folder.
eg: Replace_menu(c:\Sample\Sup\Forms2\form_menu.mmx) - This works fine.
eg: Replace_menu(../Forms/form_menu.mmx) - Does not work
You only have a few options:
Include the full path in the code
Include the fully qualified path in FORMS_PATH
Pass the path in at runtime as a parameter.
Relative paths are not permitted.

Swagger API Specification filenames

I'm trying to use Swagger to create API documentation for an API we're building and I've never used it before.
The documentation on Github says that the Resources Listing needs t be at /api-docs and the various resource files need to be at /api-docs/books etc.
This makes naming files and folders very tricky. I think they expect the files to have no file names, rather than having a folder called /api-docs it has to be an extension-less file, then you can't put the resources in an api-docs folder because you can't call the folder that, so they suggest using a folder called /listings.
This folder doesn't appear in the URL structure of your documentation though, it's kind of invisible because you set the baseURL in your resources to the proper path, but it looks like that has to be an absolute path, which is awkward if you want to have it on several servers (local and production).
Maybe I just don't get it but this all seems to be absolutely nuts.
So, I have 2 questions.....
1) Can I give my resource listing file and my resource files a .json extension? This would make sense as it's a JSON file.
2) Can I use a relative path to the resource listing file in the baseURL in my resource files?
Ideally, my file structure would be flatter, like this...
/api-docs
resources.json
books.json
films.json
Is Swagger flexible enough to do this?
It's an IIS server if that makes any difference (if the solution requires routing for example).
I was able to put model files into a folder under the web root and could reference them like this.
$ref: '/models/model.yml#/MyObject'
Relative paths also worked without a leading slash.
$ref: 'models/model.yml#/MyObject'
Inside the model.yml, I can reference other objects int eh same file like this
$ref: '#/MyObject2'.
However, I could only get the main swagger file to import model files. I could not get one model file to cross-reference another model file.
I was using a Tomcat web server but the principle will be the same.

How do I make Yeoman not use the parent directory name for the application .js file?

When I use yeoman init angular:allto bootstrap my app, yeoman uses the name of the directory I'm calling it from as the name of the main application .js file. I.e. if I'm running the command in /Users/myusername/dev/projects/my-angular-app, then the file app/scripts/my-angular-app.js is created as the main .js file for the app.
If I simply rename the root directory, then using Yeoman to add routes won't work, as it can no longer find the .js file it created. I've tried adding the name of the app as a parameter when invoking the Yeoman init command, but that doesn't work.
I've tried doing the init command in a directory with the name I want the app to have, and then renaming the directory afterwards. But it seems Yeoman reads the name of that directory every time it's invoked, so after changing the name of the directory, Yeoman is no longer able to create routes for me as it can't find the .js file with the same name as the root directory.
How can I make Yeoman use a different name for the my-angular-app.js file?
There's an open ticket about it, please weigh in your thoughts there.
I am not sure if this is possible but you might want to have a look at the Gruntfile.js and replace all the instances in the config were it is storing the old path and replace it with the new path. I am not sure if that will work as I have never tried but it might based on my understanding of Grunt.
I am like you, I like to have things named the way I want which why I don't use Yeoman even though I would love to (like they say, it is opinionated, just too opinionated for me), I have a few custom built grunt tasks that give me most of the functionality I need (mainly auto compile of SASS/TypeScript, minifying CSS/JS, and concating CSS/JS files).
The issue is with generator-angular.
Currently, the app name is taken from the bower component.json file. If you are using the more recent convention of naming this file bower.json, the app name will fall back to the directory name.
Rename bower.json to component.json until support for the new naming scheme makes it into generator-angular.
It looks like these changes have already been made but have yet to be merged into the master branch: renaming-deprecated-component_json

Issue in creating Zip file using glob.glob

I am creating a Zip file from a folder (and subfolders). it works fine and creates a new .zip file also but I am having an issue while using glob.glob. It is reading all files from the desired folder (source folder) and writing to the new zip file but the problem is that it is, however, adding subdirectories, but not adding files form the subdirectories.
I am giving user an option to select the filename and path as well as filetype also (Zip or Tar). I don;t get any problem while creating .tar.gz file, but when use creates .zip file, this problem comes across.
Here is my code:
for name in (Source_Dir):
for name in glob.glob("/path/to/source/dir/*" ):
myZip.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
myZip.close()
Also, if I use code below:
for dirpath, dirnames, filenames in os.walk(Source_Dir):
myZip.write(os.path.join(dirpath, filename) os.path.basename(filename))
myZip.close()
Now the 2nd code taks all files even if it inside the folder/ subfolders, creates a new .zip file and write to it without any directory strucure. It even does not take dir structure for main folder and simply write all files from main dir or subdir to that .zip file.
Can anyone please help me or suggest me. I would prefer glob.glob rather than the 2nd option to use.
Thanks in advance.
Regards,
Akash
Glob by design does not expand into subdirectories. It follows UNIX style path rules and expansions see the documentation for fnmatch for more information. If you want to get at the subdirectories you need to add it to the path. This example will get everything at one level down.
for name in (Source_Dir):
for name in glob.glob("/path/to/source/dir/*/*" ):
myZip.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
myZip.close()
Doug Hellman has an excellent discussion here. If you are not using the pattern features of glob (like *.txt for all text files or *[0-9].txt for all text files that have a number before the extension) then I think your os.walk solution is better