| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
| 5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
| 6 # | 6 # |
| 7 # Script to push a package to pub. | 7 # Script to push a package to pub. |
| 8 # | 8 # |
| 9 # Usage: publish_pkg.py pkg_dir | 9 # Usage: publish_pkg.py pkg_dir |
| 10 # | 10 # |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 # Within dependencies, don't print line that start with " sdk:" | 89 # Within dependencies, don't print line that start with " sdk:" |
| 90 # and strip out "{ sdk: package_name }". | 90 # and strip out "{ sdk: package_name }". |
| 91 # | 91 # |
| 92 if not line.startswith(' sdk:'): | 92 if not line.startswith(' sdk:'): |
| 93 line = re.sub(r'{(\s*)sdk:(\s+)([a-z0-9_]+)(\s*)}', '', line) | 93 line = re.sub(r'{(\s*)sdk:(\s+)([a-z0-9_]+)(\s*)}', '', line) |
| 94 pubspecFile.write(line) | 94 pubspecFile.write(line) |
| 95 else: | 95 else: |
| 96 pubspecFile.write(line) | 96 pubspecFile.write(line) |
| 97 if not foundVersion: | 97 if not foundVersion: |
| 98 pubspecFile.write('\nversion: ' + version + '\n') | 98 pubspecFile.write('\nversion: ' + version + '\n') |
| 99 pubspecFile.write('environment:\n') |
| 100 pubspecFile.write(' sdk: ">=' + version + '"\n') |
| 101 |
| 99 else: | 102 else: |
| 100 # | 103 # |
| 101 # If there's a lib/ directory in the package, copy the package. | 104 # If there's a lib/ directory in the package, copy the package. |
| 102 # Otherwise, move the package's contents to lib/. | 105 # Otherwise, move the package's contents to lib/. |
| 103 # | 106 # |
| 104 if os.path.exists(os.path.join(HOME, argv[1], 'lib')): | 107 if os.path.exists(os.path.join(HOME, argv[1], 'lib')): |
| 105 shutil.copytree(os.path.join(HOME, argv[1]), | 108 shutil.copytree(os.path.join(HOME, argv[1]), |
| 106 os.path.join(tmpDir, pkgName)) | 109 os.path.join(tmpDir, pkgName)) |
| 107 else: | 110 else: |
| 108 os.makedirs(os.path.join(tmpDir, pkgName)) | 111 os.makedirs(os.path.join(tmpDir, pkgName)) |
| 109 shutil.copytree(os.path.join(HOME, argv[1]), | 112 shutil.copytree(os.path.join(HOME, argv[1]), |
| 110 os.path.join(tmpDir, pkgName, 'lib')) | 113 os.path.join(tmpDir, pkgName, 'lib')) |
| 111 | 114 |
| 112 # Create pubspec.yaml . | 115 # Create pubspec.yaml . |
| 113 with open(pubspec, 'w') as pubspecFile: | 116 with open(pubspec, 'w') as pubspecFile: |
| 114 pubspecFile.write('name: ' + pkgName + '_unsupported\n') | 117 pubspecFile.write('name: ' + pkgName + '_unsupported\n') |
| 115 pubspecFile.write('author: None\n') | 118 pubspecFile.write('author: None\n') |
| 116 pubspecFile.write('homepage: http://None\n') | 119 pubspecFile.write('homepage: http://None\n') |
| 117 pubspecFile.write('version: ' + version + '\n') | 120 pubspecFile.write('version: ' + version + '\n') |
| 118 pubspecFile.write("description: >\n") | 121 pubspecFile.write("description: >\n") |
| 119 pubspecFile.write(' A completely unsupported clone of Dart SDK library\n'
) | 122 pubspecFile.write(' A completely unsupported clone of Dart SDK library\n'
) |
| 120 pubspecFile.write(' ' + argv[1] + ' . This package will change in\n') | 123 pubspecFile.write(' ' + argv[1] + ' . This package will change in\n') |
| 121 pubspecFile.write(' unpredictable/incompatible ways without warning.\n') | 124 pubspecFile.write(' unpredictable/incompatible ways without warning.\n') |
| 122 pubspecFile.write('dependencies:\n') | 125 pubspecFile.write('dependencies:\n') |
| 126 pubspecFile.write('environment:\n') |
| 127 pubspecFile.write(' sdk: ">=' + version + '"\n') |
| 123 | 128 |
| 124 libpath = os.path.join(HOME, argv[1], '../libraries.dart') | 129 libpath = os.path.join(HOME, argv[1], '../libraries.dart') |
| 125 if os.path.exists(libpath): | 130 if os.path.exists(libpath): |
| 126 # Copy libraries.dart into the package source code | 131 # Copy libraries.dart into the package source code |
| 127 shutil.copy(libpath, os.path.join(tmpDir, pkgName, 'lib/libraries.dart')) | 132 shutil.copy(libpath, os.path.join(tmpDir, pkgName, 'lib/libraries.dart')) |
| 128 | 133 |
| 129 # Replace '../../libraries.dart' with '../libraries.dart' | 134 # Replace '../../libraries.dart' with '../libraries.dart' |
| 130 replaceInDart.append( | 135 replaceInDart.append( |
| 131 (r'(import|part)(\s+)(\'|")\.\./(\.\./)*libraries.dart', | 136 (r'(import|part)(\s+)(\'|")\.\./(\.\./)*libraries.dart', |
| 132 r'\1\2\3\4libraries.dart')) | 137 r'\1\2\3\4libraries.dart')) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 ReplaceInFiles([os.path.join(root, name)], replaceInDart) | 178 ReplaceInFiles([os.path.join(root, name)], replaceInDart) |
| 174 elif name == 'pubspec.yaml': | 179 elif name == 'pubspec.yaml': |
| 175 ReplaceInFiles([os.path.join(root, name)], replaceInPubspec) | 180 ReplaceInFiles([os.path.join(root, name)], replaceInPubspec) |
| 176 | 181 |
| 177 print 'publishing version ' + version + ' of ' + argv[1] + ' to pub.\n' | 182 print 'publishing version ' + version + ' of ' + argv[1] + ' to pub.\n' |
| 178 subprocess.call(['pub', 'publish'], cwd=os.path.join(tmpDir, pkgName)) | 183 subprocess.call(['pub', 'publish'], cwd=os.path.join(tmpDir, pkgName)) |
| 179 shutil.rmtree(tmpDir) | 184 shutil.rmtree(tmpDir) |
| 180 | 185 |
| 181 if __name__ == '__main__': | 186 if __name__ == '__main__': |
| 182 sys.exit(Main(sys.argv)) | 187 sys.exit(Main(sys.argv)) |
| OLD | NEW |