浏览代码

dev(license-headers): implement skip and replace

KernelDeimos 10 月之前
父节点
当前提交
2bf9f60bb0
共有 2 个文件被更改,包括 17 次插入5 次删除
  1. 6 4
      experiments/js-parse-and-output/test.js
  2. 11 1
      tools/license-headers/main.js

+ 6 - 4
experiments/js-parse-and-output/test.js

@@ -1,21 +1,23 @@
 /*
 /*
  * Copyright (C) 2024 Puter Technologies Inc.
  * Copyright (C) 2024 Puter Technologies Inc.
- *
+ * 
  * This file is part of Puter.
  * This file is part of Puter.
- *
+ * 
  * Puter is free software: you can redistribute it and/or modify
  * Puter is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as published
  * it under the terms of the GNU Affero General Public License as published
  * by the Free Software Foundation, either version 3 of the License, or
  * by the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
  * (at your option) any later version.
- *
+ * 
  * This program is distributed in the hope that it will be useful,
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Affero General Public License for more details.
  * GNU Affero General Public License for more details.
- *
+ * 
  * You should have received a copy of the GNU Affero General Public License
  * You should have received a copy of the GNU Affero General Public License
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
  */
+
+
 const babelParser = require('@babel/parser');
 const babelParser = require('@babel/parser');
 const generate = (require('@babel/generator')).default;
 const generate = (require('@babel/generator')).default;
 const fs = require('fs');
 const fs = require('fs');

+ 11 - 1
tools/license-headers/main.js

@@ -405,7 +405,17 @@ const cmd_sync_fn = async () => {
                     ]
                     ]
                 })
                 })
                 const action = await prompt.run();
                 const action = await prompt.run();
-                console.log('action', action);
+                if ( action === 'skip' ) continue;
+                const before = source.slice(0, diff_info.range[0]);
+                const after = source.slice(diff_info.range[1]);
+                const new_source = before +
+                    comment_parser.output_comment({
+                        style: 'block',
+                        filename: value.name,
+                        text: desired_header,
+                    }) +
+                    after;
+                fs.writeFileSync(value.path, new_source);
             } else {
             } else {
                 counts.ok++;
                 counts.ok++;
                 process.stdout.write(`\x1B[32;1mOK\x1B[0m\n`);
                 process.stdout.write(`\x1B[32;1mOK\x1B[0m\n`);