简体   繁体   English

为什么 Cordova 项目具有相同的 index.js 副本?

[英]Why does a Cordova project have identical copies of index.js?

I included a lot of background information to help you answer this question, however you can skip down to the heading called 'Questions' to skip to the main point.我提供了很多背景信息来帮助您回答这个问题,但是您可以跳到名为“问题”的标题以跳到重点。

Background背景

I'm new to using Cordova, and I'm new to an existing Cordova project I want to further develop.我是使用 Cordova 的新手,也是我想要进一步开发的现有 Cordova 项目的新手。 As a result, when I look at the project files, I am not sure what are choices made by the previous developers and what are choices made automatically by Cordova.结果,当我查看项目文件时,我不确定以前的开发人员做出了什么选择,以及 Cordova 自动做出了什么选择。 I suspect that Cordova generates a lot of files that are not created by the application developers because in my case there are over 7900 files including source code and README's, and the application was previously (to my knowledge at least) developed by only one person.我怀疑 Cordova 生成了很多不是由应用程序开发人员创建的文件,因为在我的情况下,包括源代码和自述文件在内的文件超过 7900 个,并且该应用程序以前(至少据我所知)仅由一个人开发。

While many questions could be asked from that perspective, I would like to narrow in on a specific question to avoid being too broad.虽然可以从这个角度提出很多问题,但我想缩小一个具体问题的范围,以避免过于宽泛。 I've noted that are many files within the path structure called index.js .我注意到路径结构中有许多名为index.js的文件。

$ find . -name "index.js"
./platforms/android/app/build/intermediates/assets/debug/www/js/index.js
./platforms/android/app/src/main/assets/www/js/index.js
./platforms/android/cordova/node_modules/balanced-match/index.js
./platforms/android/cordova/node_modules/os-tmpdir/index.js
./platforms/android/cordova/node_modules/concat-map/index.js
./platforms/android/cordova/node_modules/properties-parser/index.js
./platforms/android/cordova/node_modules/elementtree/lib/parsers/index.js
./platforms/android/cordova/node_modules/os-homedir/index.js
./platforms/android/cordova/node_modules/xmlbuilder/lib/index.js
./platforms/android/cordova/node_modules/ansi/examples/beep/index.js
./platforms/android/cordova/node_modules/ansi/examples/progress/index.js
./platforms/android/cordova/node_modules/ansi/examples/clear/index.js
./platforms/android/cordova/node_modules/path-is-absolute/index.js
./platforms/android/cordova/node_modules/brace-expansion/index.js
./platforms/android/cordova/node_modules/sax/test/index.js
./platforms/android/cordova/node_modules/android-versions/index.js
./platforms/android/cordova/node_modules/lodash/index.js
./platforms/android/cordova/node_modules/cordova-registry-mapper/index.js
./www/js/index.js
./node_modules/objectorarray/index.js
./node_modules/es-abstract/index.js
./node_modules/es-abstract/test/index.js
./node_modules/isexe/index.js
./node_modules/balanced-match/index.js
./node_modules/object-keys/index.js
./node_modules/object-keys/test/index.js
./node_modules/has/src/index.js
./node_modules/has/test/index.js
./node_modules/semver/test/index.js
./node_modules/string.prototype.trim/index.js
./node_modules/string.prototype.trim/test/index.js
./node_modules/cordova-plugin-file/src/blackberry10/index.js
./node_modules/jsonfile/index.js
./node_modules/fs-extra/lib/ensure/index.js
./node_modules/fs-extra/lib/remove/index.js
./node_modules/fs-extra/lib/move/index.js
./node_modules/fs-extra/lib/output/index.js
./node_modules/fs-extra/lib/copy-sync/index.js
./node_modules/fs-extra/lib/fs/index.js
./node_modules/fs-extra/lib/empty/index.js
./node_modules/fs-extra/lib/index.js
./node_modules/fs-extra/lib/path-exists/index.js
./node_modules/fs-extra/lib/copy/index.js
./node_modules/fs-extra/lib/move-sync/index.js
./node_modules/fs-extra/lib/json/index.js
./node_modules/fs-extra/lib/mkdirs/index.js
./node_modules/concat-map/index.js
./node_modules/elementtree/lib/parsers/index.js
./node_modules/fs.realpath/index.js
./node_modules/plist/index.js
./node_modules/path-key/index.js
./node_modules/xmlbuilder/lib/index.js
./node_modules/ansi/examples/beep/index.js
./node_modules/ansi/examples/progress/index.js
./node_modules/ansi/examples/clear/index.js
./node_modules/cordova-android/node_modules/balanced-match/index.js
./node_modules/cordova-android/node_modules/os-tmpdir/index.js
./node_modules/cordova-android/node_modules/concat-map/index.js
./node_modules/cordova-android/node_modules/properties-parser/index.js
./node_modules/cordova-android/node_modules/elementtree/lib/parsers/index.js
./node_modules/cordova-android/node_modules/os-homedir/index.js
./node_modules/cordova-android/node_modules/xmlbuilder/lib/index.js
./node_modules/cordova-android/node_modules/ansi/examples/beep/index.js
./node_modules/cordova-android/node_modules/ansi/examples/progress/index.js
./node_modules/cordova-android/node_modules/ansi/examples/clear/index.js
./node_modules/cordova-android/node_modules/path-is-absolute/index.js
./node_modules/cordova-android/node_modules/brace-expansion/index.js
./node_modules/cordova-android/node_modules/sax/test/index.js
./node_modules/cordova-android/node_modules/android-versions/index.js
./node_modules/cordova-android/node_modules/lodash/index.js
./node_modules/cordova-android/node_modules/cordova-registry-mapper/index.js
./node_modules/cordova-android/bin/templates/project/assets/www/js/index.js
./node_modules/for-each/index.js
./node_modules/tape/index.js
./node_modules/path-is-absolute/index.js
./node_modules/brace-expansion/index.js
./node_modules/deep-equal/index.js
./node_modules/has-symbols/index.js
./node_modules/has-symbols/test/index.js
./node_modules/shebang-regex/index.js
./node_modules/is-callable/index.js
./node_modules/through/index.js
./node_modules/through/test/index.js
./node_modules/resumer/index.js
./node_modules/resolve/index.js
./node_modules/resolve/test/resolver/dot_main/index.js
./node_modules/resolve/test/resolver/multirepo/packages/package-b/index.js
./node_modules/resolve/test/resolver/multirepo/packages/package-a/index.js
./node_modules/resolve/test/resolver/quux/foo/index.js
./node_modules/resolve/test/resolver/incorrect_main/index.js
./node_modules/resolve/test/resolver/same_names/foo/index.js
./node_modules/resolve/test/resolver/dot_slash_main/index.js
./node_modules/resolve/test/shadowed_core/node_modules/util/index.js
./node_modules/resolve/test/node_path/x/ccc/index.js
./node_modules/resolve/test/node_path/x/aaa/index.js
./node_modules/resolve/test/node_path/y/ccc/index.js
./node_modules/resolve/test/node_path/y/bbb/index.js
./node_modules/resolve/test/module_dir/ymodules/aaa/index.js
./node_modules/resolve/test/module_dir/xmodules/aaa/index.js
./node_modules/resolve/test/precedence/aaa/index.js
./node_modules/resolve/test/dotdot/abc/index.js
./node_modules/resolve/test/dotdot/index.js
./node_modules/function-bind/index.js
./node_modules/function-bind/test/index.js
./node_modules/shebang-command/index.js
./node_modules/minimist/index.js
./node_modules/cordova-plugin-network-information/src/blackberry10/index.js
./node_modules/cross-spawn/index.js
./node_modules/es-to-primitive/index.js
./node_modules/es-to-primitive/test/index.js
./node_modules/strip-bom/index.js
./node_modules/is-date-object/index.js
./node_modules/path-parse/index.js
./node_modules/is-symbol/index.js
./node_modules/is-symbol/test/index.js
./node_modules/base64-js/index.js
./node_modules/node-version-compare/index.js
./node_modules/node-version-compare/test/index.js
./node_modules/universalify/index.js
./node_modules/define-properties/index.js
./node_modules/define-properties/test/index.js
./node_modules/nice-try/src/index.js
./node_modules/defined/index.js
./node_modules/object-inspect/index.js
./node_modules/is-regex/index.js
./plugins/cordova-plugin-file/src/blackberry10/index.js
./plugins/cordova-plugin-network-information/src/blackberry10/index.js

It would be extremely broad and impractical to question what each and every one of these identically-named files are for, and some may be inanswerable if their existence depends on design choices of the previous developers of this project.质疑这些同名文件中的每一个文件的用途是非常广泛和不切实际的,如果它们的存在取决于该项目以前开发人员的设计选择,那么有些文件可能无法回答。 Fortunately, I can be more specific than that.幸运的是,我可以比这更具体。 I have an issue to debug, and with a specific search string related to the bug, I was able to find that specific files named index.js contained that string.我有一个要调试的问题,并且使用与该错误相关的特定搜索字符串,我能够找到名为index.js的特定文件包含该字符串。

$ grep -ril "<search_string>" .
./platforms/android/app/build/intermediates/assets/debug/www/js/index.js
./platforms/android/app/src/main/assets/www/js/index.js
./www/js/index.js

And to clarify further, while not being the only files returned by grep , these three index.js files were the only files that appeared to be relevant to my bug.为了进一步澄清,虽然不是grep返回的唯一文件,但这三个index.js文件是唯一似乎与我的错误相关的文件。 I then used cmp to compare these three files, and I found that they're mutually identical (not shown since cmp by default only prints output when there is a difference).然后我使用cmp比较这三个文件,发现它们是相互相同的(未显示,因为cmp默认情况下仅在存在差异时才打印 output)。

There seems to be some confusion about the importance of ./www/js/index.js , but it also seems to be the case that I should prefer to edit ./www/js/index.js rather than ./platforms/android/app/src/main/assets/www/js/index.js because ./platforms/android/app/src/main/assets/www/js/index.js is automatically generated by Cordova according to this post .关于./www/js/index.js的重要性似乎有些混乱,但我似乎更喜欢编辑./www/js/index.js而不是./platforms/android/app/src/main/assets/www/js/index.js因为./platforms/android/app/src/main/assets/www/js/index.js根据这篇文章由 Cordova 自动生成。 This suggest that ./www/js/index.js is not automatically generated, although this still leaves open whether ./platforms/android/app/build/intermediates/assets/debug/www/js/index.js is automatically generated.这表明./www/js/index.js不是自动生成的,尽管./platforms/android/app/build/intermediates/assets/debug/www/js/index.js是否自动生成仍然悬而未决。 Given that build is in the path of ./platforms/android/app/build/intermediates/assets/debug/www/js/index.js , I suspect that this is a file automatically generated when the command cordova build android is run.鉴于build位于./platforms/android/app/build/intermediates/assets/debug/www/js/index.js的路径中,我怀疑这是在运行命令cordova build android时自动生成的文件。 This leads me to the suspicion that I should edit ./www/js/index.js and not the other two of these three files.这让我怀疑我应该编辑./www/js/index.js而不是这三个文件中的另外两个。

Questions问题

I'm really asking 3 questions in one post, however since their scope and background are nearly identical I would prefer to keep them together for context.我真的在一篇文章中问了 3 个问题,但是由于他们的 scope 和背景几乎相同,我更愿意将它们放在一起作为上下文。

  1. Which of the three index.js should be edited in developing an application with Cordova?使用 Cordova 开发应用程序时应该编辑三个index.js中的哪个?
     ./platforms/android/app/build/intermediates/assets/debug/www/js/index.js./platforms/android/app/src/main/assets/www/js/index.js./www/js/index.js
  2. The three index.js files mentioned in Question 1 are identical.问题 1 中提到的三个index.js文件是相同的。 Why do each of these identical copies exist?为什么每个相同的副本都存在?

  3. There are non-identical files named index.js in a Cordova project. Cordova 项目中有名为index.js的不相同的文件。 Why are they all called the same name if they are non-identical in content?如果它们的内容不相同,为什么它们都被称为相同的名称?

You should edit /www/js/index.js .您应该编辑/www/js/index.js

The other two files are created during the build process.其他两个文件是在构建过程中创建的。 A built Cordova app will have all www folder contents inside an android app structure, that's why they are inside /platforms/android/app/src/main/构建的 Cordova 应用程序将在 android 应用程序结构中包含所有www文件夹内容,这就是它们位于/platforms/android/app/src/main/中的原因

The other index.js files are there because it's a Node.js pattern其他index.js文件在那里,因为它是 Node.js 模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM