roll-right 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,26 +1,57 @@
1
1
  # roll-right
2
2
 
3
- A helper utilty for gather browser artifacts from node modules, code repositories, etc.
3
+ A command line tool that gathers selected code components from curated bases of code and that, first, fans them into templates for site pages and that, second, populates templates with static site-specific code in order to generate static pages for sites.
4
+
5
+ ***Here are steps of a generation process for site maintainers***:
6
+
7
+ 1. store commonly used, well-tested code in files in selected directories
8
+ 2. provide a file describing families of page skeletons
9
+ 3. provide a JSON description that selects which skeleton parts are to be used along with source directories
10
+ 4. run roll-right in phase 1 with the JSON to generate site templates
11
+ 5. provide static components, pictures, etc. to populate templates
12
+ 6. run roll-right in phase 2 with .subst files specifying the template population
13
+ 7. use other tools to deploy files dropped into a staging directory
14
+
15
+ The generation process is not limited to coalescing code for pages. There is support for generating node.js modules, generating web page modules, etc. for npm publication.
16
+
17
+ ## install it
18
+
19
+ ```
20
+ npm install -g roll-right
21
+ ```
22
+
23
+
24
+ ## run it
25
+
26
+ ```
27
+ roll-right --phase 1 <website-identifier> <directory including config>
28
+ ```
29
+
30
+
31
+
32
+ ```
33
+ roll-right --phase 2 <website-identifier> <directory including config>
34
+ ```
35
+
4
36
 
5
37
 
6
38
  ## How it Helps
7
39
 
8
- This is tool is not a replacement for final publication steps enabled by rollup, browserify, or others.
40
+ This tool is not a replacement for final publication steps enabled by rollup, browserify, or others. Instead, this stool may generate code that will be sumbitted to those tools.
9
41
 
10
- This tool provides help with preparing and using an entry point into a module that can be used to obtain the browser version of a module.
42
+ In fact, whole pages needing no further manipulation may be generated by this tool. So, in some cases this tool does the job that others do. However, some build systems use the other tools to generate their final runtime products. And, this tool may be upstream from those tools.
11
43
 
12
- The aim is make it so that the tool does not have to look at a directory structure of a module, e.g. node_modules in order to get the browser version of some code. It does not require that the code be written in some strange way to accomodate the placement of the same code in two contexts. It does not require reading a special key in a package.json file peculiar to npm.
44
+ In particular, this tool addresses moving preexisting code into certain packaged contexts at the source level. Other packages rollup modules into single code sets or module collections into one file.
13
45
 
14
- It does require that two versions of the node module/browser module/window level javascript, etc. be available in the package.
46
+ This tool can be used to replicate code into projects, allowing for function by function selection. The final output will be a combined source file with a chain of support for working code. That is, a developer may request that a whole module be copied into a combined source file for a project, or he may select some functions to be placed into the combined source file. But, he may expect that the functions included will have their supporting functions brought in as well.
15
47
 
16
- * It provides tools to help create the separate versions from one.
17
- * It provides tools to insert a snippet of code in the interface (entry point) level of the module.
48
+ More commonly, this tool is useful for creating web pages that host bundled operations and that provide basic common libraries that will not be accessed on the global (window) level. In the sense that a browser provides a common library accessible to all parts of a project, a window can offer an extension of that capability. The extension is mostly a packaging of that capability into simpler calls.
18
49
 
19
- The code inserted, is a call that will fetch the browser version of the code and return it to its caller. The caller will usually be the command line version of roll-right. Users will have access to the roll-right command line tool, and will call it to update to the latest browser version of code, depositing it where the rollup (or others) can get at it.
50
+ One may ask why one would allow code (fixed version) to be copied into a number of projects without creating a module publication. The answer has more to do with expediency of project creation with some time being taken to decide what is a maintable module. The tool will copy just one function from a group of functions into a project if that is specified. But, when the module is maintained, the tool may copy all the function of a group into the new module and ready the code for publication. Projects that use the module will import all the functions in some sense into their code. Certainly, down stream tree shaking may work to reduce the number of functions included. But, that may just move certain worries down stream.
20
51
 
21
- For example, I have a Svelte project that needs some modules, but the modules might not be expressly published in npm. Instead, the modules can be deposited into a common directory accessible by the files in the projects. The build tool will grab those files from that diretory and put them in the final build file.
52
+ So, there are options for deciding how alpha code will be included in projects. But, this tool also provides generation based on skeletons.
22
53
 
23
- For another example, I have some code that must appear at the script level of index.html. It is not intended to be inside a module component. It will just be insterted at some point marked by a variable. The roll-right tool has to call a subtool that does the substitution and leaves the templated result in the appropriate project directory.
54
+ In order to create a template, this tool reads a skeleton file and a JSON configuration that describes how to select alpha code and use some or all of the skeleton to create an .html file that has code and variables, where the mark the place where final code will be placed.
24
55
 
25
56
 
26
57
  ## Setting up publisher calls in a node.js module
package/bin/index.js CHANGED
@@ -1,14 +1,117 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ const papa = require('../index.js')
4
+ const {load_json_file} = require('../lib/utils')
3
5
 
6
+ const {transfer_node_module_browser_version} = require('../lib/rr_utils')
7
+ const {transfer_github_browser_version} = require('../lib/rr_utils')
8
+ const {transfer_local_directory_browser_version} = require('../lib/rr_utils')
9
+ const {port_modules} = require('../lib/mod_utils')
4
10
 
11
+ const Phase1 = require('../lib/phase1')
12
+ const Phase2 = require('../lib/phase2')
13
+ //
14
+ //
5
15
 
6
- const papa = require('../index.js')
16
+ var g_argv = require('minimist')(process.argv.slice(2));
17
+ console.dir(g_argv);
18
+
19
+ let g_target = g_argv._[0]
20
+ let g_source_dir = g_argv._[1]
21
+ if ( g_source_dir === undefined ) {
22
+ g_source_dir = "."
23
+ }
7
24
 
8
- console.log(__filename)
9
- console.log(process.argv[0])
10
- console.log(process.argv[1])
11
25
 
26
+ function load_config(cf_name) {
27
+ let path = g_source_dir + '/' + cf_name
28
+ return load_json_file(path)
29
+ }
12
30
 
31
+
32
+ const g_config = load_config("roll-right.json")
13
33
  papa.identify_me()
14
34
 
35
+ // //
36
+ function read_data(roll_conf) {
37
+ try {
38
+ console.dir(roll_conf)
39
+ for ( let ky in roll_conf ) {
40
+ let source_spec = roll_conf[ky]
41
+ let kys = Object.keys(source_spec)
42
+ if ( kys.length ) {
43
+ switch ( ky ) {
44
+ case "pnpm" : {
45
+ transfer_node_module_browser_version(source_spec)
46
+ break
47
+ }
48
+ case "github" : {
49
+ transfer_github_browser_version(source_spec)
50
+ break
51
+ }
52
+ case "local" : {
53
+ transfer_local_directory_browser_version(source_spec)
54
+ break;
55
+ }
56
+ default: {
57
+ // plugins
58
+ break;
59
+ }
60
+
61
+ }
62
+ }
63
+ }
64
+ } catch (e) {
65
+ console.log(e)
66
+ }
67
+ }
68
+
69
+
70
+ async function command_line_operations() {
71
+ console.log("command line operations")
72
+
73
+ if ( g_argv.phase ) {
74
+ console.log(`starting phase ${g_argv.phase} instantiation`)
75
+ switch ( g_argv.phase ) {
76
+ case "template" :
77
+ case 1: { /// creates templates
78
+ if ( typeof g_config.alpha === "string" ) {
79
+ g_config.alpha = load_json_file(g_config.alpha) // ALPHA
80
+ }
81
+ let ph1 = new Phase1(g_target,g_config.alpha) // g_target <- args[0] ... g_config <- read <- g_source_dir <- args[1]
82
+ ph1.run()
83
+ break
84
+ }
85
+ case "page":
86
+ case 2: {
87
+ if ( typeof g_config.beta === "string" ) {
88
+ g_config.beta = load_json_file(g_config.beta) // BETA
89
+ }
90
+ let ph2 = new Phase2(g_target,g_config.beta) // g_target <- args[0] ... g_config <- read <- g_source_dir <- args[1]
91
+ ph2.run()
92
+ break
93
+ }
94
+ default : {
95
+ console.log("unnown phase")
96
+ break;
97
+ }
98
+ }
99
+ }
100
+ if ( g_argv.gather ) { // about moving files to directories for node module, browser modules, etc.
101
+ if ( typeof g_config.gather === "string" ) {
102
+ g_config.modules = load_json_file(g_config.gather)
103
+ }
104
+ read_data(g_config.gather)
105
+ }
106
+ if ( g_argv.modules ) { // transforms and then copies base alpha code to final publication directores (npm is the only case yet)
107
+ if ( typeof g_config.modules === "string" ) {
108
+ g_config.modules = load_json_file(g_config.modules)
109
+ }
110
+ port_modules(g_config.modules,g_argv)
111
+ }
112
+
113
+ }
114
+
115
+
116
+
117
+ command_line_operations()
package/index.js CHANGED
@@ -7,5 +7,5 @@ module.exports.browser_code = roll_right_utilities.browser_code_access
7
7
 
8
8
 
9
9
  module.exports.identify_me = () => {
10
- console.log("I AM ROLL-RIGHT")
10
+ console.log("roll-right static content management and module publication")
11
11
  }
@@ -0,0 +1,79 @@
1
+
2
+ const fs = require('fs')
3
+ const path = require('path')
4
+ const {load_json_file,array_flatten} = require('../lib/utils')
5
+ const {execSync} = require('child_process')
6
+ const {translate_marker} = require('../lib/utils')
7
+
8
+
9
+
10
+ async function cp_module_to(dest,src,config) {
11
+ let src_dr = translate_marker(src,config)
12
+ let dest_file = translate_marker(dest,config)
13
+ //
14
+ let path_parts = dest_file.split('/')
15
+ try {
16
+ let src_file = `${src_dr}/${path_parts[path_parts.length-1]}`
17
+ fs.copyFileSync(src_file,dest_file)
18
+ } catch (e) {
19
+ console.log(e)
20
+ }
21
+ //
22
+ }
23
+
24
+ async function check_tests(src,dest,config) {
25
+ return true
26
+ }
27
+
28
+ async function shell_command(cmd) {
29
+ try {
30
+ execSync(cmd,{
31
+ stdio: [0, 1, 2]
32
+ })
33
+ } catch (e) {
34
+ console.log(e)
35
+ }
36
+ }
37
+
38
+
39
+ function bump_npm_version() {
40
+ let npm = load_json_file("package.json")
41
+ let v = npm.version
42
+ let semv = v.split('.')
43
+ let minv = parseInt(semv[semv.length - 1])
44
+ minv++
45
+ semv[semv.length - 1] = "" + minv
46
+ npm.version = semv.join('.')
47
+ fs.writeFileSync("package.json",JSON.stringify(npm,null,2))
48
+ }
49
+
50
+
51
+ async function npm_publish() {
52
+ await shell_command("npm publish .")
53
+ }
54
+
55
+ async function port_modules(config,flags) {
56
+ //
57
+ let all_tests = true
58
+ for ( let mod in config.sources ) {
59
+ let tests_ok = await check_tests(mod,config.sources[mod],config)
60
+ if ( tests_ok ) {
61
+ await cp_module_to(mod,config.sources[mod],config)
62
+ }
63
+ all_tests = all_tests && tests_ok
64
+ }
65
+ //
66
+ if ( all_tests ) {
67
+ switch ( config.mod_type ) {
68
+ case "npm" :
69
+ default: {
70
+ if ( flags.publish ) {
71
+ bump_npm_version()
72
+ await npm_publish()
73
+ }
74
+ }
75
+ }
76
+ }
77
+ }
78
+
79
+ module.exports.port_modules = port_modules